- Main Page
- Modules
- Classes
- Files
- Directories

- Class List
- Class Hierarchy
- Class Members

# NEDElement Class Reference
[Data classes]

`#include <nedelement.h>`

Inheritance diagram for NEDElement:

List of all members.

## Detailed Description

Base class for objects in a NED object tree, the XML-based in-memory representation for NED files.

An instance of a NEDElement subclass represent an XML element. NEDElement provides a DOM-like, generic access to the tree; subclasses additionally provide a typed interface.

## Public Member Functions
Constructor, destructor
| NEDElement ()
| NEDElement (NEDElement *parent)
virtual | ~NEDElement ()
Common properties
virtual const char * | getTagName () const =0
virtual int | getTagCode () const =0
virtual long | getId () const
virtual void | setId (long id)
virtual const char * | getSourceLocation () const
virtual void | setSourceLocation (const char *loc)
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 NEDElement * | getParent () const
virtual NEDElement * | getFirstChild () const
virtual NEDElement * | getLastChild () const
virtual NEDElement * | getNextSibling () const
virtual NEDElement * | getPrevSibling () const
virtual void | appendChild (NEDElement *node)
virtual void | insertChildBefore (NEDElement *where, NEDElement *newnode)
virtual NEDElement * | removeChild (NEDElement *node)
virtual NEDElement * | getFirstChildWithTag (int tagcode) const
virtual NEDElement * | getNextSiblingWithTag (int tagcode) const
virtual int | getNumChildren () const
virtual int | getNumChildrenWithTag (int tagcode) const
Utility functions
NEDElement * | getFirstChildWithAttribute (int tagcode, const char *attr, const char *attrvalue=NULL)
NEDElement * | getParentWithTag (int tagcode)
User data
virtual void | setUserData (NEDElementUserData *data)
virtual NEDElementUserData * | getUserData () const
## 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)

## Constructor & Destructor Documentation

NEDElement::NEDElement | ( |  | ) |

| Constructor.

NEDElement::NEDElement | ( | NEDElement * | parent | ) |

| Constructor. Takes parent element.

virtual NEDElement::~NEDElement | ( |  | ) | `[virtual]`

| Destructor. Destroys children too.

## Member Function Documentation

virtual void NEDElement::appendChild | ( | NEDElement * | node | ) | `[virtual]`

| Appends the given element at the end of the child element list. The node pointer passed should not be NULL.

virtual void NEDElement::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.

static const char* NEDElement::boolToString | ( | bool | b | ) | `[static, protected]`

static const char* NEDElement::enumToString | ( | int | b,
|  | const char * | vals[],
|  | int | nums[],
|  | int | n
| ) | `[static, protected]`

virtual const char* NEDElement::getAttribute | ( | const char * | attr | ) | const`[virtual]`

| Returns the value of the attribute with the given name. Relies on lookupAttribute() and getAttribute(). It returns NULL if the given attribute is not found.

virtual const char* NEDElement::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 NULL if k is out of range (i.e. negative or greater than getNumAttributes()). Implemented in NedFilesNode, NedFileNode, ImportNode, ImportedFileNode, ChannelNode, ChannelAttrNode, NetworkNode, SimpleModuleNode, CompoundModuleNode, ParamsNode, ParamNode, GatesNode, GateNode, MachinesNode, MachineNode, SubmodulesNode, SubmoduleNode, SubstparamsNode, SubstparamNode, GatesizesNode, GatesizeNode, SubstmachinesNode, SubstmachineNode, ConnectionsNode, ConnectionNode, ConnAttrNode, ForLoopNode, LoopVarNode, DisplayStringNode, ExpressionNode, OperatorNode, FunctionNode, ParamRefNode, IdentNode, ConstNode, CplusplusNode, StructDeclNode, ClassDeclNode, MessageDeclNode, EnumDeclNode, EnumNode, EnumFieldsNode, EnumFieldNode, MessageNode, ClassNode, StructNode, FieldsNode, FieldNode, PropertiesNode, PropertyNode, and UnknownNode.

virtual const char* NEDElement::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 NULL if the given attribute is not found.

virtual const char* NEDElement::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 NULL if k is out of range (i.e. negative or greater than getNumAttributes()). Implemented in NedFilesNode, NedFileNode, ImportNode, ImportedFileNode, ChannelNode, ChannelAttrNode, NetworkNode, SimpleModuleNode, CompoundModuleNode, ParamsNode, ParamNode, GatesNode, GateNode, MachinesNode, MachineNode, SubmodulesNode, SubmoduleNode, SubstparamsNode, SubstparamNode, GatesizesNode, GatesizeNode, SubstmachinesNode, SubstmachineNode, ConnectionsNode, ConnectionNode, ConnAttrNode, ForLoopNode, LoopVarNode, DisplayStringNode, ExpressionNode, OperatorNode, FunctionNode, ParamRefNode, IdentNode, ConstNode, CplusplusNode, StructDeclNode, ClassDeclNode, MessageDeclNode, EnumDeclNode, EnumNode, EnumFieldsNode, EnumFieldNode, MessageNode, ClassNode, StructNode, FieldsNode, FieldNode, PropertiesNode, PropertyNode, and UnknownNode.

