COPASI API  4.16.103
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | Static Private Member Functions | Private Attributes | List of all members
CAnnotation Class Reference

#include <CAnnotation.h>

Inheritance diagram for CAnnotation:
Inheritance graph
[legend]
Collaboration diagram for CAnnotation:
Collaboration graph
[legend]

Public Types

typedef std::map< std::string,
std::string > 
UnsupportedAnnotation
 

Public Member Functions

bool addUnsupportedAnnotation (const std::string &name, const std::string &xml)
 
 CAnnotation ()
 
 CAnnotation (const CAnnotation &src)
 
virtual const std::string & getKey () const
 
const std::string & getMiriamAnnotation () const
 
const std::string & getNotes () const
 
UnsupportedAnnotationgetUnsupportedAnnotations ()
 
const UnsupportedAnnotationgetUnsupportedAnnotations () const
 
bool operator== (const CAnnotation &rhs) const
 
bool removeUnsupportedAnnotation (const std::string &name)
 
bool replaceUnsupportedAnnotation (const std::string &name, const std::string &xml)
 
void setMiriamAnnotation (const std::string &miriamAnnotation, const std::string &newId, const std::string &oldId)
 
void setNotes (const std::string &notes)
 
virtual ~CAnnotation ()
 

Static Public Member Functions

static CAnnotationcastObject (CCopasiObject *pObject)
 
static const CAnnotationcastObject (const CCopasiObject *pObject)
 

Protected Attributes

std::string mKey
 

Static Private Member Functions

static bool isValidXML (const std::string &xml)
 

Private Attributes

std::string mMiriamAnnotation
 
std::string mNotes
 
UnsupportedAnnotation mUnsupportedAnnotations
 
std::string mXMLId
 

Detailed Description

Definition at line 14 of file CAnnotation.h.

Member Typedef Documentation

typedef std::map< std::string, std::string > CAnnotation::UnsupportedAnnotation

Definition at line 17 of file CAnnotation.h.

Constructor & Destructor Documentation

CAnnotation::CAnnotation ( )

Default constructor

Definition at line 81 of file CAnnotation.cpp.

81  :
82  mKey(""),
83  mNotes(),
85  mXMLId(),
87 {}
std::string mNotes
Definition: CAnnotation.h:125
std::string mMiriamAnnotation
Definition: CAnnotation.h:130
UnsupportedAnnotation mUnsupportedAnnotations
Definition: CAnnotation.h:141
std::string mKey
Definition: CAnnotation.h:119
std::string mXMLId
Definition: CAnnotation.h:135
CAnnotation::CAnnotation ( const CAnnotation src)

Copy constructor

Parameters
constCAnnotation & src

Definition at line 89 of file CAnnotation.cpp.

89  :
90  mKey(""),
91  mNotes(src.mNotes),
93  mXMLId(src.mXMLId),
95 {}
std::string mNotes
Definition: CAnnotation.h:125
std::string mMiriamAnnotation
Definition: CAnnotation.h:130
UnsupportedAnnotation mUnsupportedAnnotations
Definition: CAnnotation.h:141
std::string mKey
Definition: CAnnotation.h:119
std::string mXMLId
Definition: CAnnotation.h:135
CAnnotation::~CAnnotation ( )
virtual

Destructor

Definition at line 97 of file CAnnotation.cpp.

References CCopasiRootContainer::getKeyFactory(), mKey, and CKeyFactory::remove().

98 {
100 }
bool remove(const std::string &key)
std::string mKey
Definition: CAnnotation.h:119
static CKeyFactory * getKeyFactory()

Member Function Documentation

bool CAnnotation::addUnsupportedAnnotation ( const std::string &  name,
const std::string &  xml 
)

Add an unsupported annotation

Parameters
conststd::string & name
conststd::string & xml
Returns
bool success

Definition at line 211 of file CAnnotation.cpp.

References CCopasiMessage::ERROR, isValidXML(), MCAnnotation, and mUnsupportedAnnotations.

Referenced by SBMLImporter::importNotes().

212 {
213  // The name must not be empty
214  if (name == "")
215  {
217  return false;
218  }
219 
220  // The name must be unique
222  {
224  return false;
225  }
226 
227  // We need to check whether we have valid XML.
228  if (!isValidXML(xml))
229  {
231  return false;
232  }
233 
235 
236  return true;
237 }
UnsupportedAnnotation mUnsupportedAnnotations
Definition: CAnnotation.h:141
#define MCAnnotation
static bool isValidXML(const std::string &xml)
char name[1]
Definition: stdsoap2.h:1342
CAnnotation * CAnnotation::castObject ( CCopasiObject pObject)
static

Definition at line 32 of file CAnnotation.cpp.

Referenced by CMIRIAMInfo::load(), CQNotes::load(), CMIRIAMInfo::save(), CQNotes::save(), and CQMiriamWidget::showEvent().

