Public Types | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Friends | List of all members
icl_core::config::AttributeTree Class Reference

#include <AttributeTree.h>

Public Types

enum  { eOK, eEMPTY_TREE, eFILE_SAVE_ERROR, eFILE_LOAD_ERROR }
 

Public Member Functions

AttributeTreeaddNewSubTree ()
 
AttributeTreeaddNextTree (AttributeTree *nexttree)
 
AttributeTreeaddSubTree (AttributeTree *subtree)
 
void appendAttribute (const char *attribute, const char *separator="")
 
void appendDescription (const char *description, const char *separator="")
 
const char * attribute () const
 
 AttributeTree (const char *description=0, AttributeTree *parent=0)
 
 AttributeTree (const AttributeTree &other)
 
 AttributeTree (const AttributeTree &other, AttributeTree *parent)
 
bool changed ()
 
const char * comment ()
 
AttributeTreecommentAttributeTree ()
 
int contains ()
 
const char * fileName ()
 
AttributeTreefirstSubTree ()
 
int get (std::istream &in, bool process_include=true, bool load_comments=false, const FilePath *file_path=NULL)
 
char * getAttribute ()
 
char * getAttribute (const char *description, const char *default_attribute=0, AttributeTree **subtree=0)
 
const char * getDescription () const
 
const char * getFilePath ()
 
char * getOrSetDefault (const char *description, const char *default_attribute)
 
AttributeTreegetSubTree (const char *description)
 
bool hasComment ()
 
bool hasMultilineComment ()
 
bool isAttribute (const char *description, const char *attribute=0)
 
bool isComment ()
 
bool isMultilineComment ()
 
int load (const char *filename, bool unmark_changes=true, bool process_include=true, bool load_comments=false, bool preserve_order=false)
 
char * newSubNodeDescription (const char *base_description="")
 
AttributeTreenextSubTree (AttributeTree *subtree)
 
AttributeTreeparent ()
 
AttributeTreeparentTree ()
 
void printSubTree (std::ostream &out, int change_style_depth=3, const char *upper_description=0)
 
void revertOrder ()
 
AttributeTreeroot ()
 
int save (const char *filename, int change_style_depth=3, bool unmark_changes=true)
 
AttributeTreesearch (const char *description, const char *attribute)
 
AttributeTreesetAttribute (const char *description, const char *attribute)
 
AttributeTreesetAttribute (const char *description, const char *subdescription, const char *attribute)
 
void setAttribute (const char *attribute)
 
void setComment (const char *comment)
 
void setDescription (const char *description)
 
AttributeTreesubTree (const char *description)
 
void unlink ()
 
void unlinkSub ()
 
void unmarkChanges ()
 
 ~AttributeTree ()
 

Static Public Attributes

static const char * m_file_name_str = "_ATTRIBUTE_TREE_FILE_NAME_"
 
static const char * m_file_path_str = "_ATTRIBUTE_TREE_FILE_PATH_"
 

Private Member Functions

AttributeTreeaddSubTree (AttributeTree *subtree, AttributeTree *after_node)
 
void appendString (char *&dest, const char *src, const char *separator)
 
char * getSpecialAttribute (const char *description, AttributeTree **subtree=NULL)
 
AttributeTreeoperator= (const AttributeTree &)
 
void split (char *&description, char *&sub_description)
 

Private Attributes

bool m_changed
 
AttributeTreem_parent
 
SubTreeListm_subtree_list
 
char * m_this_attribute
 
char * m_this_description
 

Friends

class SubTreeList
 

Detailed Description

This class can be used to store attribute information in a tree structure. The information can be stored and requested by browsing the tree or by directly giving a description.

Descriptions have the following format:

Examples for setting or reading attributes:

at->setAttribute("Pushbutton.1.geometry.x","135");

When getting an attribute that is not stored in the tree, a default value can be specified to be returned in that case.

at->getAttribute("Pushbutton.1.geometry.x","120");

To store the default attribute if the given description can not be found in the tree, another function can be used:

at->getOrSetDefault("Pushbutton.1.geometry.x","120");
Note
All attributes are stored as strings.

Definition at line 307 of file AttributeTree.h.

Member Enumeration Documentation

anonymous enum

Save and Load error codes.

Enumerator
eOK 

All OK.

eEMPTY_TREE 

Tree is empty.

eFILE_SAVE_ERROR 

Save Error.

eFILE_LOAD_ERROR 

Load Error.

Definition at line 314 of file AttributeTree.h.

Constructor & Destructor Documentation

icl_core::config::AttributeTree::AttributeTree ( const char *  description = 0,
AttributeTree parent = 0 
)

Creates a new empty Tree.