virtual const char* NEDElement::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 NULL if k is out of range (i.e. negative or greater than getNumAttributes()). Implemented in NedFilesNode, NedFileNode, ImportNode, ImportedFileNode, ChannelNode, ChannelAttrNode, NetworkNode, SimpleModuleNode, CompoundModuleNode, ParamsNode, ParamNode, GatesNode, GateNode, MachinesNode, MachineNode, SubmodulesNode, SubmoduleNode, SubstparamsNode, SubstparamNode, GatesizesNode, GatesizeNode, SubstmachinesNode, SubstmachineNode, ConnectionsNode, ConnectionNode, ConnAttrNode, ForLoopNode, LoopVarNode, DisplayStringNode, ExpressionNode, OperatorNode, FunctionNode, ParamRefNode, IdentNode, ConstNode, CplusplusNode, StructDeclNode, ClassDeclNode, MessageDeclNode, EnumDeclNode, EnumNode, EnumFieldsNode, EnumFieldNode, MessageNode, ClassNode, StructNode, FieldsNode, FieldNode, PropertiesNode, PropertyNode, and UnknownNode.

virtual NEDElement* NEDElement::getFirstChild | ( |  | ) | const`[virtual]`

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

NEDElement* NEDElement::getFirstChildWithAttribute | ( | int | tagcode,
|  | const char * | attr,
|  | const char * | attrvalue = `NULL`
| ) |

| Returns find first child element with the give tagcode and the given attribute (optionally) having the given value. Returns NULL if not found.

virtual NEDElement* NEDElement::getFirstChildWithTag | ( | int | tagcode | ) | const`[virtual]`

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

virtual long NEDElement::getId | ( |  | ) | const`[virtual]`

| Returns a unique id, originally set by the contructor.

virtual NEDElement* NEDElement::getLastChild | ( |  | ) | const`[virtual]`

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

virtual NEDElement* NEDElement::getNextSibling | ( |  | ) | const`[virtual]`

| Returns pointer to the next sibling of this element (i.e. the next child in the parent element). Returns NULL if there're no subsequent elements. getFirstChild() and getNextSibling() can be used to loop through the child list:
     for (NEDElement *child=node->getFirstChild(); child; child = child->getNextSibling())
     {
        ...
     }

virtual NEDElement* NEDElement::getNextSiblingWithTag | ( | int | tagcode | ) | const`[virtual]`

| Returns pointer to the next sibling of this element with the given tag code. Return NULL if there're no such subsequent elements. getFirstChildWithTag() and getNextSiblingWithTag() are a convient way to loop through elements with a certain tag code in the child list:
     for (NEDElement *child=node->getFirstChildWithTag(tagcode); child; child = child->getNextSiblingWithTag(tagcode))
     {
         ...
     }

virtual int NEDElement::getNumAttributes | ( |  | ) | const`[pure virtual]`

| Pure virtual method, it should be redefined in subclasses to return the number of attributes defined in the DTD. Implemented in NedFilesNode, NedFileNode, ImportNode, ImportedFileNode, ChannelNode, ChannelAttrNode, NetworkNode, SimpleModuleNode, CompoundModuleNode, ParamsNode, ParamNode, GatesNode, GateNode, MachinesNode, MachineNode, SubmodulesNode, SubmoduleNode, SubstparamsNode, SubstparamNode, GatesizesNode, GatesizeNode, SubstmachinesNode, SubstmachineNode, ConnectionsNode, ConnectionNode, ConnAttrNode, ForLoopNode, LoopVarNode, DisplayStringNode, ExpressionNode, OperatorNode, FunctionNode, ParamRefNode, IdentNode, ConstNode, CplusplusNode, StructDeclNode, ClassDeclNode, MessageDeclNode, EnumDeclNode, EnumNode, EnumFieldsNode, EnumFieldNode, MessageNode, ClassNode, StructNode, FieldsNode, FieldNode, PropertiesNode, PropertyNode, and UnknownNode.

virtual int NEDElement::getNumChildren | ( |  | ) | const`[virtual]`

| Returns the number of child elements.

virtual int NEDElement::getNumChildrenWithTag | ( | int | tagcode | ) | const`[virtual]`

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

virtual NEDElement* NEDElement::getParent | ( |  | ) | const`[virtual]`

| Returns the parent element, or NULL if this element has no parent.

NEDElement* NEDElement::getParentWithTag | ( | int | tagcode | ) |

| Climb up in the element tree until it finds an element with the given tagcode. Returns NULL if not found.

virtual NEDElement* NEDElement::getPrevSibling | ( |  | ) | const`[virtual]`

| Returns pointer to the previous sibling of this element (i.e. the previous child in the parent element). Returns NULL if there're no elements before this one.

