libNuML 1.1.1
Library for reading / writing NuML documents
NMBase.h
Go to the documentation of this file.
1/*
2* ****************************************************************************
3* This file is part of libNUML. Please visit http://code.google.com/p/numl/for more
4* information about NUML, and the latest version of libNUML.
5* Copyright (c) 2013 The University of Manchester.
6*
7* This library is free software; you can redistribute it and/or modify it
8* under the terms of the GNU Lesser General Public License as published
9* by the Free Software Foundation. A copy of the license agreement is
10* provided in the file named "LICENSE.txt" included with this software
11* distribution and also available online as http://www.gnu.org/licenses/lgpl.html
12*
13* Contributors:
14* Joseph O. Dada, The University of Manchester - initial API and implementation
15* ****************************************************************************
16**/
17
24#ifndef NMBase_h
25#define NMBase_h
26
27
28#include <numl/common/extern.h>
29#include <numl/common/numlfwd.h>
30#include <sbml/util/List.h>
31#include <numl/NUMLTypeCodes.h>
32#include <numl/NUMLNamespaces.h>
33#include <sbml/SyntaxChecker.h> //change from numl
34#include <numl/NUMLVisitor.h>
35
36
37#include <string>
38#include <stdexcept>
39#include <algorithm>
40
41#include <numl/NUMLErrorLog.h>
42
43
44#include <sbml/xml/XMLAttributes.h>
45#include <sbml/xml/XMLOutputStream.h>
46#include <sbml/xml/XMLNode.h>
47#include <sbml/xml/XMLInputStream.h>
48#include <sbml/xml/XMLNamespaces.h>
49#include <sbml/xml/XMLToken.h>
50
51
52
53#ifdef __cplusplus
54LIBNUML_CPP_NAMESPACE_BEGIN
55
56class NUMLErrorLog;
57//class NUMLVisitor;
58class NUMLDocument;
59
60class NUMLConstructorException : public std::invalid_argument
61{
62public:
63
64 /* constructor */
66
67};
68
69
71{
72public:
73
77 virtual ~NMBase ();
78
79
83 NMBase& operator=(const NMBase& orig);
84
85
93 virtual bool accept (NUMLVisitor& v) const = 0;
94
95
101 virtual NMBase* clone () const = 0;
102
103
127 const std::string& getMetaId () const;
128
129
153 std::string& getMetaId ();
154
155
156 /*
157 * NOTE: THIS IS FOR BACKWARD COMPATABILITY REASONS
158 *
159 * Returns the value of the "id" attribute of this object.
160 *
161 * @return the id of this NUML object.
162 */
163 virtual const std::string& getId () const;
164
165
166 /*
167 * NOTE: THIS IS FOR BACKWARD COMPATABILITY REASONS
168 *
169 * Returns the value of the "name" attribute of this object.
170 *
171 * @return the name of this NUML object.
172 */
173 virtual const std::string& getName () const;
203//TODO std::string getAnnotationString ();
204
205
211 virtual LIBSBML_CPP_NAMESPACE_QUALIFIER XMLNamespaces* getNamespaces() const ;
212
213
231 const NUMLDocument* getNUMLDocument () const;
232
233
251 NUMLDocument* getNUMLDocument ();
252
262 NMBase* getParentNUMLObject();
263
280 NMBase* getAncestorOfType(NUMLTypeCode_t type);
281
282
291 unsigned int getLine () const;
292
293
302 unsigned int getColumn () const;
303
304
330 bool isSetMetaId () const;
331
332
333
334 /*
335 * NOTE: THIS IS FOR BACKWARD COMPATABILITY REASONS
336 * Predicate returning @c true or @c false depending on whether this
337 * object's "name" attribute has been set.
338 *
339 * @return @c true if the "name" attribute of this NUML object has been
340 * set, @c false otherwise.
341 */
342 bool isSetName () const;
343
372 int setMetaId (const std::string& metaid);
373
374 /*
375 * NOTE: THIS IS FOR BACKWARD COMPATABILITY REASONS
376 *
377 * Sets the value of the "id" attribute of this NUML object to a copy
378 * of @p id.
379 *
380 * The string @p sid is copied. Note that NUML has strict requirements
381 * for the syntax of identifiers.
382 *
383 * @param sid the string to use as the identifier of this object
384 *
385 * @return integer value indicating success/failure of the
386 * function. The possible values returned by this function are:
387 * @li @link OperationReturnValues_t#LIBNUML_OPERATION_SUCCESS LIBNUML_OPERATION_SUCCESS @endlink
388 * @li @link OperationReturnValues_t#LIBNUML_INVALID_ATTRIBUTE_VALUE LIBNUML_INVALID_ATTRIBUTE_VALUE @endlink
389 */
390 virtual int setId (const std::string& sid);
391
392
393
394 /*
395 * NOTE: THIS IS FOR BACKWARD COMPATABILITY REASONS
396 * Sets the value of the "name" attribute of this NUML object.
397 *
398 * The string in @p name is copied.
399 *
400 * @param name the new name for the object
401 *
402 * @return integer value indicating success/failure of the
403 * function. @if clike The value is drawn from the
404 * enumeration #OperationReturnValues_t. @endif The possible values
405 * returned by this function are:
406 * @li LIBNUML_OPERATION_SUCCESS
407 * @li LIBNUML_INVALID_ATTRIBUTE_VALUE
408 */
409 // TODO int setName (const std::string& name);
410
416 virtual void setNUMLDocument (NUMLDocument* d);
417
418
424 virtual void setParentNUMLObject (NMBase* sb);
425
437 int setNamespaces(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLNamespaces* xmlns);
438
439
465 int unsetMetaId ();
466
467
468#if 0
480 int unsetId ();
481
482
494 int unsetName ();
495#endif
496
504 unsigned int getLevel () const;
505
506
514 unsigned int getVersion () const;
515
533 // virtual int getTypeCode () const;
534
549 virtual NUMLTypeCode_t getTypeCode () const;
550
551
566 bool hasValidLevelVersionNamespaceCombination();
567
568
576 virtual const std::string& getElementName () const = 0;
577
578
586 char* toNUML ();
587
588
592 void read (LIBSBML_CPP_NAMESPACE_QUALIFIER XMLInputStream& stream);
593
594
598 void write (LIBSBML_CPP_NAMESPACE_QUALIFIER XMLOutputStream& stream) const;
599
600
611 virtual void writeElements (LIBSBML_CPP_NAMESPACE_QUALIFIER XMLOutputStream& stream) const;
612
613
614 /* function returns true if component has all the required
615 * attributes
616 * needs to be overloaded for each component
617 */
618 virtual bool hasRequiredAttributes() const ;
619
620
621 /* function returns true if component has all the required
622 * elements
623 * needs to be overloaded for each component
624 */
625 virtual bool hasRequiredElements() const ;
626
627
628 /* sets the NUMLnamespaces - internal use only*/
629 void setNUMLNamespaces(NUMLNamespaces * numlns);
630
631
632 /* gets the NUMLnamespaces - internal use only*/
633 NUMLNamespaces * getNUMLNamespaces() const;
634
635 void syncAnnotation();
636 bool isSetNotes() const;
637 bool isSetAnnotation() const;
638 virtual int setAnnotation(const LIBSBML_CPP_NAMESPACE_QUALIFIER XMLNode* annotation);
639 virtual int setAnnotation(const std::string& annotation);
640 virtual int appendAnnotation(const LIBSBML_CPP_NAMESPACE_QUALIFIER XMLNode* annotation);
641 virtual int appendAnnotation(const std::string& annotation);
642 int removeTopLevelAnnotationElement(const std::string elementName,
643 const std::string elementURI = "");
644 int replaceTopLevelAnnotationElement(const LIBSBML_CPP_NAMESPACE_QUALIFIER XMLNode* annotation);
645 int replaceTopLevelAnnotationElement(const std::string& annotation);
646 int setNotes(const LIBSBML_CPP_NAMESPACE_QUALIFIER XMLNode* notes);
647 int setNotes(const std::string& notes, bool addXHTMLMarkup = false);
648 int appendNotes(const LIBSBML_CPP_NAMESPACE_QUALIFIER XMLNode* notes);
649 int appendNotes(const std::string& notes);
650 int unsetNotes();
651 int unsetAnnotation();
652
653 LIBSBML_CPP_NAMESPACE_QUALIFIER XMLNode* getNotes() const;
654 std::string getNotesString() const;
655 LIBSBML_CPP_NAMESPACE_QUALIFIER XMLNode* getAnnotation() const;
656 std::string getAnnotationString() const;
657
658
659
660protected:
661
662
669 virtual void writeXMLNS(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLOutputStream& stream) const;
670
671
687 NMBase (const std::string& id = "", const std::string& name = "");
688
689
694 NMBase (unsigned int level, unsigned int version);
695
696
701 NMBase (NUMLNamespaces* numlns);
702
703
707 NMBase(const NMBase& orig);
708
709
718 virtual NMBase* createObject (LIBSBML_CPP_NAMESPACE_QUALIFIER XMLInputStream& stream);
719
720
727 virtual bool readOtherXML (LIBSBML_CPP_NAMESPACE_QUALIFIER XMLInputStream& stream);
728
729
740 virtual int getElementPosition () const;
741
742
747 NUMLErrorLog* getErrorLog ();
748
749
768 void logError ( unsigned int id
769 , const unsigned int level = 2
770 , const unsigned int version = 3
771 , const std::string& details = "" );
772
773
777 void logUnknownAttribute( std::string attribute,
778 const unsigned int level,
779 const unsigned int version,
780 const std::string element );
781
782
786 void logUnknownElement( const std::string element,
787 const unsigned int level,
788 const unsigned int version );
789
790
794 void logEmptyString( std::string attribute,
795 const unsigned int level,
796 const unsigned int version,
797 std::string element);
798
799
805 virtual void readAttributes (const LIBSBML_CPP_NAMESPACE_QUALIFIER XMLAttributes& attributes);
806
807
818 virtual void writeAttributes (LIBSBML_CPP_NAMESPACE_QUALIFIER XMLOutputStream& stream) const;
819
820
825 void checkOrderAndLogError (NMBase* object, int expected);
826
827
833 void checkNUMLListPopulated(NMBase* object);
834
835
836#if 0
861 void checkUnitSyntax(unsigned int flag = 0);
862#endif
863
868 void checkDefaultNamespace(const LIBSBML_CPP_NAMESPACE_QUALIFIER XMLNamespaces* xmlns, const std::string& elementName);
869
870
876 void checkXHTML(const LIBSBML_CPP_NAMESPACE_QUALIFIER XMLNode *);
877
882 void checkAnnotation();
883
884 std::string mMetaId;
885 std::string mId;
886 std::string mName;
887
889
890 LIBSBML_CPP_NAMESPACE_QUALIFIER XMLNode* mNotes;
891 LIBSBML_CPP_NAMESPACE_QUALIFIER XMLNode* mAnnotation;
892
893 //int mObjectLevel;
894 //int mObjectVersion;
895
897
898
899 unsigned int mLine;
900 unsigned int mColumn;
901
902 int mDept;
903
904 /* store the parent NUML object */
906
907 /* flag that allows object to know its been deleted
908 * for OS where the memory is still readable after a delete
909 */
911
912 std::string mEmptyString;
913
914
915
916private:
917
922 void setNMBaseFields (const LIBSBML_CPP_NAMESPACE_QUALIFIER XMLToken& element);
923
924
928 bool readAnnotation (LIBSBML_CPP_NAMESPACE_QUALIFIER XMLInputStream& stream);
929
930
934 bool readNotes (LIBSBML_CPP_NAMESPACE_QUALIFIER XMLInputStream& stream);
935
936 bool getHasBeenDeleted();
937
938
939};
940
941LIBNUML_CPP_NAMESPACE_END
942
943#endif /* __cplusplus */
944
945
946
947#ifndef SWIG
948
949LIBNUML_CPP_NAMESPACE_BEGIN
951
952/*-----------------------------------------------------------------------------
953 * See the .cpp file for the documentation of the following functions.
954 *---------------------------------------------------------------------------*/
955
956
958const char *
960
961
963const NUMLDocument_t *
965
966
968const NMBase_t *
970
971
973const NMBase_t *
974NMBase_getAncestorOfType (NMBase_t *sb, NUMLTypeCode_t type);
975
976
978unsigned int
979NMBase_getLine (const NMBase_t *sb);
980
981
983unsigned int
984NMBase_getColumn (const NMBase_t *sb);
985
986
988LIBSBML_CPP_NAMESPACE_QUALIFIER XMLNode_t *
989NMBase_getNotes (NMBase_t *sb);
990
991
993char*
994NMBase_getNotesString (NMBase_t *sb);
995
996
998LIBSBML_CPP_NAMESPACE_QUALIFIER XMLNode_t *
999NMBase_getAnnotation (NMBase_t *sb);
1000
1001
1003char*
1004NMBase_getAnnotationString (NMBase_t *sb);
1005
1006
1008int
1009NMBase_isSetMetaId (const NMBase_t *sb);
1010
1011
1013int
1014NMBase_isSetNotes (const NMBase_t *sb);
1015
1016
1018int
1019NMBase_isSetAnnotation (const NMBase_t *sb);
1020
1021
1023int
1024NMBase_setMetaId (NMBase_t *sb, const char *metaid);
1025
1026
1028int
1029NMBase_setNamespaces (NMBase_t *sb, LIBSBML_CPP_NAMESPACE_QUALIFIER XMLNamespaces_t *xmlns);
1030
1031
1033int
1034NMBase_setNotes (NMBase_t *sb, LIBSBML_CPP_NAMESPACE_QUALIFIER XMLNode_t *notes);
1035
1036
1038int
1039NMBase_setNotesString (NMBase_t *sb, char *notes);
1040
1041
1043int
1044NMBase_appendNotes (NMBase_t *sb, LIBSBML_CPP_NAMESPACE_QUALIFIER XMLNode_t *notes);
1045
1046
1048int
1049NMBase_appendNotesString (NMBase_t *sb, char *notes);
1050
1051
1053int
1054NMBase_setAnnotation (NMBase_t *sb, LIBSBML_CPP_NAMESPACE_QUALIFIER XMLNode_t *annotation);
1055
1056
1058int
1059NMBase_setAnnotationString (NMBase_t *sb, char *annotation);
1060
1061
1063int
1064NMBase_appendAnnotation (NMBase_t *sb, LIBSBML_CPP_NAMESPACE_QUALIFIER XMLNode_t *annotation);
1065
1066
1068int
1069NMBase_appendAnnotationString (NMBase_t *sb, char *annotation);
1070
1071
1073int
1075
1077unsigned int
1078NMBase_getLevel (const NMBase_t *sb);
1079
1080
1082unsigned int
1083NMBase_getVersion (const NMBase_t *sb);
1084
1085
1088NMBase_getTypeCode (const NMBase_t *sb);
1089
1090
1092const char *
1094
1095
1097int
1099
1100
1102LIBNUML_CPP_NAMESPACE_END
1103
1104#endif /* !SWIG */
1105#endif /* NMBase_h */
LIBNUML_EXTERN int NMBase_setMetaId(NMBase_t *sb, const char *metaid)
Sets the value of the "metaid" attribute of the given object.
Definition: NMBase.cpp:2460
LIBNUML_EXTERN const char * NMBase_getElementName(const NMBase_t *sb)
Returns the XML element name of the given structure.
Definition: NMBase.cpp:2543
LIBNUML_EXTERN const char * NMBase_getMetaId(NMBase_t *sb)
Returns the value of the "metaid" attribute of the given NMBase_t structure.
Definition: NMBase.cpp:2311
LIBNUML_EXTERN const NMBase_t * NMBase_getParentNUMLObject(NMBase_t *sb)
Returns the parent NMBase_t structure of the given NMBase_t structure.
Definition: NMBase.cpp:2375
LIBNUML_EXTERN NUMLTypeCode_t NMBase_getTypeCode(const NMBase_t *sb)
Returns the libNUML type code for the given structure.
Definition: NMBase.cpp:2525
LIBNUML_EXTERN int NMBase_setNamespaces(NMBase_t *sb, LIBSBML_CPP_NAMESPACE_QUALIFIER XMLNamespaces_t *xmlns)
Sets the namespaces relevant of this NUML object.
Definition: NMBase.cpp:2482
LIBNUML_EXTERN int NMBase_hasValidLevelVersionNamespaceCombination(NMBase_t *sb)
Predicate returning nonzero true or false depending on whether the object's level/version and namespa...
Definition: NMBase.cpp:2603
LIBNUML_EXTERN unsigned int NMBase_getColumn(const NMBase_t *sb)
Returns the column number on which the given object first appears in the XML representation of the NU...
Definition: NMBase.cpp:2579
LIBNUML_EXTERN unsigned int NMBase_getLevel(const NMBase_t *sb)
Returns the NUML Level of the overall NUML document.
Definition: NMBase.cpp:2391
LIBNUML_EXTERN int NMBase_isSetMetaId(const NMBase_t *sb)
Predicate returning nonzero true or false depending on whether the given structure's "metaid" attribu...
Definition: NMBase.cpp:2424
LIBNUML_EXTERN const NUMLDocument_t * NMBase_getNUMLDocument(NMBase_t *sb)
‍**
Definition: NMBase.cpp:2359
LIBNUML_EXTERN unsigned int NMBase_getVersion(const NMBase_t *sb)
Returns the Version within the NUML Level of the overall NUML document.
Definition: NMBase.cpp:2408
LIBNUML_EXTERN unsigned int NMBase_getLine(const NMBase_t *sb)
Returns the line number on which the given object first appears in the XML representation of the NUML...
Definition: NMBase.cpp:2561
LIBNUML_EXTERN int NMBase_unsetMetaId(NMBase_t *sb)
Unsets the "metaid" attribute of the given object.
Definition: NMBase.cpp:2501
NUMLTypeCode_t
An enumeration of NUML types to help identify NUML objects at runtime.
Definition: NUMLTypeCodes.h:34
This is the base class for all numl objects.
Definition: NMBase.h:71
virtual int appendAnnotation(const LIBSBML_CPP_NAMESPACE_QUALIFIER XMLNode *annotation)
unsigned int mLine
Definition: NMBase.h:899
int appendNotes(const LIBSBML_CPP_NAMESPACE_QUALIFIER XMLNode *notes)
std::string mId
Definition: NMBase.h:885
bool mHasBeenDeleted
Definition: NMBase.h:910
virtual const std::string & getElementName() const =0
Returns the XML element name of this object.
int mDept
Definition: NMBase.h:902
virtual bool accept(NUMLVisitor &v) const =0
Accepts the given NUMLVisitor for this instance of NMBase.
virtual NMBase * clone() const =0
Creates and returns a deep copy of this NMBase object.
LIBSBML_CPP_NAMESPACE_QUALIFIER XMLNode * mNotes
Definition: NMBase.h:890
virtual int setAnnotation(const LIBSBML_CPP_NAMESPACE_QUALIFIER XMLNode *annotation)
NUMLNamespaces * mNUMLNamespaces
Definition: NMBase.h:896
NMBase * mParentNUMLObject
Definition: NMBase.h:905
int replaceTopLevelAnnotationElement(const LIBSBML_CPP_NAMESPACE_QUALIFIER XMLNode *annotation)
std::string mMetaId
Definition: NMBase.h:884
std::string mEmptyString
Definition: NMBase.h:912
NUMLDocument * mNUML
Definition: NMBase.h:888
LIBSBML_CPP_NAMESPACE_QUALIFIER XMLNode * mAnnotation
Definition: NMBase.h:891
unsigned int mColumn
Definition: NMBase.h:900
std::string mName
Definition: NMBase.h:886
int setNotes(const LIBSBML_CPP_NAMESPACE_QUALIFIER XMLNode *notes)
Definition: NMBase.h:61
NUMLConstructorException()
elements permitted on the body element of xhtml
Definition: NMBase.cpp:60
This represents the numl document that contains all information.
Definition: NUMLDocument.h:107
the error log containing all errors / warnings encountered
Definition: NUMLErrorLog.h:39
namespace class
Definition: NUMLNamespaces.h:47
Implementation of the Visitor design pattern, for operations on NUML objects.
Definition: NUMLVisitor.h:73
#define BEGIN_C_DECLS
Definition: extern.h:112
#define LIBNUML_EXTERN
Begin svn Header.
Definition: extern.h:104
#define END_C_DECLS
Definition: extern.h:113
CLASS_OR_STRUCT XMLNode XMLNode_t
Definition: numlfwd.h:235
CLASS_OR_STRUCT NUMLDocument NUMLDocument_t
Definition: numlfwd.h:88
CLASS_OR_STRUCT NMBase NMBase_t
Definition: numlfwd.h:82
CLASS_OR_STRUCT XMLNamespaces XMLNamespaces_t
Definition: numlfwd.h:247