33 {
34  CModelEntity * pEntity = NULL;
35  CEvent * pEvent = NULL;
36  CReaction * pReaction = NULL;
37  CFunction * pFunction = NULL;
38  CModelParameterSet * pParameterSet = NULL;
39 
40  if ((pEntity = dynamic_cast< CModelEntity * >(pObject)) != NULL)
41  return static_cast< CAnnotation * >(pEntity);
42 
43  if ((pEvent = dynamic_cast< CEvent * >(pObject)) != NULL)
44  return static_cast< CAnnotation * >(pEvent);
45 
46  if ((pReaction = dynamic_cast< CReaction * >(pObject)) != NULL)
47  return static_cast< CAnnotation * >(pReaction);
48 
49  if ((pParameterSet = dynamic_cast< CModelParameterSet * >(pObject)) != NULL)
50  return static_cast< CAnnotation * >(pParameterSet);
51 
52  if ((pFunction = dynamic_cast< CFunction * >(pObject)) != NULL)
53  return static_cast< CAnnotation * >(pFunction);
54 
55  return NULL;
56 }
Definition: CEvent.h:152
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
const CAnnotation * CAnnotation::castObject ( const CCopasiObject pObject)
static

Definition at line 59 of file CAnnotation.cpp.

60 {
61  const CModelEntity * pEntity = NULL;
62  const CEvent * pEvent = NULL;
63  const CReaction * pReaction = NULL;
64  const CFunction * pFunction = NULL;
65 
66  if ((pEntity = dynamic_cast< const CModelEntity * >(pObject)) != NULL)
67  return static_cast< const CAnnotation * >(pEntity);
68 
69  if ((pEvent = dynamic_cast< const CEvent * >(pObject)) != NULL)
70  return static_cast< const CAnnotation * >(pEvent);
71 
72  if ((pReaction = dynamic_cast< const CReaction * >(pObject)) != NULL)
73  return static_cast< const CAnnotation * >(pReaction);
74 
75  if ((pFunction = dynamic_cast< const CFunction * >(pObject)) != NULL)
76  return static_cast< const CAnnotation * >(pFunction);
77 
78  return NULL;
79 }
Definition: CEvent.h:152
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
const std::string & CAnnotation::getKey ( ) const
virtual

Retrieve the key

Returns
std::string key

Reimplemented in CModel, CEvent, CReaction, CModelEntity, CFunction, and CModelParameterSet.

Definition at line 103 of file CAnnotation.cpp.

References mKey.

Referenced by CFunction::getKey(), CModelEntity::getKey(), CReaction::getKey(), CEvent::getKey(), and CMIRIAMInfo::save().

104 {
105  return mKey;
106 }
std::string mKey
Definition: CAnnotation.h:119
const std::string & CAnnotation::getMiriamAnnotation ( ) const
const std::string & CAnnotation::getNotes ( ) const
CAnnotation::UnsupportedAnnotation & CAnnotation::getUnsupportedAnnotations ( )

Retrieve the unsupported annotations in xml format.

Returns
std::map< std::string, std::string > & unsupportedAnnotations

Definition at line 201 of file CAnnotation.cpp.

References mUnsupportedAnnotations.

Referenced by CCopasiXMLParser::ReactionElement::end(), CCopasiXMLParser::EventElement::end(), CCopasiXMLParser::ModelElement::end(), CCopasiXMLParser::FunctionElement::end(), CCopasiXML::saveAnnotation(), and CSBMLExporter::setSBMLNotes().

202 {
204 }
UnsupportedAnnotation mUnsupportedAnnotations
Definition: CAnnotation.h:141
const CAnnotation::UnsupportedAnnotation & CAnnotation::getUnsupportedAnnotations ( ) const

Definition at line 206 of file CAnnotation.cpp.

References mUnsupportedAnnotations.

207 {
209 }
UnsupportedAnnotation mUnsupportedAnnotations
Definition: CAnnotation.h:141
bool CAnnotation::isValidXML ( const std::string &  xml)
staticprivate

Definition at line 275 of file CAnnotation.cpp.

References BUFFER_SIZE, CCopasiMessage::getLastMessage(), CExpatTemplate< CType >::parse(), and CCopasiMessage::size().

Referenced by addUnsupportedAnnotation(), and replaceUnsupportedAnnotation().

276 {
277  std::istringstream XML;
278  XML.str(xml);
279  XML.imbue(std::locale::classic());
280  XML.precision(16);
281 
282  bool done = false;
283 
284  CVersion Version;
285  CCopasiXMLParser Parser(Version);
286 
287  size_t Size = CCopasiMessage::size();
288 
289 #define BUFFER_SIZE 0xfffe
290  char * pBuffer = new char[BUFFER_SIZE + 1];
291 
292  while (!done)
293  {
294  XML.get(pBuffer, BUFFER_SIZE, 0);
295 
296  if (XML.eof()) done = true;
297 
298  if (XML.fail() && !done)
299  {
300  done = true;
301  return false;
302  }
303 
304  if (!Parser.parse(pBuffer, -1, done))
305  {
306  done = true;
307  return false;
308  }
309  }
310 
311  delete [] pBuffer;
312 #undef BUFFER_SIZE
313 
314  // Remove error messages created by setExpression as this may fail
315  // due to incomplete model specification at this time.
316  while (CCopasiMessage::size() > Size)
318 
319  return true;
320 }
static size_t size()
#define BUFFER_SIZE
static CCopasiMessage getLastMessage()
bool CAnnotation::operator== ( const CAnnotation rhs) const

