COPASI API  4.16.103
CExpat.h
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2015 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2003 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 /**
16  * This file describes the C++ interface to the expat library used by
17  * COPASI.
18  *
19  * Created for COPASI by Stefan Hoops 2003
20  * Copyright Stefan Hoops
21  */
22 
23 #ifndef COPASI_CExpat
24 #define COPASI_CExpat
25 
26 #include <assert.h>
27 #include <expat.h>
28 #include <string.h>
29 
31 
32 /**
33  * CExpatTemplate class.
34  * The class CExpatTemplate is a template defining a C++ interface to
35  * the expat library.
36  *
37  * Created for COPASI by Stefan Hoops 2003
38  */
39 template <class CType>
41 {
42  // Attributes
43 protected:
44 
45  /**
46  * The expat parser
47  */
48  XML_Parser mParser;
49 
50 public:
51  /**
52  * Destroy the parser
53  */
54  void destroy()
55  {
56  if (mParser != NULL)
57  XML_ParserFree(mParser);
58 
59  mParser = NULL;
60  }
61 
62  /**
63  * Default constructor
64  */
66  mParser(NULL)
67  {}
68 
69  /**
70  * Destructor
71  */
73 
74  /**
75  * Create a parser
76  * @param const XML_Char *pszEncoding (Default = NULL)
77  * @param const XML_Char *pszSep (Default = NULL)
78  */
79  bool create(const XML_Char *pszEncoding = NULL,
80  const XML_Char *pszSep = NULL)
81  {
82  //
83  // Destroy the old parser
84  //
85 
86  destroy();
87 
88  //
89  // If the encoding or separator are empty, then NULL
90  //
91 
92  if (pszEncoding != NULL && pszEncoding [0] == 0)
93  pszEncoding = NULL;
94 
95  if (pszSep != NULL && pszSep [0] == 0)
96  pszSep = NULL;
97 
98  //
99  // Create the new one
100  //
101 
102  mParser = XML_ParserCreate_MM(pszEncoding, NULL, pszSep);
103 
104  if (mParser == NULL)
105  return false;
106 
107  //
108  // Invoke the post create routine
109  //
110 
111  CType *pThis = static_cast <CType *>(this);
112  pThis->onPostCreate();
113 
114  //
115  // Set the user data used in callbacks
116  //
117 
118  XML_SetUserData(mParser, (void *) this);
119 
120  //
121  // Allow the handling of skipped entities, e.g. in XHTML
122  //
123  XML_UseForeignDTD(mParser, XML_TRUE);
124 
125  return true;
126  }
127 
128  /**
129  * Parse a block of character data
130  * @param const char *pszBuffer
131  * @param int nLength (Default: -1 (zero terminated))
132  * @param bool fIsFinal (Default: true)
133  * @return bool Success
134  */
135  bool parse(const char *pszBuffer, int nLength = -1, bool fIsFinal = true)
136  {
137  //
138  // Validate
139  //
140 
141  assert(mParser != NULL);
142 
143  //
144  // Get the length if not specified
145  //
146 
147  if (nLength < 0)
148  nLength = (int) strlen(pszBuffer);
149 
150  //
151  // Invoke the parser
152  //
153 
154  return XML_Parse(mParser, pszBuffer, nLength, fIsFinal) != 0;
155  }
156 
157 #ifdef WCHAR
158  /**
159  * Parse a block of wide character data
160  * @param const WCHAR *pszBuffer
161  * @param int nLength (Default: -1 (zero terminated))
162  * @param bool fIsFinal (Default: true)
163  * @return bool Success
164  */
165  bool parse(const WCHAR *pszBuffer, int nLength = -1, bool fIsFinal = true)
166  {
167  //
168  // Validate
169  //
170 
171  assert(mParser != NULL);
172 
173  //
174  // Get the length if not specified
175  //
176 
177  if (nLength < 0)
178  nLength = wcslen(pszBuffer) * 2;
179 
180  //
181  // Invoke the parser
182  //
183 
184  return XML_Parse(mParser, pszBuffer, nLength, fIsFinal) != 0;
185  }
186 #endif
187 
188  /**
189  * Parse internal buffer
190  * @param int nLength
191  * @param bool fIsFinal (Default: true)
192  * @return bool Success
193  */
194  bool parseBuffer(int nLength, bool fIsFinal = true)
195  {
196  assert(mParser != NULL);
197  return XML_ParseBuffer(mParser, nLength, fIsFinal) != 0;
198  }
199 
200  /**
201  * Get the internal buffer
202  */
203  void *getBuffer(int nLength)
204  {
205  assert(mParser != NULL);
206  return XML_GetBuffer(mParser, nLength);
207  }
208 
209  /**
210  * Enable/Disable the start element handler
211  * @param bool fEnable (Default: true)
212  */
213  void enableStartElementHandler(bool fEnable = true)
214  {
215  assert(mParser != NULL);
216  XML_SetStartElementHandler(mParser, fEnable ? startElementHandler : NULL);
217  }
218 
219  /**
220  * Enable/Disable end element handler
221  * @param bool fEnable (Default: true)
222  */
223  void enableEndElementHandler(bool fEnable = true)
224  {
225  assert(mParser != NULL);
226  XML_SetEndElementHandler(mParser, fEnable ? endElementHandler : NULL);
227  }
228 
229  /**
230  * Enable/Disable the element handlers
231  * @param bool fEnable (Default: true)
232  */
233  void enableElementHandler(bool fEnable = true)
234  {
235  assert(mParser != NULL);
236  enableStartElementHandler(fEnable);
237  enableEndElementHandler(fEnable);
238  }
239 
240  /**
241  * Enable/Disable the character data handler
242  * @param bool fEnable (Default: true)
243  */
244  void enableCharacterDataHandler(bool fEnable = true)
245  {
246  assert(mParser != NULL);
247  XML_SetCharacterDataHandler(mParser,
248  fEnable ? characterDataHandler : NULL);
249  }
250 
251  /**
252  * Enable/Disable the processing instruction handler
253  * @param bool fEnable (Default: true)
254  */
255  void enableProcessingInstructionHandler(bool fEnable = true)
256  {
257  assert(mParser != NULL);
258  XML_SetProcessingInstructionHandler(mParser,
259  fEnable ? processingInstructionHandler : NULL);
260  }
261 
262  /**
263  * Enable/Disable the comment handler
264  * @param bool fEnable (Default: true)
265  */
266  void enableCommentHandler(bool fEnable = true)
267  {
268  assert(mParser != NULL);
269  XML_SetCommentHandler(mParser, fEnable ? commentHandler : NULL);
270  }
271 
272  /**
273  * Enable/Disable the start CDATA section handler
274  * @param bool fEnable (Default: true)
275  */
276  void enableStartCdataSectionHandler(bool fEnable = true)
277  {
278  assert(mParser != NULL);
279  XML_SetStartCdataSectionHandler(mParser,
280  fEnable ? startCdataSectionHandler : NULL);
281  }
282 
283  /**
284  * Enable/Disable the end CDATA section handlers
285  * @param bool fEnable (Default: true)
286  */
287  void enableEndCdataSectionHandler(bool fEnable = true)
288  {
289  assert(mParser != NULL);
290  XML_SetEndCdataSectionHandler(mParser,
291  fEnable ? endCdataSectionHandler : NULL);
292  }
293 
294  /**
295  * Enable/Disable the CDATA section handlers
296  * @param bool fEnable (Default: true)
297  */
298  void enableCdataSectionHandler(bool fEnable = true)
299  {
300  assert(mParser != NULL);
303  }
304 
305  /**
306  * Enable/Disable default handler
307  * @param bool fEnable (Default: true)
308  */
309  void enableDefaultHandler(bool fEnable = true, bool fExpand = true)
310  {
311  assert(mParser != NULL);
312 
313  if (fExpand)
314  {
315  XML_SetDefaultHandlerExpand(mParser,
316  fEnable ? defaultHandler : NULL);
317  }
318  else
319  XML_SetDefaultHandler(mParser, fEnable ? defaultHandler : NULL);
320  }
321 
322  /**
323  * Enable/Disable external entity ref handler
324  * @param bool fEnable (Default: true)
325  */
326  void enableExternalEntityRefHandler(bool fEnable = true)
327  {
328  assert(mParser != NULL);
329  XML_SetExternalEntityRefHandler(mParser,
330  fEnable ? externalEntityRefHandler : NULL);
331  }
332 
333  /**
334  * Enable/Disable the skipped entity handler
335  * @param bool fEnable (Default: true)
336  */
337  void enableSkippedEntityHandler(bool fEnable = true)
338  {
339  assert(mParser != NULL);
340  XML_SetSkippedEntityHandler(mParser,
341  fEnable ? skippedEntityHandler : NULL);
342  }
343 
344  /**
345  * Enable/Disable unknown encoding handler
346  * @param bool fEnable (Default: true)
347  */
348  void enableUnknownEncodingHandler(bool fEnable = true)
349  {
350  assert(mParser != NULL);
351  XML_SetUnknownEncodingHandler(mParser,
352  fEnable ? unknownEncodingHandler : NULL,
353  NULL);
354  }
355 
356  /**
357  * Enable/Disable start namespace handler
358  * @param bool fEnable (Default: true)
359  */
360  void enableStartNamespaceDeclHandler(bool fEnable = true)
361  {
362  assert(mParser != NULL);
363  XML_SetStartNamespaceDeclHandler(mParser,
364  fEnable ? startNamespaceDeclHandler : NULL);
365  }
366 
367  /**
368  * Enable/Disable end namespace handler
369  * @param bool fEnable (Default: true)
370  */
371  void enableEndNamespaceDeclHandler(bool fEnable = true)
372  {
373  assert(mParser != NULL);
374  XML_SetEndNamespaceDeclHandler(mParser,
375  fEnable ? endNamespaceDeclHandler : NULL);
376  }
377 
378  /**
379  * Enable/Disable namespace handlers
380  * @param bool fEnable (Default: true)
381  */
382  void enableNamespaceDeclHandler(bool fEnable = true)
383  {
386  }
387 
388  /**
389  * Enable/Disable the XML declaration handler
390  * @param bool fEnable (Default: true)
391  */
392  void enableXmlDeclHandler(bool fEnable = true)
393  {
394  assert(mParser != NULL);
395  XML_SetXmlDeclHandler(mParser, fEnable ? xmlDeclHandler : NULL);
396  }
397 
398  /**
399  * Enable/Disable the start DOCTYPE declaration handler
400  * @param bool fEnable (Default: true)
401  */
402  void enableStartDoctypeDeclHandler(bool fEnable = true)
403  {
404  assert(mParser != NULL);
405  XML_SetStartDoctypeDeclHandler(mParser,
406  fEnable ? startDoctypeDeclHandler : NULL);
407  }
408 
409  /**
410  * Enable/Disable the end DOCTYPE declaration handler
411  * @param bool fEnable (Default: true)
412  */
413  void enableEndDoctypeDeclHandler(bool fEnable = true)
414  {
415  assert(mParser != NULL);
416  XML_SetEndDoctypeDeclHandler(mParser,
417  fEnable ? endDoctypeDeclHandler : NULL);
418  }
419 
420  /**
421  * Enable/Disable the DOCTYPE declaration handler
422  * @param bool fEnable (Default: true)
423  */
424  void enableDoctypeDeclHandler(bool fEnable = true)
425  {
426  assert(mParser != NULL);
429  }
430 
431  /**
432  * Get last error
433  * @return enum XML_Error
434  */
435  enum XML_Error getErrorCode()
436  {
437  assert(mParser != NULL);
438  return XML_GetErrorCode(mParser);
439  }
440 
441  /**
442  * Get last error string
443  * @return const XML_LChar * errorString
444  */
445  const XML_LChar *getErrorString()
446  {return XML_ErrorString(getErrorCode());}
447 
448  /**
449  * Get error string
450  * @param enum XML_Error nError
451  * @return const XML_LChar * errorString
452  */
453  static const XML_LChar *getErrorString(enum XML_Error nError)
454  {return XML_ErrorString(nError);}
455 
456  /**
457  * Get the current byte index
458  * @return long byteIndex
459  */
461  {
462  assert(mParser != NULL);
463  return XML_GetCurrentByteIndex(mParser);
464  }
465 
466  /**
467  * Get the current line number
468  * @return ing lineNumber
469  */
471  {
472  assert(mParser != NULL);
473  return XML_GetCurrentLineNumber(mParser);
474  }
475 
476  /**
477  * Get the current column number
478  * @return in cloumnNumber
479  */
481  {
482  assert(mParser != NULL);
483  return XML_GetCurrentColumnNumber(mParser);
484  }
485 
486  /**
487  * Get the current byte count
488  * @return in byteCount
489  */
491  {
492  assert(mParser != NULL);
493  return XML_GetCurrentByteCount(mParser);
494  }
495 
496  /**
497  * Get the input context
498  * @const char * inputContext
499  */
500  const char *getInputContext(int *pnOffset, int *pnSize)
501  {
502  assert(mParser != NULL);
503  return XML_GetInputContext(mParser, pnOffset, pnSize);
504  }
505 
506  /**
507  * Return the version string
508  * @return const XML_LChar * version
509  */
510  static const XML_LChar *getExpatVersion()
511  {return XML_ExpatVersion();}
512 
513  // @cmember Get the version information
514 
515  /**
516  * Get the version information
517  * @param int nMajor
518  * @param int nMinor
519  * @param int nMicro
520  */
521  static void getExpatVersion(int &nMajor, int &nMinor, int &nMicro)
522  {
523  XML_Expat_Version v = XML_ExpatVersionInfo();
524 
525  nMajor = v.major;
526  nMinor = v.minor;
527  nMicro = v.micro;
528  }
529 
530  /**
531  * Start element handler
532  * @param const XML_Char *pszName
533  * @param const XML_Char **papszAttrs
534  */
535  void onStartElement(const XML_Char *pszName, const XML_Char **papszAttrs)
536  {return;}
537 
538  /**
539  * End element handler
540  * @param const XML_Char *pszName
541  */
542  void onEndElement(const XML_Char *pszName)
543  {return;}
544 
545  /**
546  * Character data handler
547  * @param const XML_Char *pszData
548  * @param int nLength
549  */
550  void onCharacterData(const XML_Char *pszData, int nLength)
551  {return;}
552 
553  /**
554  * Processing instruction handler
555  * @param const XML_Char *pszTarget
556  * @param const XML_Char *pszData
557  */
558  void onProcessingInstruction(const XML_Char *pszTarget,
559  const XML_Char *pszData)
560  {return;}
561 
562  /**
563  * Comment handler
564  * @param const XML_Char *pszData
565  */
566  void onComment(const XML_Char *pszData)
567  {return;}
568 
569  /**
570  * Start CDATA section handler
571  */
573  {return;}
574 
575  /**
576  * End CDATA section handler
577  */
579  {return;}
580 
581  /**
582  * Default handler
583  * @param const XML_Char *pszData
584  * @param int nLength
585  */
586  void onDefault(const XML_Char *pszData, int nLength)
587  {return;}
588 
589  /**
590  * External entity ref handler
591  * @param const XML_Char *pszContext
592  * @param const XML_Char *pszBase
593  * @param const XML_Char *pszSystemID
594  * @param const XML_Char *pszPublicID
595  */
596  bool onExternalEntityRef(const XML_Char *pszContext,
597  const XML_Char *pszBase,
598  const XML_Char *pszSystemID,
599  const XML_Char *pszPublicID)
600  {return false;}
601 
602  /**
603  * Skipped entity handler
604  * This is called in two situations:
605  * 1) An entity reference is encountered for which no declaration
606  * has been read *and* this is not an error.
607  * 2) An internal entity reference is read, but not expanded, because
608  * XML_SetDefaultHandler has been called.
609  * Note: skipped parameter entities in declarations and skipped general
610  * entities in attribute values cannot be reported, because
611  * the event would be out of sync with the reporting of the
612  * declarations or attribute values
613  * @param const XML_Char *entityName
614  * @param int is_parameter_entity
615  */
616  void onSkippedEntityHandler(const XML_Char * /* entityName */,
617  int /* is_parameter_entity */)
618  {return;}
619 
620  /**
621  * Unknown encoding handler
622  * @param const XML_Char *pszName
623  * @param XML_Encoding *pInfo
624  */
625  bool onUnknownEncoding(const XML_Char *pszName, XML_Encoding *pInfo)
626  {return false;}
627 
628  /**
629  * Start namespace declaration handler
630  * @param const XML_Char *pszPrefix
631  * @param const XML_Char *pszURI
632  */
633  void onStartNamespaceDecl(const XML_Char *pszPrefix,
634  const XML_Char *pszURI)
635  {return;}
636 
637  /**
638  * End namespace declaration handler
639  * @param const XML_Char *pszPrefix
640  */
641  void onEndNamespaceDecl(const XML_Char *pszPrefix)
642  {return;}
643 
644  /**
645  * XML declaration handler
646  * @param const XML_Char *pszVersion
647  * @param const XML_Char *pszEncoding
648  * @param bool fStandalone
649  */
650  void onXmlDecl(const XML_Char *pszVersion,
651  const XML_Char *pszEncoding,
652  bool fStandalone)
653  {return;}
654 
655  /**
656  * Start DOCTYPE declaration handler
657  * @param const XML_Char *pszDoctypeName
658  * @param const XML_Char *pszSysID
659  * @param const XML_Char *pszPubID
660  * @param bool fHasInternalSubset
661  */
662  void onStartDoctypeDecl(const XML_Char *pszDoctypeName,
663  const XML_Char *pszSysID,
664  const XML_Char *pszPubID,
665  bool fHasInternalSubset)
666  {return;}
667 
668  /**
669  * End DOCTYPE declaration handler
670  */
672  {return;}
673 
674  /**
675  * Retrieve the attribute value for the given name out of the list
676  * of attributes. If required is true and the attribute is not found an
677  * exception is thrown. If required is false and the attribute is not found
678  * NULL is returned.
679  *
680  * @param const std::string & name
681  * @param const char ** attributes
682  * @param const bool & required (default: true)
683  * @return const char * value
684  */
685  const char * getAttributeValue(const std::string & name,
686  const char ** attributes,
687  const bool & required = true) const
688  {
689  unsigned C_INT32 i;
690 
691  for (i = 0; attributes[i]; i += 2)
692  if (attributes[i] == name) break;
693 
694  if (attributes[i]) return attributes[i + 1];
695 
696  if (required)
698  name.c_str(), getCurrentLineNumber());
699 
700  return NULL;
701  }
702 
703  /**
704  * Retrieve the attribute value for the given name out of the list
705  * of attributes. If the attribute is not found default is returned.
706  * @param const std::string & name
707  * @param const char ** attributes
708  * @param const char * default
709  * @return const char * value
710  */
711  const char * getAttributeValue(const std::string & name,
712  const char ** attributes,
713  const char * def) const
714  {
715  const char * tmp = getAttributeValue(name, attributes, false);
716 
717  if (!tmp) return def;
718 
719  return tmp;
720  }
721 
722  /**
723  * Convert an attribute of type xs:boolean to bool. If attribute is NULL
724  * false is returned.
725  * @param const char * attribute
726  * @return bool
727  */
728  static bool toBool(const char * attribute)
729  {
730  if (!attribute) return false;
731 
732  if (!strcmp(attribute, "true") || !strcmp(attribute, "1")) return true;
733 
734  return false;
735  }
736 
737 protected:
738  /**
739  * Handle any post creation
740  */
742  {}
743 
744  /**
745  * Start element handler wrapper
746  * @param void *pUserData
747  * @param const XML_Char *pszName
748  * @param const XML_Char **papszAttrs
749  */
750  static void startElementHandler(void *pUserData,
751  const XML_Char *pszName,
752  const XML_Char **papszAttrs)
753  {
754  CType *pThis = static_cast <CType *>((CExpatTemplate <CType> *) pUserData);
755  pThis->onStartElement(pszName, papszAttrs);
756  }
757 
758  /**
759  * End element handler wrapper
760  * @param void *pUserData
761  * @param const XML_Char *pszName
762  */
763  static void endElementHandler(void *pUserData,
764  const XML_Char *pszName)
765  {
766  CType *pThis = static_cast <CType *>((CExpatTemplate <CType> *) pUserData);
767  pThis->onEndElement(pszName);
768  }
769 
770  /**
771  * Character data handler wrapper
772  * @param void *pUserData
773  * @param const XML_Char *pszData
774  * @param int nLength
775  */
776  static void characterDataHandler(void *pUserData,
777  const XML_Char *pszData,
778  int nLength)
779  {
780  CType *pThis = static_cast <CType *>((CExpatTemplate <CType> *) pUserData);
781  pThis->onCharacterData(pszData, nLength);
782  }
783 
784  /**
785  * Processing instruction handler wrapper
786  * @param void *pUserData
787  * @param const XML_Char *pszTarget
788  * @param const XML_Char *pszData
789  */
790  static void processingInstructionHandler(void *pUserData,
791  const XML_Char *pszTarget,
792  const XML_Char *pszData)
793  {
794  CType *pThis = static_cast <CType *>((CExpatTemplate <CType> *) pUserData);
795  pThis->onProcessingInstruction(pszTarget, pszData);
796  }
797 
798  /**
799  * Comment handler wrapper
800  * @param void *pUserData
801  * @param const XML_Char *pszData
802  */
803  static void commentHandler(void *pUserData,
804  const XML_Char *pszData)
805  {
806  CType *pThis = static_cast <CType *>((CExpatTemplate <CType> *) pUserData);
807  pThis->onComment(pszData);
808  }
809 
810  /**
811  * Start CDATA section wrapper
812  * @param void *pUserData
813  */
814  static void startCdataSectionHandler(void *pUserData)
815  {
816  CType *pThis = static_cast <CType *>((CExpatTemplate <CType> *) pUserData);
817  pThis->onStartCdataSection();
818  }
819 
820  /**
821  * End CDATA section wrapper
822  * @param void *pUserData
823  */
824  static void endCdataSectionHandler(void *pUserData)
825  {
826  CType *pThis = static_cast <CType *>((CExpatTemplate <CType> *) pUserData);
827  pThis->onEndCdataSection();
828  }
829 
830  /**
831  * Default wrapper
832  * @param void *pUserData
833  * @param const XML_Char *pszData
834  * @param int nLength
835  */
836  static void defaultHandler(void *pUserData,
837  const XML_Char *pszData,
838  int nLength)
839  {
840  CType *pThis = static_cast <CType *>((CExpatTemplate <CType> *) pUserData);
841  pThis->onDefault(pszData, nLength);
842  }
843 
844  /**
845  * External entity ref wrapper
846  * @param void *pUserData
847  * @param const XML_Char *pszContext
848  * @param const XML_Char *pszBase
849  * @param const XML_Char *pszSystemID
850  * @param const XML_Char *pszPublicID
851  */
852  static int externalEntityRefHandler(XML_Parser pUserData,
853  const XML_Char *pszContext,
854  const XML_Char *pszBase,
855  const XML_Char *pszSystemID,
856  const XML_Char *pszPublicID)
857  {
858  CType *pThis = static_cast <CType *>((CExpatTemplate <CType> *) pUserData);
859  return pThis->onExternalEntityRef(pszContext,
860  pszBase, pszSystemID, pszPublicID) ? 1 : 0;
861  }
862 
863  /**
864  * Skipped entity handler
865  * This is called in two situations:
866  * 1) An entity reference is encountered for which no declaration
867  * has been read *and* this is not an error.
868  * 2) An internal entity reference is read, but not expanded, because
869  * XML_SetDefaultHandler has been called.
870  * Note: skipped parameter entities in declarations and skipped general
871  * entities in attribute values cannot be reported, because
872  * the event would be out of sync with the reporting of the
873  * declarations or attribute values
874  * @param void *pUserData
875  * @param const XML_Char *entityName
876  * @param int is_parameter_entity
877  */
878  static void skippedEntityHandler(void *pUserData,
879  const XML_Char *entityName,
880  int is_parameter_entity)
881  {
882  CType *pThis = static_cast <CType *>((CExpatTemplate <CType> *) pUserData);
883  pThis->onSkippedEntityHandler(entityName, is_parameter_entity);
884  }
885 
886  /**
887  * Unknown encoding wrapper
888  * @param void *pUserData
889  * @param const XML_Char *pszName
890  * @param XML_Encoding *pInfo
891  */
892  static int unknownEncodingHandler(void * pUserData,
893  const XML_Char *pszName,
894  XML_Encoding *pInfo)
895  {
896  CType *pThis = static_cast <CType *>((CExpatTemplate <CType> *) pUserData);
897  return pThis->onUnknownEncoding(pszName, pInfo) ? 1 : 0;
898  }
899 
900  /**
901  * Start namespace decl wrapper
902  * @param void *pUserData
903  * @param const XML_Char *pszPrefix
904  * @param const XML_Char *pszURI
905  */
906  static void startNamespaceDeclHandler(void *pUserData,
907  const XML_Char *pszPrefix,
908  const XML_Char *pszURI)
909  {
910  CType *pThis = static_cast <CType *>((CExpatTemplate <CType> *) pUserData);
911  pThis->onStartNamespaceDecl(pszPrefix, pszURI);
912  }
913 
914  /**
915  * End namespace decl wrapper
916  * @param void *pUserData
917  * @param const XML_Char *pszPrefix
918  */
919  static void endNamespaceDeclHandler(void *pUserData,
920  const XML_Char *pszPrefix)
921  {
922  CType *pThis = static_cast <CType *>((CExpatTemplate <CType> *) pUserData);
923  pThis->onEndNamespaceDecl(pszPrefix);
924  }
925 
926  /**
927  * XML declaration wrapper
928  * @param void *pUserData
929  * @param const XML_Char *pszVersion
930  * @param const XML_Char *pszEncoding
931  * @param int nStandalone
932  */
933  static void xmlDeclHandler(void *pUserData,
934  const XML_Char *pszVersion,
935  const XML_Char *pszEncoding,
936  int nStandalone)
937  {
938  CType *pThis = static_cast <CType *>((CExpatTemplate <CType> *) pUserData);
939  pThis->onXmlDecl(pszVersion, pszEncoding, nStandalone != 0);
940  }
941 
942  /**
943  * Start Doctype declaration wrapper
944  * @param void *pUserData
945  * @param const XML_Char *pszDoctypeName
946  * @param const XML_Char *pszSysID
947  * @param const XML_Char *pszPubID
948  * @param int nHasInternalSubset
949  */
950  static void startDoctypeDeclHandler(void *pUserData,
951  const XML_Char *pszDoctypeName,
952  const XML_Char *pszSysID,
953  const XML_Char *pszPubID,
954  int nHasInternalSubset)
955  {
956  CType *pThis = static_cast <CType *>((CExpatTemplate <CType> *) pUserData);
957  pThis->onStartDoctypeDecl(pszDoctypeName, pszSysID,
958  pszPubID, nHasInternalSubset != 0);
959  }
960 
961  /**
962  * End Doctype declaration wrapper
963  * @param void *pUserData
964  */
965  static void endDoctypeDeclHandler(void *pUserData)
966  {
967  CType *pThis = static_cast <CType *>((CExpatTemplate <CType> *) pUserData);
968  pThis->onEndDoctypeDecl();
969  }
970 };
971 
972 /**
973  * CExpat class.
974  * The class CExpat is an instantiation of the CExpatTemplate class above.
975  * Is can be used where late binding is preferred to template behaviour.
976  *
977  * Created for Copasi by Stefan Hoops 2003
978  */
979 class CExpat : public CExpatTemplate <CExpat>
980 {
981 public:
982 
983  /**
984  * Default constructor
985  */
986  CExpat();
987 
988  /**
989  * Destructor
990  */
991  virtual ~CExpat();
992 
993  /**
994  * Start element handler
995  * @param const XML_Char *pszName
996  * @param const XML_Char **papszAttrs
997  */
998  virtual void onStartElement(const XML_Char *pszName,
999  const XML_Char **papszAttrs);
1000 
1001  /**
1002  * End element handler
1003  * @param const XML_Char *pszName
1004  */
1005  virtual void onEndElement(const XML_Char *pszName);
1006 
1007  /**
1008  * Character data handler
1009  * @param const XML_Char *pszData
1010  * @param int nLength
1011  */
1012  virtual void onCharacterData(const XML_Char *pszData,
1013  int nLength);
1014 
1015  /**
1016  * Processing instruction handler
1017  * @param const XML_Char *pszTarget
1018  * @param const XML_Char *pszData
1019  */
1020  virtual void onProcessingInstruction(const XML_Char *pszTarget,
1021  const XML_Char *pszData);
1022 
1023  /**
1024  * Comment handler
1025  * @param const XML_Char *pszData
1026  */
1027  virtual void onComment(const XML_Char *pszData);
1028 
1029  /**
1030  * Start CDATA section handler
1031  */
1032  virtual void onStartCdataSection();
1033 
1034  /**
1035  * End CDATA section handler
1036  */
1037  virtual void onEndCdataSection();
1038 
1039  /**
1040  * Default handler
1041  * @param const XML_Char *pszData
1042  * @param int nLength
1043  */
1044  virtual void onDefault(const XML_Char *pszData,
1045  int nLength);
1046 
1047  /**
1048  * External entity ref handler
1049  * @param const XML_Char *pszContext
1050  * @param const XML_Char *pszBase
1051  * @param const XML_Char *pszSystemID
1052  * @param const XML_Char *pszPublicID
1053  */
1054  virtual bool onExternalEntityRef(const XML_Char *pszContext,
1055  const XML_Char *pszBase,
1056  const XML_Char *pszSystemID,
1057  const XML_Char *pszPublicID);
1058 
1059  /**
1060  * Skipped entity handler
1061  * This is called in two situations:
1062  * 1) An entity reference is encountered for which no declaration
1063  * has been read *and* this is not an error.
1064  * 2) An internal entity reference is read, but not expanded, because
1065  * XML_SetDefaultHandler has been called.
1066  * Note: skipped parameter entities in declarations and skipped general
1067  * entities in attribute values cannot be reported, because
1068  * the event would be out of sync with the reporting of the
1069  * declarations or attribute values
1070  * @param const XML_Char *entityName
1071  * @param int is_parameter_entity
1072  */
1073  virtual void onSkippedEntityHandler(const XML_Char * /* entityName */,
1074  int /* is_parameter_entity */);
1075 
1076  /**
1077  * Unknown encoding handler
1078  * @param const XML_Char *pszName
1079  * @param XML_Encoding *pInfo
1080  */
1081  virtual bool onUnknownEncoding(const XML_Char *pszName,
1082  XML_Encoding *pInfo);
1083 
1084  /**
1085  * Start namespace declaration handler
1086  * @param const XML_Char *pszPrefix
1087  * @param const XML_Char *pszURI
1088  */
1089  virtual void onStartNamespaceDecl(const XML_Char *pszPrefix,
1090  const XML_Char *pszURI);
1091 
1092  /**
1093  * End namespace declaration handler
1094  * @param const XML_Char *pszPrefix
1095  */
1096  virtual void onEndNamespaceDecl(const XML_Char *pszPrefix);
1097 
1098  /**
1099  * XML declaration handler
1100  * @param const XML_Char *pszVersion
1101  * @param const XML_Char *pszEncoding
1102  * @param bool fStandalone
1103  */
1104  virtual void onXmlDecl(const XML_Char *pszVersion,
1105  const XML_Char *pszEncoding,
1106  bool fStandalone);
1107 
1108  /**
1109  * Start DOCTYPE declaration handler
1110  * @param const XML_Char *pszDoctypeName
1111  * @param const XML_Char *pszSysID
1112  * @param const XML_Char *pszPubID
1113  * @param bool fHasInternalSubset
1114  */
1115  virtual void onStartDoctypeDecl(const XML_Char *pszDoctypeName,
1116  const XML_Char *pszSysID,
1117  const XML_Char *pszPubID,
1118  bool fHasInternalSubset);
1119 
1120  /**
1121  * End DOCTYPE declaration handler
1122  */
1123  virtual void onEndDoctypeDecl();
1124 };
1125 
1126 #endif // COPASI_CExpat
virtual void onEndElement(const XML_Char *pszName)
Definition: CExpat.cpp:41
void onStartNamespaceDecl(const XML_Char *pszPrefix, const XML_Char *pszURI)
Definition: CExpat.h:633
CExpat()
Definition: CExpat.cpp:31
virtual void onEndDoctypeDecl()
Definition: CExpat.cpp:97
void enableEndElementHandler(bool fEnable=true)
Definition: CExpat.h:223
static const XML_LChar * getErrorString(enum XML_Error nError)
Definition: CExpat.h:453
void enableElementHandler(bool fEnable=true)
Definition: CExpat.h:233
void onEndNamespaceDecl(const XML_Char *pszPrefix)
Definition: CExpat.h:641
long getCurrentByteIndex()
Definition: CExpat.h:460
void onStartDoctypeDecl(const XML_Char *pszDoctypeName, const XML_Char *pszSysID, const XML_Char *pszPubID, bool fHasInternalSubset)
Definition: CExpat.h:662
void enableDefaultHandler(bool fEnable=true, bool fExpand=true)
Definition: CExpat.h:309
virtual void onStartCdataSection()
Definition: CExpat.cpp:55
static bool toBool(const char *attribute)
Definition: CExpat.h:728
void enableStartDoctypeDeclHandler(bool fEnable=true)
Definition: CExpat.h:402
static const XML_LChar * getExpatVersion()
Definition: CExpat.h:510
virtual ~CExpat()
Definition: CExpat.cpp:34
void onXmlDecl(const XML_Char *pszVersion, const XML_Char *pszEncoding, bool fStandalone)
Definition: CExpat.h:650
bool create(const XML_Char *pszEncoding=NULL, const XML_Char *pszSep=NULL)
Definition: CExpat.h:79
static void defaultHandler(void *pUserData, const XML_Char *pszData, int nLength)
Definition: CExpat.h:836
virtual void onProcessingInstruction(const XML_Char *pszTarget, const XML_Char *pszData)
Definition: CExpat.cpp:48
bool parseBuffer(int nLength, bool fIsFinal=true)
Definition: CExpat.h:194
virtual void onStartDoctypeDecl(const XML_Char *pszDoctypeName, const XML_Char *pszSysID, const XML_Char *pszPubID, bool fHasInternalSubset)
Definition: CExpat.cpp:91
static void skippedEntityHandler(void *pUserData, const XML_Char *entityName, int is_parameter_entity)
Definition: CExpat.h:878
const char * getAttributeValue(const std::string &name, const char **attributes, const bool &required=true) const
Definition: CExpat.h:685
#define MCXML
XML_Parser mParser
Definition: CExpat.h:48
void onStartCdataSection()
Definition: CExpat.h:572
void enableEndDoctypeDeclHandler(bool fEnable=true)
Definition: CExpat.h:413
void onDefault(const XML_Char *pszData, int nLength)
Definition: CExpat.h:586
static void startNamespaceDeclHandler(void *pUserData, const XML_Char *pszPrefix, const XML_Char *pszURI)
Definition: CExpat.h:906
static void xmlDeclHandler(void *pUserData, const XML_Char *pszVersion, const XML_Char *pszEncoding, int nStandalone)
Definition: CExpat.h:933
static void commentHandler(void *pUserData, const XML_Char *pszData)
Definition: CExpat.h:803
#define C_INT32
Definition: copasi.h:90
static int unknownEncodingHandler(void *pUserData, const XML_Char *pszName, XML_Encoding *pInfo)
Definition: CExpat.h:892
void enableEndCdataSectionHandler(bool fEnable=true)
Definition: CExpat.h:287
virtual bool onExternalEntityRef(const XML_Char *pszContext, const XML_Char *pszBase, const XML_Char *pszSystemID, const XML_Char *pszPublicID)
Definition: CExpat.cpp:65
static void startElementHandler(void *pUserData, const XML_Char *pszName, const XML_Char **papszAttrs)
Definition: CExpat.h:750
virtual void onEndCdataSection()
Definition: CExpat.cpp:58
enum XML_Error getErrorCode()
Definition: CExpat.h:435
void enableStartCdataSectionHandler(bool fEnable=true)
Definition: CExpat.h:276
virtual void onComment(const XML_Char *pszData)
Definition: CExpat.cpp:52
virtual void onDefault(const XML_Char *pszData, int nLength)
Definition: CExpat.cpp:61
void enableCdataSectionHandler(bool fEnable=true)
Definition: CExpat.h:298
const char * getInputContext(int *pnOffset, int *pnSize)
Definition: CExpat.h:500
virtual void onXmlDecl(const XML_Char *pszVersion, const XML_Char *pszEncoding, bool fStandalone)
Definition: CExpat.cpp:86
virtual void onStartNamespaceDecl(const XML_Char *pszPrefix, const XML_Char *pszURI)
Definition: CExpat.cpp:79
~CExpatTemplate()
Definition: CExpat.h:72
void enableXmlDeclHandler(bool fEnable=true)
Definition: CExpat.h:392
static void endNamespaceDeclHandler(void *pUserData, const XML_Char *pszPrefix)
Definition: CExpat.h:919
void onComment(const XML_Char *pszData)
Definition: CExpat.h:566
void enableDoctypeDeclHandler(bool fEnable=true)
Definition: CExpat.h:424
void enableEndNamespaceDeclHandler(bool fEnable=true)
Definition: CExpat.h:371
void enableStartElementHandler(bool fEnable=true)
Definition: CExpat.h:213
void onCharacterData(const XML_Char *pszData, int nLength)
Definition: CExpat.h:550
void enableCommentHandler(bool fEnable=true)
Definition: CExpat.h:266
int getCurrentColumnNumber()
Definition: CExpat.h:480
void onProcessingInstruction(const XML_Char *pszTarget, const XML_Char *pszData)
Definition: CExpat.h:558
virtual void onCharacterData(const XML_Char *pszData, int nLength)
Definition: CExpat.cpp:44
void * getBuffer(int nLength)
Definition: CExpat.h:203
void enableStartNamespaceDeclHandler(bool fEnable=true)
Definition: CExpat.h:360
void enableNamespaceDeclHandler(bool fEnable=true)
Definition: CExpat.h:382
bool onUnknownEncoding(const XML_Char *pszName, XML_Encoding *pInfo)
Definition: CExpat.h:625
static void startCdataSectionHandler(void *pUserData)
Definition: CExpat.h:814
void onEndElement(const XML_Char *pszName)
Definition: CExpat.h:542
static void endElementHandler(void *pUserData, const XML_Char *pszName)
Definition: CExpat.h:763
const char * getAttributeValue(const std::string &name, const char **attributes, const char *def) const
Definition: CExpat.h:711
CExpatTemplate()
Definition: CExpat.h:65
bool onExternalEntityRef(const XML_Char *pszContext, const XML_Char *pszBase, const XML_Char *pszSystemID, const XML_Char *pszPublicID)
Definition: CExpat.h:596
void onEndCdataSection()
Definition: CExpat.h:578
static void endCdataSectionHandler(void *pUserData)
Definition: CExpat.h:824
void enableSkippedEntityHandler(bool fEnable=true)
Definition: CExpat.h:337
static void characterDataHandler(void *pUserData, const XML_Char *pszData, int nLength)
Definition: CExpat.h:776
void onEndDoctypeDecl()
Definition: CExpat.h:671
static void endDoctypeDeclHandler(void *pUserData)
Definition: CExpat.h:965
virtual void onEndNamespaceDecl(const XML_Char *pszPrefix)
Definition: CExpat.cpp:83
void onSkippedEntityHandler(const XML_Char *, int)
Definition: CExpat.h:616
static int externalEntityRefHandler(XML_Parser pUserData, const XML_Char *pszContext, const XML_Char *pszBase, const XML_Char *pszSystemID, const XML_Char *pszPublicID)
Definition: CExpat.h:852
virtual void onStartElement(const XML_Char *pszName, const XML_Char **papszAttrs)
Definition: CExpat.cpp:37
virtual void onSkippedEntityHandler(const XML_Char *, int)
Definition: CExpat.cpp:71
static void startDoctypeDeclHandler(void *pUserData, const XML_Char *pszDoctypeName, const XML_Char *pszSysID, const XML_Char *pszPubID, int nHasInternalSubset)
Definition: CExpat.h:950
void enableCharacterDataHandler(bool fEnable=true)
Definition: CExpat.h:244
int getCurrentByteCount()
Definition: CExpat.h:490
virtual bool onUnknownEncoding(const XML_Char *pszName, XML_Encoding *pInfo)
Definition: CExpat.cpp:75
int getCurrentLineNumber() const
Definition: CExpat.h:470
bool parse(const char *pszBuffer, int nLength=-1, bool fIsFinal=true)
Definition: CExpat.h:135
void onStartElement(const XML_Char *pszName, const XML_Char **papszAttrs)
Definition: CExpat.h:535
const XML_LChar * getErrorString()
Definition: CExpat.h:445
void onPostCreate()
Definition: CExpat.h:741
static void getExpatVersion(int &nMajor, int &nMinor, int &nMicro)
Definition: CExpat.h:521
void enableExternalEntityRefHandler(bool fEnable=true)
Definition: CExpat.h:326
void enableProcessingInstructionHandler(bool fEnable=true)
Definition: CExpat.h:255
void enableUnknownEncodingHandler(bool fEnable=true)
Definition: CExpat.h:348
void destroy()
Definition: CExpat.h:54
Definition: CExpat.h:979
static void processingInstructionHandler(void *pUserData, const XML_Char *pszTarget, const XML_Char *pszData)
Definition: CExpat.h:790