Base class for objects in a NED object tree, the XML-based in-memory representation for NED files. An instance of an ASTNode subclass represent an XML element. ASTNode provides a DOM-like, generic access to the tree; subclasses additionally provide a typed interface.
Public Member Functions | |
Constructor, destructor | |
ASTNode () | |
ASTNode (ASTNode *parent) | |
virtual | ~ASTNode () |
virtual ASTNode * | dup () const =0 |
virtual ASTNode * | dupTree () const |
Common properties | |
virtual const char * | getTagName () const =0 |
virtual int | getTagCode () const =0 |
virtual long | getId () const |
virtual void | setId (long id) |
virtual FileLine | getSourceLocation () const |
virtual void | setSourceLocation (FileLine loc) |
void | setSourceLocation (const char *fileName, int lineNumber) |
virtual const char * | getSourceFileName () const |
virtual int | getSourceLineNumber () const |
virtual const char * | getSourceFileDirectory () const |
virtual const SourceRegion & | getSourceRegion () const |
virtual void | setSourceRegion (const SourceRegion ®ion) |
Generic access to attributes (Methods have to be redefined in subclasses!) | |
virtual void | applyDefaults () |
virtual int | getNumAttributes () const =0 |
virtual const char * | getAttributeName (int k) const =0 |
virtual int | lookupAttribute (const char *attr) const |
virtual const char * | getAttribute (int k) const =0 |
virtual const char * | getAttribute (const char *attr) const |
virtual void | setAttribute (int k, const char *value)=0 |
virtual void | setAttribute (const char *attr, const char *value) |
virtual const char * | getAttributeDefault (int k) const =0 |
virtual const char * | getAttributeDefault (const char *attr) const |
Generic access to children and siblings | |
virtual ASTNode * | getParent () const |
virtual ASTNode * | getFirstChild () const |
virtual ASTNode * | getLastChild () const |
virtual ASTNode * | getNextSibling () const |
virtual ASTNode * | getPrevSibling () const |
virtual void | appendChild (ASTNode *node) |
virtual void | insertChildBefore (ASTNode *where, ASTNode *newnode) |
virtual ASTNode * | removeChild (ASTNode *node) |
virtual ASTNode * | getFirstChildWithTag (int tagcode) const |
virtual ASTNode * | getNextSiblingWithTag (int tagcode) const |
virtual ASTNode * | getPreviousSiblingWithTag (int tagcode) const |
virtual int | getNumChildren () const |
virtual int | getNumChildrenWithTag (int tagcode) const |
Utility functions | |
ASTNode * | getFirstChildWithAttribute (int tagcode, const char *attr, const char *attrvalue=nullptr) |
ASTNode * | getParentWithTag (int tagcode) |
User data | |
virtual void | setUserData (UserData *data) |
virtual UserData * | getUserData () const |
Static Public Member Functions | |
Counters | |
static long | getNumCreated () |
static long | getNumExisting () |
Static Protected Member Functions | |
static bool | stringToBool (const char *s) |
static const char * | boolToString (bool b) |
static int | stringToEnum (const char *s, const char *vals[], int nums[], int n) |
static const char * | enumToString (int b, const char *vals[], int nums[], int n) |
static void | validateEnum (int b, const char *vals[], int nums[], int n) |
ASTNode | ( | ) |
Constructor
|
virtual |
Destructor. Destroys children too.
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
pure virtual |
Creates and returns a duplicate of the element. Child elements are not copied.
|
virtual |
Recursive version of dup(): duplicates the whole subtree.
|
pure virtual |
Overridden in subclasses to return the name of the XML element the class represents.
|
pure virtual |
Overridden in subclasses to return the numeric code (NED_xxx) of the XML element the class represents.
|
virtual |
Returns a unique id, originally set by the constructor.
|
virtual |
The unique id assigned by the constructor can be overwritten here.
|
virtual |
Returns the file:line line position where this element originally came from.
|
virtual |
Sets the file:line position indicating where this element originally came from.
|
inline |
Utility function based on setSourceLocation(). Needed by the IDE.
References ASTNode::setSourceLocation().
Referenced by ASTNode::setSourceLocation().
|
virtual |
Utility function based on getSourceLocation(). Needed by the IDE.
|
virtual |
Utility function based on getSourceLocation(). Needed by the IDE.
|
virtual |
Returns the directory this element was loaded from.
|
virtual |
Returns the source region, containing a line:col region in the source file that corresponds to this element.
|
virtual |
Sets source region, containing a line:col region in the source file that corresponds to this element. Called by the (NED/XML) parser.
|
virtual |
Sets every attribute to its default value (as returned by getAttributeDefault()). Attributes without a default value are not affected.
This method is called from the constructors of derived classes.
|
pure virtual |
Pure virtual method, it should be redefined in subclasses to return the number of attributes defined in the DTD.
|
pure virtual |
Pure virtual method, it should be redefined in subclasses to return the name of the kth attribute as defined in the DTD.
It should return nullptr if k is out of range (i.e. negative or greater than getNumAttributes()).
|
virtual |
Returns the index of the given attribute. It returns -1 if the attribute is not found. Relies on getNumAttributes() and getAttributeName().
|
pure virtual |
Pure virtual method, it should be redefined in subclasses to return the value of the kth attribute (i.e. the attribute with the name getAttributeName(k)).
It should return nullptr if k is out of range (i.e. negative or greater than getNumAttributes()).
|
virtual |
Returns the value of the attribute with the given name. Relies on lookupAttribute() and getAttribute().
It returns nullptr if the given attribute is not found.
|
pure virtual |
Pure virtual method, it should be redefined in subclasses to set the value of the kth attribute (i.e. the attribute with the name getAttributeName(k)).
If k is out of range (i.e. negative or greater than getNumAttributes()), the call should be ignored.
|
virtual |
Sets the value of the attribute with the given name. Relies on lookupAttribute() and setAttribute().
If the given attribute is not found, the call has no effect.
|
pure virtual |
Pure virtual method, it should be redefined in subclasses to return the default value of the kth attribute, as defined in the DTD.
It should return nullptr if k is out of range (i.e. negative or greater than getNumAttributes()), or if the attribute is #REQUIRED; and return "" if the attribute is #IMPLIED.
|
virtual |
Returns the default value of the given attribute, as defined in the DTD. Relies on lookupAttribute() and getAttributeDefault().
It returns nullptr if the given attribute is not found.
|
virtual |
Returns the parent element, or nullptr if this element has no parent.
|
virtual |
Returns pointer to the first child element, or nullptr if this element has no children.
|
virtual |
Returns pointer to the last child element, or nullptr if this element has no children.
|
virtual |
Returns pointer to the next sibling of this element (i.e. the next child in the parent element). Returns nullptr if there're no subsequent elements.
getFirstChild() and getNextSibling() can be used to loop through the child list:
for (ASTNode *child=node->getFirstChild(); child; child = child->getNextSibling()) { ... }
|
virtual |
Returns pointer to the previous sibling of this element (i.e. the previous child in the parent element). Returns nullptr if there're no elements before this one.
|
virtual |
Appends the given element at the end of the child element list.
The node pointer passed should not be nullptr.
Inserts the given element just before the specified child element in the child element list, or at the end of the child list if nullptr is specified as the insert position.
The where element must be a child of this element, or nullptr. The node pointer passed should not be nullptr.
Removes the given element from the child element list.
The pointer passed should be a child of this element.
|
virtual |
Returns pointer to the first child element with the given tag code, or nullptr if this element has no such children.
|
virtual |
Returns pointer to the next sibling of this element with the given tag code. Returns nullptr if there's no such element.
getFirstChildWithTag() and getNextSiblingWithTag() are a convenient way to loop through elements with a certain tag code in the child list:
for (ASTNode *child=node->getFirstChildWithTag(tagcode); child; child = child->getNextSiblingWithTag(tagcode)) { ... }
|
virtual |
Returns pointer to the previous sibling of this element with the given tag code. Returns nullptr if there's no such element.
|
virtual |
Returns the number of child elements.
|
virtual |
Returns the number of child elements with the given tag code.
ASTNode* getFirstChildWithAttribute | ( | int | tagcode, |
const char * | attr, | ||
const char * | attrvalue = nullptr |
||
) |
Returns first child element with the given tagcode and the given attribute (optionally) having the given value. Returns nullptr if not found.
ASTNode* getParentWithTag | ( | int | tagcode | ) |
Climb up in the element tree until it finds an element with the given tagcode. Returns "this" if its tagcode already matches. Returns nullptr if not found.
|
inlinestatic |
Returns ASTNodes constructed so far (this number can only increase).
|
inlinestatic |
Returns the number of ASTNodes currently in existence (created minus deleted). Useful for detecting memory leaks.
|
virtual |
Replaces user data object with the given one.
|
virtual |
Return pointer to the user data object, or nullptr if setUserData() has not been called yet.