virtual const char* NEDElement::getSourceLocation | ( |  | ) | const`[virtual]`

| Returns a string containing a file/line position showing where this element originally came from.

virtual int NEDElement::getTagCode | ( |  | ) | const`[pure virtual]`

| Overridden in subclasses to return the numeric code (NED_xxx) of the XML element the class represents. Implemented in NedFilesNode, NedFileNode, ImportNode, ImportedFileNode, ChannelNode, ChannelAttrNode, NetworkNode, SimpleModuleNode, CompoundModuleNode, ParamsNode, ParamNode, GatesNode, GateNode, MachinesNode, MachineNode, SubmodulesNode, SubmoduleNode, SubstparamsNode, SubstparamNode, GatesizesNode, GatesizeNode, SubstmachinesNode, SubstmachineNode, ConnectionsNode, ConnectionNode, ConnAttrNode, ForLoopNode, LoopVarNode, DisplayStringNode, ExpressionNode, OperatorNode, FunctionNode, ParamRefNode, IdentNode, ConstNode, CplusplusNode, StructDeclNode, ClassDeclNode, MessageDeclNode, EnumDeclNode, EnumNode, EnumFieldsNode, EnumFieldNode, MessageNode, ClassNode, StructNode, FieldsNode, FieldNode, PropertiesNode, PropertyNode, and UnknownNode.

virtual const char* NEDElement::getTagName | ( |  | ) | const`[pure virtual]`

| Overridden in subclasses to return the name of the XML element the class represents. Implemented in NedFilesNode, NedFileNode, ImportNode, ImportedFileNode, ChannelNode, ChannelAttrNode, NetworkNode, SimpleModuleNode, CompoundModuleNode, ParamsNode, ParamNode, GatesNode, GateNode, MachinesNode, MachineNode, SubmodulesNode, SubmoduleNode, SubstparamsNode, SubstparamNode, GatesizesNode, GatesizeNode, SubstmachinesNode, SubstmachineNode, ConnectionsNode, ConnectionNode, ConnAttrNode, ForLoopNode, LoopVarNode, DisplayStringNode, ExpressionNode, OperatorNode, FunctionNode, ParamRefNode, IdentNode, ConstNode, CplusplusNode, StructDeclNode, ClassDeclNode, MessageDeclNode, EnumDeclNode, EnumNode, EnumFieldsNode, EnumFieldNode, MessageNode, ClassNode, StructNode, FieldsNode, FieldNode, PropertiesNode, PropertyNode, and UnknownNode.

virtual NEDElementUserData* NEDElement::getUserData | ( |  | ) | const`[virtual]`

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

virtual void NEDElement::insertChildBefore | ( | NEDElement * | where,
|  | NEDElement * | newnode
| ) | `[virtual]`

| Inserts the given element just before the specified child element in the child element list. The where element must be a child of this element. The node pointer passed should not be NULL.

virtual int NEDElement::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().

virtual NEDElement* NEDElement::removeChild | ( | NEDElement * | node | ) | `[virtual]`

| Removes the given element from the child element list. The pointer passed should be a child of this element.

virtual void NEDElement::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.

virtual void NEDElement::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. Implemented in NedFilesNode, NedFileNode, ImportNode, ImportedFileNode, ChannelNode, ChannelAttrNode, NetworkNode, SimpleModuleNode, CompoundModuleNode, ParamsNode, ParamNode, GatesNode, GateNode, MachinesNode, MachineNode, SubmodulesNode, SubmoduleNode, SubstparamsNode, SubstparamNode, GatesizesNode, GatesizeNode, SubstmachinesNode, SubstmachineNode, ConnectionsNode, ConnectionNode, ConnAttrNode, ForLoopNode, LoopVarNode, DisplayStringNode, ExpressionNode, OperatorNode, FunctionNode, ParamRefNode, IdentNode, ConstNode, CplusplusNode, StructDeclNode, ClassDeclNode, MessageDeclNode, EnumDeclNode, EnumNode, EnumFieldsNode, EnumFieldNode, MessageNode, ClassNode, StructNode, FieldsNode, FieldNode, PropertiesNode, PropertyNode, and UnknownNode.

virtual void NEDElement::setId | ( | long | id | ) | `[virtual]`

| Unique id assigned by the constructor can be overwritten here.

virtual void NEDElement::setSourceLocation | ( | const char * | loc | ) | `[virtual]`

| Sets location string (a string containing a file/line position showing where this element originally came from). Called by the (NED/XML) parser.

virtual void NEDElement::setUserData | ( | NEDElementUserData * | data | ) | `[virtual]`

| Replaces user data object with the given one.

static bool NEDElement::stringToBool | ( | const char * | s | ) | `[static, protected]`

static int NEDElement::stringToEnum | ( | const char * | s,
|  | const char * | vals[],
|  | int | nums[],
|  | int | n
| ) | `[static, protected]`

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

- nedelement.h