OMNeT++ NEDXML  6.0.3
ASTNode Class Referenceabstract

#include <astnode.h>

Description

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 ASTNodedup () const =0
 
virtual ASTNodedupTree () 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 SourceRegiongetSourceRegion () const
 
virtual void setSourceRegion (const SourceRegion &region)
 
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 ASTNodegetParent () const
 
virtual ASTNodegetFirstChild () const
 
virtual ASTNodegetLastChild () const
 
virtual ASTNodegetNextSibling () const
 
virtual ASTNodegetPrevSibling () const
 
virtual void appendChild (ASTNode *node)
 
virtual void insertChildBefore (ASTNode *where, ASTNode *newnode)
 
virtual ASTNoderemoveChild (ASTNode *node)
 
virtual ASTNodegetFirstChildWithTag (int tagcode) const
 
virtual ASTNodegetNextSiblingWithTag (int tagcode) const
 
virtual ASTNodegetPreviousSiblingWithTag (int tagcode) const
 
virtual int getNumChildren () const
 
virtual int getNumChildrenWithTag (int tagcode) const
 
Utility functions
ASTNodegetFirstChildWithAttribute (int tagcode, const char *attr, const char *attrvalue=nullptr)
 
ASTNodegetParentWithTag (int tagcode)
 
User data
virtual void setUserData (UserData *data)
 
virtual UserDatagetUserData () 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)
 

Constructor & Destructor Documentation

◆ ASTNode() [1/2]

ASTNode ( )

Constructor

◆ ASTNode() [2/2]

ASTNode ( ASTNode parent)

Constructor. Takes parent element.

◆ ~ASTNode()

virtual ~ASTNode ( )
virtual

Destructor. Destroys children too.

Member Function Documentation

◆ stringToBool()

static bool stringToBool ( const char *  s)
staticprotected

◆ boolToString()

static const char* boolToString ( bool  b)
staticprotected

◆ stringToEnum()

static int stringToEnum ( const char *  s,
const char *  vals[],
int  nums[],
int  n 
)
staticprotected

◆ enumToString()

static const char* enumToString ( int  b,
const char *  vals[],
int  nums[],
int  n 
)
staticprotected

◆ validateEnum()

static void validateEnum ( int  b,
const char *  vals[],
int  nums[],
int  n 
)
staticprotected

◆ dup()

virtual ASTNode* dup ( ) const
pure virtual

Creates and returns a duplicate of the element. Child elements are not copied.

◆ dupTree()

virtual ASTNode* dupTree ( ) const
virtual

Recursive version of dup(): duplicates the whole subtree.

◆ getTagName()

virtual const char* getTagName ( ) const
pure virtual

Overridden in subclasses to return the name of the XML element the class represents.

◆ getTagCode()

virtual int getTagCode ( ) const
pure virtual

Overridden in subclasses to return the numeric code (NED_xxx) of the XML element the class represents.

◆ getId()

virtual long getId ( ) const
virtual

Returns a unique id, originally set by the constructor.

◆ setId()

virtual void setId ( long  id)
virtual

The unique id assigned by the constructor can be overwritten here.

◆ getSourceLocation()

virtual FileLine getSourceLocation ( ) const
virtual

Returns the file:line line position where this element originally came from.

◆ setSourceLocation() [1/2]

virtual void setSourceLocation ( FileLine  loc)
virtual

Sets the file:line position indicating where this element originally came from.

◆ setSourceLocation() [2/2]

void setSourceLocation ( const char *  fileName,
int  lineNumber 
)
inline

Utility function based on setSourceLocation(). Needed by the IDE.

References ASTNode::setSourceLocation().

Referenced by ASTNode::setSourceLocation().

◆ getSourceFileName()

virtual const char* getSourceFileName ( ) const
virtual

Utility function based on getSourceLocation(). Needed by the IDE.

◆ getSourceLineNumber()

virtual int getSourceLineNumber ( ) const
virtual

Utility function based on getSourceLocation(). Needed by the IDE.

◆ getSourceFileDirectory()

virtual const char* getSourceFileDirectory ( ) const
virtual

Returns the directory this element was loaded from.

◆ getSourceRegion()