Definition at line 680 of file AttributeTree.cpp.

icl_core::config::AttributeTree::AttributeTree ( const AttributeTree other)

Creates new Tree with same attributes and subtree as the other tree, i.e. this function copies a subtree!

Definition at line 704 of file AttributeTree.cpp.

icl_core::config::AttributeTree::AttributeTree ( const AttributeTree other,
AttributeTree parent 
)

Creates new Tree with same attribute and subtree as the other tree, i.e. this function copies a subtree!

Attention: The Tree is inserted into the list of specified parent (if given). There is no check whether another subtree with same description exists or not!

Definition at line 743 of file AttributeTree.cpp.

icl_core::config::AttributeTree::~AttributeTree ( )

Deletes tree including its subtrees. The parent is informed about this deletion (the sub_tree pointer is set to 0).

Definition at line 787 of file AttributeTree.cpp.

Member Function Documentation

AttributeTree * icl_core::config::AttributeTree::addNewSubTree ( )

Adds a new sub-node using newSubNodeDescription().

Definition at line 1100 of file AttributeTree.cpp.

AttributeTree* icl_core::config::AttributeTree::addNextTree ( AttributeTree nexttree)
inline

Inserts a tree as a next node of this node. If the tree's description is already used by another node on that level, the description is set to a new unused description by using newSubNodeDescription().

Note
This is only possible if this object has a parent. On failure NULL is returned.

Definition at line 544 of file AttributeTree.h.

AttributeTree* icl_core::config::AttributeTree::addSubTree ( AttributeTree subtree)
inline

Inserts a tree as a subtree of this node. If the tree's description is already used by another subtree, the description is set to a new unused description by using newSubNodeDescription().

Definition at line 532 of file AttributeTree.h.

AttributeTree * icl_core::config::AttributeTree::addSubTree ( AttributeTree subtree,
AttributeTree after_node 
)
private

This function implements addSubTree and addNextTree.

Definition at line 1109 of file AttributeTree.cpp.

void icl_core::config::AttributeTree::appendAttribute ( const char *  attribute,
const char *  separator = "" 
)
inline

Append a string to the attribute.

Parameters
attributethe string to be appended
separatoran additional seperator string which is added in between (e.g. "\n")

Definition at line 631 of file AttributeTree.h.

void icl_core::config::AttributeTree::appendDescription ( const char *  description,
const char *  separator = "" 
)
inline

Append a string to the description.

Parameters
descriptionthe string to be appended
separatoran additional seperator string which is added in between (e.g. "\n")

Definition at line 641 of file AttributeTree.h.

void icl_core::config::AttributeTree::appendString ( char *&  dest,
const char *  src,
const char *  separator 
)
private

Definition at line 1517 of file AttributeTree.cpp.

const char* icl_core::config::AttributeTree::attribute ( ) const
inline

Returns the Attribute of this node.

Definition at line 462 of file AttributeTree.h.

bool icl_core::config::AttributeTree::changed ( )

Returns true if any changes occurred since the last call of unmarkChanges().

Definition at line 1481 of file AttributeTree.cpp.

const char * icl_core::config::AttributeTree::comment ( )

Returns the Comment of this Attribute Tree. If no comment subtree exists "" is returned.

Definition at line 1571 of file AttributeTree.cpp.

AttributeTree * icl_core::config::AttributeTree::commentAttributeTree ( )

Get the comment subtree. If none exists NULL is returned.

Definition at line 1547 of file AttributeTree.cpp.

int icl_core::config::AttributeTree::contains ( )

Returns the number of valid entries in the subtree.

Definition at line 1503 of file AttributeTree.cpp.

const char* icl_core::config::AttributeTree::fileName ( )
inline

This function directly returns the filename this attribute belongs to. This corresponds to the virtual attribute 'm_file_name_str'.

Definition at line 693 of file AttributeTree.h.

AttributeTree* icl_core::config::AttributeTree::firstSubTree ( )
inline

Get a pointer to the first subtree. This function can be used to browse the whole tree.

Definition at line 492 of file AttributeTree.h.

int icl_core::config::AttributeTree::get ( std::istream &  in,
bool  process_include = true,
bool  load_comments = false,
const FilePath file_path = NULL 
)

Reads information from a stream and stores it into a tree.

Definition at line 1288 of file AttributeTree.cpp.

char* icl_core::config::AttributeTree::getAttribute ( )
inline

Set an attribute in the subtree of this tree. This is used to set an attribute in the tree without knowing the root descriptor.

Returns the attribute of this node.

Definition at line 383 of file AttributeTree.h.

