COPASI API  4.16.103
ListOfUnsupportedAnnotations.cpp
Go to the documentation of this file.
1 // Copyright (C) 2012 - 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 /*
7  * ListOfUnsupportedAnnotations.cpp
8  *
9  * Created on: May 24, 2012
10  * Author: shoops
11  */
12 
13 #include "copasi.h"
14 
15 #include "CExpat.h"
16 #include "CCopasiXMLParser.h"
17 #include "CCopasiXMLInterface.h"
18 
19 #define START_ELEMENT -1
20 #define UNKNOWN_ELEMENT -2
21 
23  SCopasiXMLParserCommon & common):
25  mName(),
26  mXML(),
27  mLevel(0),
28  mElementEmpty()
29 {}
30 
31 // virtual
33 {}
34 
35 // virtual
37  const XML_Char **papszAttrs)
38 {
39  mCurrentElement++; /* We should always be on the next element */
40  const XML_Char ** ppAttrs;
41 
42  if (mLevel) mCurrentElement = Content;
43 
44  switch (mCurrentElement)
45  {
46  case UnsupportedAnnotation:
47 
48  if (strcmp(pszName, "UnsupportedAnnotation"))
50  pszName, "UnsupportedAnnotation", mParser.getCurrentLineNumber());
51 
52  mName = mParser.getAttributeValue("name", papszAttrs);
53  mXML.str("");
54  mLevel = 0;
55  mParser.enableCharacterDataHandler();
56  mElementEmpty.push(false);
57  break;
58 
59  case Content:
60 
61  if (mElementEmpty.top() == true)
62  {
63  mXML << ">";
64  mElementEmpty.top() = false;
65  }
66 
68  mXML << "<" << pszName;
69 
70  for (ppAttrs = papszAttrs; *ppAttrs && **ppAttrs; ppAttrs += 2)
71  mXML << " " << *ppAttrs << "=\""
73 
74  mLevel++;
75  mElementEmpty.push(true);
76 
77  mParser.enableCharacterDataHandler();
78  break;
79 
80  default:
81  mLastKnownElement = mCurrentElement - 1;
82  mCurrentElement = UNKNOWN_ELEMENT;
83  mParser.pushElementHandler(&mParser.mUnknownElement);
84  mParser.onStartElement(pszName, papszAttrs);
85  break;
86  }
87 
88  return;
89 }
90 
91 // virtual
93 {
94  std::string XML;
95 
96  switch (mCurrentElement)
97  {
98  case UnsupportedAnnotation:
99 
100  if (strcmp(pszName, "UnsupportedAnnotation"))
102  pszName, "UnsupportedAnnotation", mParser.getCurrentLineNumber());
103 
105 
106  XML = mXML.str();
107 
108  {
109  // remove leading whitepsaces
110  std::string::size_type pos = XML.find_first_not_of("\x0a\x0d\t ");
111 
112  if (pos != 0) XML.erase(0, pos);
113 
114  // remove trailing whitepsace
115  pos = XML.find_last_not_of("\x0a\x0d\t ");
116 
117  if (pos < XML.length())
118  XML = XML.substr(0, pos + 1);
119  }
120 
121  mXML.str(XML);
122 
123  mParser.popElementHandler();
124  mCurrentElement = START_ELEMENT;
125  mElementEmpty.pop();
126 
127  deleteCurrentHandler();
128 
129  /* Tell the parent element we are done. */
130  mParser.onEndElement(pszName);
131  break;
132 
133  case Content:
134  XML = mParser.getCharacterData();
135 
136  // Check whether and how we need to close the element
137  if (mElementEmpty.top() == true)
138  {
139  if (XML != "")
140  {
141  mElementEmpty.top() = false;
142  mXML << ">";
143  }
144  else
145  mXML << " />";
146  }
147 
148  if (XML != "")
150 
151  if (mElementEmpty.top() == false)
152  mXML << "</" << pszName << ">";
153 
154  mElementEmpty.pop();
155  mElementEmpty.top() = false;
156  mLevel--;
157 
158  if (!mLevel) mCurrentElement = UnsupportedAnnotation;
159 
160  mParser.enableCharacterDataHandler();
161  break;
162 
163  case UNKNOWN_ELEMENT:
164  mCurrentElement = mLastKnownElement;
165  break;
166 
167  default:
169  pszName, "???", mParser.getCurrentLineNumber());
170  break;
171  }
172 
173  return;
174 }
175 
177 {
178  return mName;
179 }
180 
182 {
183  return mXML.str();
184 }
185 
187  SCopasiXMLParserCommon & common):
189  mUnsupportedAnnotations(),
190  mpUnsupportedAnnotationElement(NULL)
191 {}
192 
193 // virtual
195 {
196  pdelete(mpUnsupportedAnnotationElement);
197 }
198 
199 // virtual
201  const XML_Char **papszAttrs)
202 {
203  mpCurrentHandler = NULL;
204  mCurrentElement = mLastKnownElement;
205 
206  while (mpCurrentHandler == NULL)
207  {
208  mCurrentElement++; /* We should always be on the next element */
209 
210  switch (mCurrentElement)
211  {
212  case ListOfUnsupportedAnnotations:
213 
214  if (strcmp(pszName, "ListOfUnsupportedAnnotations"))
216  pszName, "ListOfUnsupportedAnnotations", mParser.getCurrentLineNumber());
217 
218  mLastKnownElement = ListOfUnsupportedAnnotations;
219  mUnsupportedAnnotations.clear();
220 
221  return;
222 
223  case UnsupportedAnnotation:
224 
225  if (!strcmp(pszName, "UnsupportedAnnotation"))
226  {
227  /* If we do not have a ModelParameterSet element handler we create one. */
228  if (!mpUnsupportedAnnotationElement)
229  mpUnsupportedAnnotationElement = new UnsupportedAnnotationElement(mParser, mCommon);
230 
231  mpCurrentHandler = mpUnsupportedAnnotationElement;
232  }
233 
234  break;
235 
236  default:
237  mCurrentElement = UNKNOWN_ELEMENT;
238  mpCurrentHandler = &mParser.mUnknownElement;
239  break;
240  }
241  }
242 
243  mParser.pushElementHandler(mpCurrentHandler);
244 
245  if (mpCurrentHandler != &mParser.mUnknownElement)
246  {
247  mLastKnownElement = mCurrentElement;
248  }
249 
250  mParser.onStartElement(pszName, papszAttrs);
251 }
252 
253 // virtual
255 {
256  switch (mCurrentElement)
257  {
258  case ListOfUnsupportedAnnotations:
259 
260  if (strcmp(pszName, "ListOfUnsupportedAnnotations"))
262  pszName, "ListOfUnsupportedAnnotations", mParser.getCurrentLineNumber());
263 
264  mParser.popElementHandler();
265  mCurrentElement = START_ELEMENT;
266  mLastKnownElement = START_ELEMENT;
267 
268  /* Tell the parent element we are done. */
269  mParser.onEndElement(pszName);
270  break;
271 
272  case UnsupportedAnnotation:
273 
274  if (strcmp(pszName, "UnsupportedAnnotation"))
276  pszName, "UnsupportedAnnotation", mParser.getCurrentLineNumber());
277 
278  if (mpUnsupportedAnnotationElement != NULL)
279  {
280  mUnsupportedAnnotations[mpUnsupportedAnnotationElement->getName()] =
281  mpUnsupportedAnnotationElement->getXML();
282  }
283 
284  mLastKnownElement = ListOfUnsupportedAnnotations;
285  mCurrentElement = ListOfUnsupportedAnnotations;
286  break;
287 
288  case UNKNOWN_ELEMENT:
289  mCurrentElement = mLastKnownElement;
290  break;
291 
292  default:
294  pszName, "???", mParser.getCurrentLineNumber());
295  break;
296  }
297 
298  return;
299 }
300 
302 {
303  return mUnsupportedAnnotations;
304 }
SCopasiXMLParserCommon mCommon
#define pdelete(p)
Definition: copasi.h:215
#define MCXML
const CAnnotation::UnsupportedAnnotation & getUnsupportedAnnotations() const
UnsupportedAnnotationElement(CCopasiXMLParser &parser, SCopasiXMLParserCommon &common)
XML_Parser mParser
Definition: CExpat.h:48
#define START_ELEMENT
ListOfUnsupportedAnnotationsElement(CCopasiXMLParser &parser, SCopasiXMLParserCommon &common)
#define UNKNOWN_ELEMENT
virtual void start(const XML_Char *pszName, const XML_Char **papszAttrs)
std::map< std::string, std::string > UnsupportedAnnotation
Definition: CAnnotation.h:17
static std::string encode(const std::string &str, const EncodingType &type=standard)
virtual void start(const XML_Char *pszName, const XML_Char **papszAttrs)