Computing 4 Assignment 5 - David Lordan
 All Classes Files Functions Variables Enumerations Enumerator
Public Member Functions | Public Attributes | List of all members
Element Class Reference

#include <Element.h>

Public Member Functions

 Element ()
 
 Element (const Element &orig)
 
virtual ~Element ()
 
 Element (string strElementName, int nLineNo, string content, string currentLine)
 
int getLineNo () const
 
string getTagName () const
 
string getStrContent () const
 
void setStrContent (string content)
 
void setTagName (string tagName)
 
void displayAttributes ()
 
void addChild (Element *newChild)
 
void setParent (Element *Parent)
 
ElementgetParent ()
 
int getNoOfChildren ()
 
int getLevel ()
 
void setLevel (int newLevel)
 
bool hasAttributes ()
 

Public Attributes

vector< Attribute * > vecAttribute
 
vector< Element * > vecChildren
 

Detailed Description

Definition at line 27 of file Element.h.

Constructor & Destructor Documentation

Element::Element ( )

Default constructor. Sets strTagName and strContent to be an empty string, sets lineNumber to 0.

Definition at line 22 of file Element.cpp.

Element::Element ( const Element orig)

Copy constructor Creates a new Element object setting each element variable to match the object it is copied from.

Parameters
orig- Original element object which is copied.

Definition at line 34 of file Element.cpp.

Element::~Element ( )
virtual

Standard destructor.

Definition at line 69 of file Element.cpp.

Element::Element ( string  tagName,
int  nLineNo,
string  content,
string  currentLine 
)

Custom constructor. Assigns the passed parameters to the newly created element's member variables. Used in the program whenever a new element is created. Also calls the 'findAttributes' function which will scan the line on which the element was found for attributes and populate a vector of found attributes. Also sets the to element's level to 0 as the 'setLevel' function is called after the new element is created. This should be re-factored in future versions.

Parameters
tagName- A string which is used to store the element's tag name.
nLineNo- The line number of the XML file on which the element was found.
content- A string which is used to store the element's content.
currentLine- The entire line of an XML file on which the element was found, used when 'findAttributes' is called.

Definition at line 53 of file Element.cpp.

Member Function Documentation

void Element::addChild ( Element newChild)

Function to store pointers to children of the element. Pointers are pushed on to the element's 'vecChildren' vector and the number of children is incremented. This is called in the program just after a new element is created. In future versions this should be called in the element's constructor.

Parameters
newChild- A pointer to an element that is the child of the element object.

Definition at line 204 of file Element.cpp.

void Element::displayAttributes ( )

Function used to output the element's attribute names and values. This is used during the tree building process and after the tree has been built. During tree building, this function is called before the element's level has been set. The function uses this default level to determine if the tree is currently being built. This behavior is not reliable and should be updated in future versions.

Definition at line 122 of file Element.cpp.

int Element::getLevel ( )

A function that returns the level on which an element was found. This is called when new element objects are being created to retrieve the level of their parent. This is also called as the element tree is being displayed.

Returns
level - The level within the element tree in which the element object is located.

Definition at line 243 of file Element.cpp.

int Element::getLineNo ( ) const

Standard getter for the line number that a element is found on in an XML file. Used throughout the program for output and organizes the the building of the tree.

Returns
lineNumber - The line in an XML file on which an element was found.

Definition at line 86 of file Element.cpp.

int Element::getNoOfChildren ( )

Returns the number of children that an element object contains. This is called as the element tree is being displayed.

Returns
noOfChildren - An integer which is the number of children that the element object has.

Definition at line 233 of file Element.cpp.

Element * Element::getParent ( )

Function that returns a pointer to the current element's parent. This is used for creating the element tree as well as setting the element object's level.

Returns
parent - A pointer to the element object's parent.

Definition at line 224 of file Element.cpp.

string Element::getStrContent ( ) const

Standard getter for the content of an element. If the element has no content this will simply return "Empty". Used when displaying the tree structure.

Returns
strContent - The content of the current element. Defaults to "Empty".

Definition at line 95 of file Element.cpp.

string Element::getTagName ( ) const

Standard getter for the element's tag name, used throughout the program for output and for building the tree.

Returns
strTagName - The string stored as the elements tag name.

Definition at line 77 of file Element.cpp.

bool Element::hasAttributes ( )

A simple boolean function that determines if the element object contains attributes or not. This is done by checking if the 'vecAttribute' vector is empty. This is called as the tree is being displayed.

Returns
- Boolean value referencing the presence or lack of attributes for the element.

Definition at line 263 of file Element.cpp.

void Element::setLevel ( int  newLevel)

Sets an element objects level as the element tree is being created. In future versions this should be called within the element constructor.

Parameters
newLevel- The level in which an element is found within the element tree. This parameter is always passed as the element object's parent's level + 1.

Definition at line 253 of file Element.cpp.

void Element::setParent ( Element Parent)

Function to store a pointer to the current element's parent. This is called in the program just after a new element is created. In future versions this should be called in the element's constructor.

Parameters
Parent- A pointer to an element that is the parent of the element object.

Definition at line 215 of file Element.cpp.

void Element::setStrContent ( string  content)

Standard setter for the element's content. Called when a new element is created.

Parameters
content- A string which is to be stored as the element's content.

Definition at line 111 of file Element.cpp.

void Element::setTagName ( string  tagName)

Standard setter for the element's tag name. Called when a new element is created.

Parameters
tagName- A string which is to be stored as the element's tag name.

Definition at line 103 of file Element.cpp.

Member Data Documentation

vector<Attribute*> Element::vecAttribute

A vector which is used to store pointers to attribute objects that belong to the current element object.

Definition at line 163 of file Element.h.

vector<Element*> Element::vecChildren

A vector which is used to store pointers to other element objects that are children of the current element object.

Definition at line 167 of file Element.h.


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