char * icl_core::config::AttributeTree::getAttribute ( const char *  description,
const char *  default_attribute = 0,
AttributeTree **  subtree = 0 
)

Returns the attribute of a given description. If the description is not stored in the tree, the default_attribute is returned.

Definition at line 984 of file AttributeTree.cpp.

const char* icl_core::config::AttributeTree::getDescription ( ) const
inline

Returns the description of this node.

Definition at line 455 of file AttributeTree.h.

const char* icl_core::config::AttributeTree::getFilePath ( )
inline

This function directly returns the virtual attribute 'm_file_path_str'.

Definition at line 669 of file AttributeTree.h.

char * icl_core::config::AttributeTree::getOrSetDefault ( const char *  description,
const char *  default_attribute 
)

Gets an attribute. If the attribute is not set in the tree, the given default-value is saved into the tree.

Definition at line 1055 of file AttributeTree.cpp.

char * icl_core::config::AttributeTree::getSpecialAttribute ( const char *  description,
AttributeTree **  subtree = NULL 
)
private

This function searches for special attributes up to the root.

Definition at line 959 of file AttributeTree.cpp.

AttributeTree * icl_core::config::AttributeTree::getSubTree ( const char *  description)

Returns the subtree with the given description if it exists. Returns NULL if not.

Definition at line 889 of file AttributeTree.cpp.

bool icl_core::config::AttributeTree::hasComment ( )
inline

Checks if the Attribute Tree has a comment.

Definition at line 605 of file AttributeTree.h.

bool icl_core::config::AttributeTree::hasMultilineComment ( )

Checks if the Attribute Tree has a multiline comment.

Definition at line 1584 of file AttributeTree.cpp.

bool icl_core::config::AttributeTree::isAttribute ( const char *  description,
const char *  attribute = 0 
)

Returns true if the description's attribute is equal to the given attribute.

Definition at line 1463 of file AttributeTree.cpp.

bool icl_core::config::AttributeTree::isComment ( )

Checks if this Attribute Tree is a comment.

Definition at line 1561 of file AttributeTree.cpp.

bool icl_core::config::AttributeTree::isMultilineComment ( )

Checks if this Attribute Tree is a multiline comment.

Definition at line 1566 of file AttributeTree.cpp.

int icl_core::config::AttributeTree::load ( const char *  filename,
bool  unmark_changes = true,
bool  process_include = true,
bool  load_comments = false,
bool  preserve_order = false 
)

Reads information from a file and stores it into a tree. If unmark_changes is true, all changed flags will be set to false.

Parameters
filenameName of the file from which to load the information.
unmark_changesIf true, all changed flags will be set to false.
process_includeIf true, process include directives in the file.
load_commentsIf true, load comments as tree nodes rather than ignoring them. This way the comments remain intact when saving the tree back to a file.
preserve_orderif this is set true the same tree order than on save is preserved.
Note
this reverts the internal list after loading

Definition at line 1239 of file AttributeTree.cpp.

char * icl_core::config::AttributeTree::newSubNodeDescription ( const char *  base_description = "")

Creates and returns a new node description. This description contains a so far unused number. You have to delete it if you don't use it anymore. Note: setDescription() makes an own copy of a given string on the heap! You normally don't use this, use addNewSubTree to create new subtrees. Creates and returns a new sub-node description. This description contains a so far unused number. You have to delete it if you dont use it anymore.

Parameters
base_descriptionthe base description for the creation of the new one

Definition at line 1066 of file AttributeTree.cpp.

AttributeTree* icl_core::config::AttributeTree::nextSubTree ( AttributeTree subtree)
inline

Get a pointer to the next subtree. This function can be used to browse the whole tree.

Definition at line 507 of file AttributeTree.h.

AttributeTree& icl_core::config::AttributeTree::operator= ( const AttributeTree )
private
AttributeTree* icl_core::config::AttributeTree::parent ( )
inline

Returns the parent tree of this attribute tree.

Definition at line 584 of file AttributeTree.h.

AttributeTree* icl_core::config::AttributeTree::parentTree ( )
inline

Get a pointer to the parent tree. Returns NULL if this tree has no parent.

Definition at line 522 of file AttributeTree.h.

void icl_core::config::AttributeTree::printSubTree ( std::ostream &  out,
int  change_style_depth = 3,
const char *  upper_description = 0 
)

Prints all stored attributes of a subtree in an std::ostream. All descriptions will be appended to upper_description before being printed.

Definition at line 1138 of file AttributeTree.cpp.

void icl_core::config::AttributeTree::revertOrder ( )
inline

This function reverts the order of the AttributeTree.

Definition at line 648 of file AttributeTree.h.

AttributeTree* icl_core::config::AttributeTree::root ( )
inline

