COPASI API  4.16.103
Public Member Functions | Private Types | Private Attributes | List of all members
CCopasiXMLParser::CommentElement Class Reference
Inheritance diagram for CCopasiXMLParser::CommentElement:
Inheritance graph
[legend]
Collaboration diagram for CCopasiXMLParser::CommentElement:
Collaboration graph
[legend]

Public Member Functions

 CommentElement (CCopasiXMLParser &parser, SCopasiXMLParserCommon &common)
 
virtual void end (const XML_Char *pszName)
 
virtual void start (const XML_Char *pszName, const XML_Char **papszAttrs)
 
virtual ~CommentElement ()
 
- Public Member Functions inherited from CXMLElementHandler< CCopasiXMLParser, SCopasiXMLParserCommon >
 CXMLElementHandler (CCopasiXMLParser &parser, SCopasiXMLParserCommon &common)
 
virtual void end (const XML_Char *C_UNUSED(pszName))
 
virtual void reset ()
 
virtual void start (const XML_Char *C_UNUSED(pszName), const XML_Char **C_UNUSED(papszAttrs))
 
virtual ~CXMLElementHandler ()
 

Private Types

enum  Element { Comment = 0, xhtml }
 

Private Attributes

std::stack< bool > mElementEmpty
 
size_t mLevel
 
std::ostringstream mXhtml
 

Additional Inherited Members

- Protected Member Functions inherited from CXMLElementHandler< CCopasiXMLParser, SCopasiXMLParserCommon >
void addFix (const std::string &key, CCopasiObject *pObject)
 
void deleteCurrentHandler ()
 
- Protected Attributes inherited from CXMLElementHandler< CCopasiXMLParser, SCopasiXMLParserCommon >
SCopasiXMLParserCommonmCommon
 
C_INT32 mCurrentElement
 
C_INT32 mLastKnownElement
 
CCopasiXMLParsermParser
 
CXMLElementHandlermpCurrentHandler
 

Detailed Description

Definition at line 1734 of file CCopasiXMLParser.h.

Member Enumeration Documentation

Enum of invoked parsers

Enumerator
Comment 
xhtml 

Definition at line 1742 of file CCopasiXMLParser.h.

Constructor & Destructor Documentation

CCopasiXMLParser::CommentElement::CommentElement ( CCopasiXMLParser parser,
SCopasiXMLParserCommon common 
)
CCopasiXMLParser::CommentElement::~CommentElement ( )
virtual

Destructor

Definition at line 1999 of file CCopasiXMLParser.cpp.

Member Function Documentation

void CCopasiXMLParser::CommentElement::end ( const XML_Char *  pszName)
virtual

End element handler

Parameters
constXML_Char *pszName

Definition at line 2061 of file CCopasiXMLParser.cpp.

References SCopasiXMLParserCommon::CharacterData, CCopasiMessage::EXCEPTION, CCopasiXMLParser::mCommon, MCXML, CExpatTemplate< CExpat >::mParser, CCopasiXMLInterface::none, START_ELEMENT, and UNKNOWN_ELEMENT.

2062 {
2063  std::string Xhtml;
2064 
2065  switch (mCurrentElement)
2066  {
2067  case Comment:
2068 
2069  if (strcmp(pszName, "Comment"))
2071  pszName, "Comment", mParser.getCurrentLineNumber());
2072 
2074 
2075  mCommon.CharacterData = mXhtml.str();
2076 
2077  {
2078  // remove leading whitepsaces
2079  std::string::size_type pos = mCommon.CharacterData.find_first_not_of("\x0a\x0d\t ");
2080 
2081  if (pos != 0) mCommon.CharacterData.erase(0, pos);
2082 
2083  // remove trailing whitepsace
2084  pos = mCommon.CharacterData.find_last_not_of("\x0a\x0d\t ");
2085 
2086  if (pos < mCommon.CharacterData.length())
2087  mCommon.CharacterData = mCommon.CharacterData.substr(0, pos + 1);
2088  }
2089 
2092 
2095  mElementEmpty.pop();
2096 
2098 
2099  /* Tell the parent element we are done. */
2100  mParser.onEndElement(pszName);
2101  break;
2102 
2103  case xhtml:
2104  Xhtml = mParser.getCharacterData();
2105 
2106  // Check whether and how we need to close the attribute
2107  if (mElementEmpty.top() == true)
2108  {
2109  if (Xhtml != "")
2110  {
2111  mElementEmpty.top() = false;
2112  mXhtml << ">";
2113  }
2114  else
2115  mXhtml << " />";
2116  }
2117 
2118  mXhtml << Xhtml;
2119 
2120  if (mElementEmpty.top() == false)
2121  mXhtml << "</" << pszName << ">";
2122 
2123  mElementEmpty.pop();
2124  mElementEmpty.top() = false;
2125  mLevel--;
2126 
2127  if (!mLevel) mCurrentElement = Comment;
2128 
2130  break;
2131 
2132  case UNKNOWN_ELEMENT:
2134  break;
2135 
2136  default:
2138  pszName, "???", mParser.getCurrentLineNumber());
2139  break;
2140  }
2141 
2142  return;
2143 }
CCopasiXMLInterface::EncodingType mCharacterDataEncoding
#define START_ELEMENT
void enableCharacterDataHandler(bool fEnable=true)
#define MCXML
virtual void onEndElement(const XML_Char *pszName)
#define UNKNOWN_ELEMENT
std::string getCharacterData(const std::string &toBeStripped="", const std::string &join=" ")
void enableSkippedEntityHandler(bool fEnable=true)
Definition: CExpat.h:337
int getCurrentLineNumber() const
Definition: CExpat.h:470
void CCopasiXMLParser::CommentElement::start ( const XML_Char *  pszName,
const XML_Char **  papszAttrs 
)
virtual