Comparison operator

Parameters
constCAnnotation & rhs
Returns
bool equal

Definition at line 129 of file CAnnotation.cpp.

References CRDFUtilities::fixLocalFileAboutReference(), mMiriamAnnotation, mNotes, and mXMLId.

130 {
131  if (mNotes != rhs.mNotes)
132  return false;
133 
134  std::string Annotation = mMiriamAnnotation;
136 
137  // We need to ignore white spaces when comparing.
138  std::string::const_iterator it = Annotation.begin();
139  std::string::const_iterator end = Annotation.end();
140  std::string::const_iterator itRhs = rhs.mMiriamAnnotation.begin();
141  std::string::const_iterator endRhs = rhs.mMiriamAnnotation.end();
142 
143  while (it != end && itRhs != endRhs)
144  {
145  if (*it == * itRhs)
146  {
147  ++it;
148  ++itRhs;
149 
150  continue;
151  }
152 
153  // Advance past white spaces
154  while (it != end)
155  {
156  if (*it == '\x20' || *it == '\x09' || *it == '\x0d' || *it == '\x0a')
157  {
158  ++it;
159 
160  continue;
161  }
162 
163  break;
164  }
165 
166  // Advance past white spaces
167  while (itRhs != endRhs)
168  {
169  if (*itRhs == '\x20' || *itRhs == '\x09' || *itRhs == '\x0d' || *itRhs == '\x0a')
170  {
171  ++itRhs;
172 
173  continue;
174  }
175 
176  break;
177  }
178 
179  if (it == end && itRhs == endRhs)
180  {
181  return true;
182  }
183 
184  if (it == end || itRhs == endRhs)
185  {
186  return false;
187  }
188 
189  if (*it != *itRhs)
190  {
191  return false;
192  }
193 
194  ++it;
195  ++itRhs;
196  }
197 
198  return true;
199 }
std::string mNotes
Definition: CAnnotation.h:125
static unsigned C_INT32 fixLocalFileAboutReference(std::string &rdfXml, const std::string &newId, const std::string &oldId)
std::string mMiriamAnnotation
Definition: CAnnotation.h:130
std::string mXMLId
Definition: CAnnotation.h:135
bool CAnnotation::removeUnsupportedAnnotation ( const std::string &  name)

Remove an unsupported annotation

Parameters
conststd::string & name
Returns
bool success

Definition at line 260 of file CAnnotation.cpp.

References mUnsupportedAnnotations.

261 {
262  UnsupportedAnnotation::iterator it = mUnsupportedAnnotations.find(name);
263 
264  if (it == mUnsupportedAnnotations.end())
265  {
266  return false;
267  }
268 
269  mUnsupportedAnnotations.erase(it);
270 
271  return true;
272 }
UnsupportedAnnotation mUnsupportedAnnotations
Definition: CAnnotation.h:141
char name[1]
Definition: stdsoap2.h:1342
bool CAnnotation::replaceUnsupportedAnnotation ( const std::string &  name,
const std::string &  xml 
)

Replace an unsupported annotation

Parameters
conststd::string & name
conststd::string & xml
Returns
bool success

Definition at line 239 of file CAnnotation.cpp.

References CCopasiMessage::ERROR, isValidXML(), MCAnnotation, and mUnsupportedAnnotations.

240 {
241  // We need to check whether we have valid XML.
242  if (!isValidXML(xml))
243  {
245  return false;
246  }
247 
248  // The annotation must exist
250  {
252  return false;
253  }
254 
256 
257  return true;
258 }
UnsupportedAnnotation mUnsupportedAnnotations
Definition: CAnnotation.h:141
#define MCAnnotation
static bool isValidXML(const std::string &xml)
char name[1]
Definition: stdsoap2.h:1342
void CAnnotation::setMiriamAnnotation ( const std::string &  miriamAnnotation,
const std::string &  newId,
const std::string &  oldId 
)
void CAnnotation::setNotes ( const std::string &  notes)

Member Data Documentation

std::string CAnnotation::mKey
protected
std::string CAnnotation::mMiriamAnnotation
private

MIRIAM compliant annotation in RDF/XML format

Definition at line 130 of file CAnnotation.h.

Referenced by getMiriamAnnotation(), operator==(), and setMiriamAnnotation().

std::string CAnnotation::mNotes
private

Notes in XHTML format

Definition at line 125 of file CAnnotation.h.

Referenced by getNotes(), operator==(), and setNotes().

UnsupportedAnnotation CAnnotation::mUnsupportedAnnotations
private

The annotations which are not supported by COPASI. Note, the name is enforced to be unique.

Definition at line 141 of file CAnnotation.h.

Referenced by addUnsupportedAnnotation(), getUnsupportedAnnotations(), removeUnsupportedAnnotation(), and replaceUnsupportedAnnotation().

std::string CAnnotation::mXMLId
private

The XMLId used in the about statement

Definition at line 135 of file CAnnotation.h.

Referenced by operator==(), and setMiriamAnnotation().


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