Return the top-level attribute tree.

Definition at line 591 of file AttributeTree.h.

int icl_core::config::AttributeTree::save ( const char *  filename,
int  change_style_depth = 3,
bool  unmark_changes = true 
)

Saves the tree into a file. If unmark_changes is true, all changed flags will be set to false.

Definition at line 1218 of file AttributeTree.cpp.

AttributeTree * icl_core::config::AttributeTree::search ( const char *  description,
const char *  attribute 
)

Returns the AttributeTree found if there is any description or subdescription that matches the given description AND its attribute is equal to the given one. NULL is returned if nothing is found. If the given attribute is NULL, only the match of the descriptions is considered.

Definition at line 1446 of file AttributeTree.cpp.

AttributeTree * icl_core::config::AttributeTree::setAttribute ( const char *  description,
const char *  attribute 
)

Returns a subtree that fits the given description. Additional subtrees are created if necessary. This inline function just calls setAttribute(description, 0).

Sets an attribute. Additional subtrees are created if necessary. The return value is a direct pointer to the subtree entry that contains the attribute. If attribute is 0, it is not set, but the return value points to the corresponding entry in the tree.

Definition at line 906 of file AttributeTree.cpp.

AttributeTree * icl_core::config::AttributeTree::setAttribute ( const char *  description,
const char *  subdescription,
const char *  attribute 
)

Same function as above but with the main description already split off from the description string.

Definition at line 924 of file AttributeTree.cpp.

void icl_core::config::AttributeTree::setAttribute ( const char *  attribute)

Sets the Attribute of this AttributeTree.

Definition at line 855 of file AttributeTree.cpp.

void icl_core::config::AttributeTree::setComment ( const char *  comment)

Sets the Comment of this AttributeTree.

Definition at line 1589 of file AttributeTree.cpp.

void icl_core::config::AttributeTree::setDescription ( const char *  description)

Changes the description of this node.

Definition at line 842 of file AttributeTree.cpp.

void icl_core::config::AttributeTree::split ( char *&  description,
char *&  sub_description 
)
private

Definition at line 1436 of file AttributeTree.cpp.

AttributeTree * icl_core::config::AttributeTree::subTree ( const char *  description)

Returns the subtree with the given description. Creates a new one if necessary.

Definition at line 874 of file AttributeTree.cpp.

void icl_core::config::AttributeTree::unlink ( )

This function is used to unlink this tree from its parent. Deleting the parent afterwards does not delete this subtree.

Definition at line 825 of file AttributeTree.cpp.

void icl_core::config::AttributeTree::unlinkSub ( )

This function is used to unlink this tree's subtree. Deleting this afterwards does not delete the subtree.

Definition at line 814 of file AttributeTree.cpp.

void icl_core::config::AttributeTree::unmarkChanges ( )

Sets all changed flags to false.

Definition at line 1494 of file AttributeTree.cpp.

Friends And Related Function Documentation

friend class SubTreeList
friend

Definition at line 309 of file AttributeTree.h.

Member Data Documentation

bool icl_core::config::AttributeTree::m_changed
private

Definition at line 986 of file AttributeTree.h.

const char * icl_core::config::AttributeTree::m_file_name_str = "_ATTRIBUTE_TREE_FILE_NAME_"
static

On loading of an attribute tree a virtual attribute with name 'm_file_name_str' is created storing the filename of the loaded attribute tree file (without path). By Calling 'GetAttribute(AttributeTree::m_file_name_str, "")' this virtual attribute is returned. If you are loading more than one attribute tree file (e.g. by includes), the file stored in here is the one of the last loaded file.

Definition at line 687 of file AttributeTree.h.

const char * icl_core::config::AttributeTree::m_file_path_str = "_ATTRIBUTE_TREE_FILE_PATH_"
static

On loading of an attribute tree a virtual attribute with name 'm_file_path_str' is created storing the absolute path to the loaded attribute tree file. By Calling 'GetAttribute(AttributeTree::m_file_path_str, "")' this virtual attribute is returned. If you are loading more than one attribute tree file (e.g. by includes), the path stored in here is the one of the last loaded file.

Definition at line 664 of file AttributeTree.h.

AttributeTree* icl_core::config::AttributeTree::m_parent
private

Definition at line 980 of file AttributeTree.h.

SubTreeList* icl_core::config::AttributeTree::m_subtree_list
private

Definition at line 981 of file AttributeTree.h.

char* icl_core::config::AttributeTree::m_this_attribute
private

Definition at line 984 of file AttributeTree.h.

char* icl_core::config::AttributeTree::m_this_description
private

Definition at line 983 of file AttributeTree.h.


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


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:59