virtual const SourceRegion& getSourceRegion ( ) const
virtual

Returns the source region, containing a line:col region in the source file that corresponds to this element.

◆ setSourceRegion()

virtual void setSourceRegion ( const SourceRegion region)
virtual

Sets source region, containing a line:col region in the source file that corresponds to this element. Called by the (NED/XML) parser.

◆ applyDefaults()

virtual void applyDefaults ( )
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.

◆ getNumAttributes()

virtual int getNumAttributes ( ) const
pure virtual

Pure virtual method, it should be redefined in subclasses to return the number of attributes defined in the DTD.

◆ getAttributeName()

virtual const char* getAttributeName ( int  k) const
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()).

◆ lookupAttribute()

virtual int lookupAttribute ( const char *  attr) const
virtual

Returns the index of the given attribute. It returns -1 if the attribute is not found. Relies on getNumAttributes() and getAttributeName().

◆ getAttribute() [1/2]

virtual const char* getAttribute ( int  k) const
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()).

◆ getAttribute() [2/2]

virtual const char* getAttribute ( const char *  attr) const
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.

◆ setAttribute() [1/2]

virtual void setAttribute ( int  k,
const char *  value 
)
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.

◆ setAttribute() [2/2]

virtual void setAttribute ( const char *  attr,
const char *  value 
)
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.

◆ getAttributeDefault() [1/2]

virtual const char* getAttributeDefault ( int  k) const
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.

◆ getAttributeDefault() [2/2]

virtual const char* getAttributeDefault ( const char *  attr) const
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.

◆ getParent()

virtual ASTNode* getParent ( ) const
virtual

Returns the parent element, or nullptr if this element has no parent.

◆ getFirstChild()

virtual ASTNode* getFirstChild ( ) const
virtual

Returns pointer to the first child element, or nullptr if this element has no children.

◆ getLastChild()

virtual ASTNode* getLastChild ( ) const
virtual

Returns pointer to the last child element, or nullptr if this element has no children.

◆ getNextSibling()

virtual ASTNode* getNextSibling ( ) const
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())
{
   ...
}

◆ getPrevSibling()

virtual ASTNode* getPrevSibling ( ) const
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.

◆ appendChild()

virtual void appendChild ( ASTNode node)
virtual

Appends the given element at the end of the child element list.

The node pointer passed should not be nullptr.

◆ insertChildBefore()

virtual void insertChildBefore ( ASTNode where,
ASTNode newnode 
)
virtual

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.

◆ removeChild()

virtual ASTNode* removeChild ( ASTNode node)
virtual

Removes the given element from the child element list.

The pointer passed should be a child of this element.

◆ getFirstChildWithTag()

virtual ASTNode* getFirstChildWithTag ( int  tagcode) const
virtual

Returns pointer to the first child element with the given tag code, or nullptr if this element has no such children.

◆ getNextSiblingWithTag()

virtual ASTNode* getNextSiblingWithTag ( int  tagcode) const
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))
{
    ...
}

◆ getPreviousSiblingWithTag()

virtual ASTNode* getPreviousSiblingWithTag ( int  tagcode) const
virtual

Returns pointer to the previous sibling of this element with the given tag code. Returns nullptr if there's no such element.

◆ getNumChildren()

virtual int getNumChildren ( ) const
virtual

Returns the number of child elements.

◆ getNumChildrenWithTag()

virtual int getNumChildrenWithTag ( int  tagcode) const
virtual

Returns the number of child elements with the given tag code.

◆ getFirstChildWithAttribute()

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.

◆ getParentWithTag()

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.

◆ getNumCreated()

static long getNumCreated ( )
inlinestatic

Returns ASTNodes constructed so far (this number can only increase).

◆ getNumExisting()

static long getNumExisting ( )
inlinestatic

Returns the number of ASTNodes currently in existence (created minus deleted). Useful for detecting memory leaks.

◆ setUserData()

virtual void setUserData ( UserData data)
virtual

Replaces user data object with the given one.

◆ getUserData()

virtual UserData* getUserData ( ) const
virtual

Return pointer to the user data object, or nullptr if setUserData() has not been called yet.


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