COPASI API  4.16.103
CXMLHandler.h
Go to the documentation of this file.
1 // Copyright (C) 2010 - 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 // 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  * CXMLHandler class.
17  * This class is the base class of all XML event handlers.
18  *
19  * Created for COPASI by Stefan Hoops 2003
20  * Copyright Stefan Hoops
21  */
22 
23 #ifndef COPASI_CXMLHandler
24 #define COPASI_CXMLHandler
25 
26 #include <stack>
27 #include <string>
28 #include <iostream>
29 
30 #include "expat.h"
31 
32 class CCopasiObject;
33 
34 template<class CType, class CCommon>
36 {
37  // Attributes
38 protected:
39  /**
40  * The underlying parser.
41  */
42  CType & mParser;
43 
44  /**
45  * The shared elements between all element handlers of a parser
46  */
47  CCommon & mCommon;
48 
49  /**
50  * The currently processed element.
51  */
53 
54  /**
55  *
56  */
58 
59  /**
60  *
61  */
63 
64  // Operations
65 public:
66  /**
67  * Constructor
68  */
69  CXMLElementHandler(CType & parser, CCommon & common):
70  mParser(parser),
71  mCommon(common),
72  mCurrentElement(-1),
73  mpCurrentHandler(NULL),
75  {}
76 
77  /**
78  * Destructor
79  */
80  virtual ~CXMLElementHandler() {}
81 
82  /**
83  * Start element handler
84  * @param const XML_Char *pszName
85  * @param const XML_Char **papszAttrs
86  */
87  virtual void start(const XML_Char * C_UNUSED(pszName),
88  const XML_Char ** C_UNUSED(papszAttrs)) {}
89 
90  /**
91  * End element handler
92  * @param const XML_Char *pszName
93  */
94  virtual void end(const XML_Char * C_UNUSED(pszName)) {}
95 
96  /**
97  * Reset the element handler to start values.
98  */
99  virtual void reset() {}
100 
101 protected:
102  /**
103  * This assures that we do not accidentally delete common parser handlers.
104  */
106  {
107  if (mpCurrentHandler != NULL &&
108  mpCurrentHandler != &mParser.mUnknownElement &&
109  mpCurrentHandler != &mParser.mCharacterDataElement &&
110  mpCurrentHandler != &mParser.mListOfUnsupportedAnnotationsElement &&
111  mpCurrentHandler != &mParser.mCommentElement &&
112  mpCurrentHandler != &mParser.mMiriamAnnotationElement)
113  {
114  delete mpCurrentHandler;
115  mpCurrentHandler = NULL;
116  }
117  }
118 
119  void addFix(const std::string & key, CCopasiObject * pObject)
120  {
121  if (!mCommon.KeyMap.addFix(key, pObject))
122  {
123  CCopasiMessage(CCopasiMessage::EXCEPTION, MCXML + 22, key.c_str(), mParser.getCurrentLineNumber());
124  }
125  }
126 };
127 
128 #endif // COPASI_CXMLHandler
#define MCXML
#define C_UNUSED(p)
Definition: copasi.h:220
#define C_INT32
Definition: copasi.h:90
CCommon & mCommon
Definition: CXMLHandler.h:47
CXMLElementHandler(CType &parser, CCommon &common)
Definition: CXMLHandler.h:69
virtual void end(const XML_Char *C_UNUSED(pszName))
Definition: CXMLHandler.h:94
void addFix(const std::string &key, CCopasiObject *pObject)
Definition: CXMLHandler.h:119
virtual void reset()
Definition: CXMLHandler.h:99
virtual void start(const XML_Char *C_UNUSED(pszName), const XML_Char **C_UNUSED(papszAttrs))
Definition: CXMLHandler.h:87
virtual ~CXMLElementHandler()
Definition: CXMLHandler.h:80
CXMLElementHandler * mpCurrentHandler
Definition: CXMLHandler.h:57
C_INT32 mLastKnownElement
Definition: CXMLHandler.h:62
void deleteCurrentHandler()
Definition: CXMLHandler.h:105
C_INT32 mCurrentElement
Definition: CXMLHandler.h:52