Hasty Badger
Small UI library (a branch of Turbo Badger)
|
TBNode is a tree node with a string name and a value (TBValue). More...
#include <tb_node_tree.h>
Public Types | |
enum | GET_MISS_POLICY { GET_MISS_POLICY_NULL, GET_MISS_POLICY_CREATE } |
Public Member Functions | |
bool | ReadFile (const TBStr &filename, TB_NODE_READ_FLAGS flags=TB_NODE_READ_FLAGS_NONE) |
Read a tree of nodes from file into this node. More... | |
void | ReadData (const char *data, TB_NODE_READ_FLAGS flags=TB_NODE_READ_FLAGS_NONE) |
Read a tree of nodes from a null terminated string buffer. More... | |
void | ReadData (const char *data, int data_len, TB_NODE_READ_FLAGS flags=TB_NODE_READ_FLAGS_NONE) |
Read a tree of nodes from a buffer with a known length. More... | |
void | Clear () |
Clear the contens of this node. More... | |
bool | WriteFile (const TBStr &filename) |
Write a node and it's children to a file. More... | |
bool | WriteNode (TBStr &str, int depth=0) |
Recursively write a node and it's children to a string at depth. More... | |
void | Add (TBNode *n) |
Add node as child to this node. More... | |
void | AddBefore (TBNode *n, TBNode *reference) |
Add node before the reference node (which must be a child to this node). More... | |
void | AddAfter (TBNode *n, TBNode *reference) |
Add node after the reference node (which must be a child to this node). More... | |
void | Remove (TBNode *n) |
Remove child node n from this node. More... | |
void | Delete (TBNode *n) |
Remove and delete child node n from this node. More... | |
bool | CloneChildren (TBNode *source) |
Create duplicates of all items in source and add them to this node. More... | |
TBNode * | GetNode (const char *request, GET_MISS_POLICY mp=GET_MISS_POLICY_NULL) |
Get a node from the given request. More... | |
const TBStr & | GetName () const |
Returns the name of this node. More... | |
TBValue & | GetValue () |
Returns the value of this node. More... | |
TBValue & | GetValueFollowRef () |
Returns the value of this node. More... | |
int | GetValueInt (const char *request, int def) |
Get a value from the given request as an integer. More... | |
float | GetValueFloat (const char *request, float def) |
Get a value from the given request as an float. More... | |
TBStr | GetValueString (const char *request, const char *def) |
Get a value from the given request as an string. More... | |
TBStr | GetValueStringRaw (const char *request, const char *def) |
Same as GetValueString, but won't look up language string references. More... | |
TBNode * | GetParent () const |
TBNode * | GetFirstChild () const |
TBNode * | GetLastChild () const |
Public Member Functions inherited from tb::TBLinkOf< TBNode > | |
TBNode * | GetPrev () const |
TBNode * | GetNext () const |
Public Member Functions inherited from tb::TBLink | |
bool | IsInList () const |
Return true if the link is currently added to a list. More... | |
Static Public Member Functions | |
static TBNode * | Create (TBStr name) |
Create a new node with the given name. More... | |
static const char * | GetNextNodeSeparator (const char *request) |
Get the next position in request that is a sub node separator, or the end of the string. More... | |
Friends | |
class | TBNodeTarget |
class | TBNodeRefTree |
Additional Inherited Members | |
Public Attributes inherited from tb::TBLink | |
TBLink * | prev |
TBLink * | next |
TBLinkList * | linklist |
TBNode is a tree node with a string name and a value (TBValue).
It may have a parent TBNode and child TBNodes.
Getting the value of this node or any child, may optionally follow references to nodes in any existing TBNodeRefTree (by name).
During ReadFile/ReadData, it may also select which branches to include or exclude conditionally by lookup up values in TBNodeRefTree.
|
inline |
Add node as child to this node.
Add node after the reference node (which must be a child to this node).
Add node before the reference node (which must be a child to this node).
void tb::TBNode::Clear | ( | ) |
Clear the contens of this node.
bool tb::TBNode::CloneChildren | ( | TBNode * | source | ) |
Create duplicates of all items in source and add them to this node.
Note: Nodes does not replace existing nodes with the same name. Cloned nodes are added after any existing nodes.
|
inline |
Remove and delete child node n from this node.
|
inline |
Returns the name of this node.
|
static |
Get the next position in request that is a sub node separator, or the end of the string.
TBNode * tb::TBNode::GetNode | ( | const char * | request, |
GET_MISS_POLICY | mp = GET_MISS_POLICY_NULL |
||
) |
Get a node from the given request.
If the node doesn't exist, it will either return nullptr or create missing nodes, depending on the miss policy. It can find nodes in children as well. Names are separated by a ">".
Ex: GetNode("dishes>pizza>special>batman")
|
inline |
Returns the value of this node.
float tb::TBNode::GetValueFloat | ( | const char * | request, |
float | def | ||
) |
Get a value from the given request as an float.
Will follow possible references to TBNodeRefTree. If the value is not specified, it returns the default value (def).
TBValue & tb::TBNode::GetValueFollowRef | ( | ) |
Returns the value of this node.
Will follow possible references to TBNodeRefTree.
int tb::TBNode::GetValueInt | ( | const char * | request, |
int | def | ||
) |
Get a value from the given request as an integer.
Will follow possible references to TBNodeRefTree. If the value is not specified, it returns the default value (def).
TBStr tb::TBNode::GetValueString | ( | const char * | request, |
const char * | def | ||
) |
Get a value from the given request as an string.
Will follow possible references to TBNodeRefTree. Will also return any referenced language string. If the value is not specified, it returns the default value (def).
TBStr tb::TBNode::GetValueStringRaw | ( | const char * | request, |
const char * | def | ||
) |
Same as GetValueString, but won't look up language string references.
void tb::TBNode::ReadData | ( | const char * | data, |
TB_NODE_READ_FLAGS | flags = TB_NODE_READ_FLAGS_NONE |
||
) |
Read a tree of nodes from a null terminated string buffer.
void tb::TBNode::ReadData | ( | const char * | data, |
int | data_len, | ||
TB_NODE_READ_FLAGS | flags = TB_NODE_READ_FLAGS_NONE |
||
) |
Read a tree of nodes from a buffer with a known length.
bool tb::TBNode::ReadFile | ( | const TBStr & | filename, |
TB_NODE_READ_FLAGS | flags = TB_NODE_READ_FLAGS_NONE |
||
) |
Read a tree of nodes from file into this node.
Returns true on success.
|
inline |
Remove child node n from this node.
bool tb::TBNode::WriteFile | ( | const TBStr & | filename | ) |
Write a node and it's children to a file.
bool tb::TBNode::WriteNode | ( | TBStr & | str, |
int | depth = 0 |
||
) |