Start element handler

Parameters
constXML_Char *pszName
constXML_Char **papszAttrs

Definition at line 2004 of file CCopasiXMLParser.cpp.

References CCopasiXMLInterface::attribute, CCopasiXMLInterface::encode(), CCopasiMessage::EXCEPTION, MCXML, CExpatTemplate< CExpat >::mParser, CCopasiXMLInterface::standard, and UNKNOWN_ELEMENT.

2006 {
2007  mCurrentElement++; /* We should always be on the next element */
2008  const XML_Char ** ppAttrs;
2009 
2010  if (mLevel) mCurrentElement = xhtml;
2011 
2012  switch (mCurrentElement)
2013  {
2014  case Comment:
2015 
2016  if (strcmp(pszName, "Comment"))
2018  pszName, "Comment", mParser.getCurrentLineNumber());
2019 
2020  mXhtml.str("");
2021  mLevel = 0;
2025 
2026  mElementEmpty.push(false);
2027  break;
2028 
2029  case xhtml:
2030 
2031  if (mElementEmpty.top() == true)
2032  {
2033  mXhtml << ">";
2034  mElementEmpty.top() = false;
2035  }
2036 
2038  mXhtml << "<" << pszName;
2039 
2040  for (ppAttrs = papszAttrs; *ppAttrs && **ppAttrs; ppAttrs += 2)
2041  mXhtml << " " << *ppAttrs << "=\""
2042  << CCopasiXMLInterface::encode(*(ppAttrs + 1), CCopasiXMLInterface::attribute) << "\"";
2043 
2044  mLevel++;
2045  mElementEmpty.push(true);
2046 
2048  break;
2049 
2050  default:
2054  mParser.onStartElement(pszName, papszAttrs);
2055  break;
2056  }
2057 
2058  return;
2059 }
CCopasiXMLInterface::EncodingType mCharacterDataEncoding
UnknownElement mUnknownElement
void enableCharacterDataHandler(bool fEnable=true)
#define MCXML
#define UNKNOWN_ELEMENT
virtual void onStartElement(const XML_Char *pszName, const XML_Char **papszAttrs)
void pushElementHandler(CXMLElementHandler< CCopasiXMLParser, SCopasiXMLParserCommon > *elementHandler)
std::string getCharacterData(const std::string &toBeStripped="", const std::string &join=" ")
void enableSkippedEntityHandler(bool fEnable=true)
Definition: CExpat.h:337
static std::string encode(const std::string &str, const EncodingType &type=standard)
int getCurrentLineNumber() const
Definition: CExpat.h:470

Member Data Documentation

std::stack< bool > CCopasiXMLParser::CommentElement::mElementEmpty
private

Information whether an element is empty

Definition at line 1761 of file CCopasiXMLParser.h.

size_t CCopasiXMLParser::CommentElement::mLevel
private

The level of nested xhtml elements.

Definition at line 1756 of file CCopasiXMLParser.h.

std::ostringstream CCopasiXMLParser::CommentElement::mXhtml
private

String stream to handle xhtml comments

Definition at line 1751 of file CCopasiXMLParser.h.


The documentation for this class was generated from the following files: