#include <AttributeTree.h>
Public Types | |
enum | { eOK, eEMPTY_TREE, eFILE_SAVE_ERROR, eFILE_LOAD_ERROR } |
Public Member Functions | |
AttributeTree * | addNewSubTree () |
AttributeTree * | addNextTree (AttributeTree *nexttree) |
AttributeTree * | addSubTree (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 () |
AttributeTree * | commentAttributeTree () |
int | contains () |
const char * | fileName () |
AttributeTree * | firstSubTree () |
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) |
AttributeTree * | getSubTree (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="") |
AttributeTree * | nextSubTree (AttributeTree *subtree) |
AttributeTree * | parent () |
AttributeTree * | parentTree () |
void | printSubTree (std::ostream &out, int change_style_depth=3, const char *upper_description=0) |
void | revertOrder () |
AttributeTree * | root () |
int | save (const char *filename, int change_style_depth=3, bool unmark_changes=true) |
AttributeTree * | search (const char *description, const char *attribute) |
AttributeTree * | setAttribute (const char *description, const char *attribute) |
AttributeTree * | setAttribute (const char *description, const char *subdescription, const char *attribute) |
void | setAttribute (const char *attribute) |
void | setComment (const char *comment) |
void | setDescription (const char *description) |
AttributeTree * | subTree (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 | |
AttributeTree * | addSubTree (AttributeTree *subtree, AttributeTree *after_node) |
void | appendString (char *&dest, const char *src, const char *separator) |
char * | getSpecialAttribute (const char *description, AttributeTree **subtree=NULL) |
AttributeTree & | operator= (const AttributeTree &) |
void | split (char *&description, char *&sub_description) |
Private Attributes | |
bool | m_changed |
AttributeTree * | m_parent |
SubTreeList * | m_subtree_list |
char * | m_this_attribute |
char * | m_this_description |
Friends | |
class | SubTreeList |
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:
When getting an attribute that is not stored in the tree, a default value can be specified to be returned in that case.
To store the default attribute if the given description can not be found in the tree, another function can be used:
Definition at line 307 of file AttributeTree.h.
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.
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.
AttributeTree * icl_core::config::AttributeTree::addNewSubTree | ( | ) |
Adds a new sub-node using newSubNodeDescription().
Definition at line 1100 of file AttributeTree.cpp.
|
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().
Definition at line 544 of file AttributeTree.h.
|
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.
|
private |
This function implements addSubTree and addNextTree.
Definition at line 1109 of file AttributeTree.cpp.
|
inline |
Append a string to the attribute.
attribute | the string to be appended |
separator | an additional seperator string which is added in between (e.g. "\n") |
Definition at line 631 of file AttributeTree.h.
|
inline |
Append a string to the description.
description | the string to be appended |
separator | an additional seperator string which is added in between (e.g. "\n") |
Definition at line 641 of file AttributeTree.h.
|
private |
Definition at line 1517 of file AttributeTree.cpp.
|
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.
|
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.
|
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.
|
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.
|
inline |
Returns the description of this node.
Definition at line 455 of file AttributeTree.h.
|
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.
|
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.
|
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
.
filename | Name of the file from which to load the information. |
unmark_changes | If true , all changed flags will be set to false . |
process_include | If true , process include directives in the file. |
load_comments | If 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_order | if this is set true the same tree order than on save is preserved. |
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.
base_description | the base description for the creation of the new one |
Definition at line 1066 of file AttributeTree.cpp.
|
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.
|
private |
|
inline |
Returns the parent tree of this attribute tree.
Definition at line 584 of file AttributeTree.h.
|
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.
|
inline |
This function reverts the order of the AttributeTree.
Definition at line 648 of file AttributeTree.h.
|
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.
|
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.
|
friend |
Definition at line 309 of file AttributeTree.h.
|
private |
Definition at line 986 of file AttributeTree.h.
|
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.
|
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.
|
private |
Definition at line 980 of file AttributeTree.h.
|
private |
Definition at line 981 of file AttributeTree.h.
|
private |
Definition at line 984 of file AttributeTree.h.
|
private |
Definition at line 983 of file AttributeTree.h.