Hasty Badger
Small UI library (a branch of Turbo Badger)
 All Classes Namespaces Functions Variables Enumerations Enumerator Friends Groups Pages
tb::TBNode Class Reference

TBNode is a tree node with a string name and a value (TBValue). More...

#include <tb_node_tree.h>

Inheritance diagram for tb::TBNode:
tb::TBLinkOf< TBNode > tb::TBLink

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...
 
TBNodeGetNode (const char *request, GET_MISS_POLICY mp=GET_MISS_POLICY_NULL)
 Get a node from the given request. More...
 
const TBStrGetName () const
 Returns the name of this node. More...
 
TBValueGetValue ()
 Returns the value of this node. More...
 
TBValueGetValueFollowRef ()
 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...
 
TBNodeGetParent () const
 
TBNodeGetFirstChild () const
 
TBNodeGetLastChild () const
 

Static Public Member Functions

static TBNodeCreate (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

Detailed Description

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.

Member Enumeration Documentation

Enumerator
GET_MISS_POLICY_NULL 

GetNode will return nullptr if the node doesn't exist.

GET_MISS_POLICY_CREATE 

GetNode will create all missing nodes for the request.

Member Function Documentation

void tb::TBNode::Add ( TBNode n)
inline

Add node as child to this node.

void tb::TBNode::AddAfter ( TBNode n,
TBNode reference 
)
inline

Add node after the reference node (which must be a child to this node).

void tb::TBNode::AddBefore ( TBNode n,
TBNode reference 
)
inline

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.

TBNode * tb::TBNode::Create ( TBStr  name)
static

Create a new node with the given name.

void tb::TBNode::Delete ( TBNode n)
inline

Remove and delete child node n from this node.

const TBStr& tb::TBNode::GetName ( ) const
inline

Returns the name of this node.

const char * tb::TBNode::GetNextNodeSeparator ( const char *  request)
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")

TBValue& tb::TBNode::GetValue ( )
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.

void tb::TBNode::Remove ( TBNode n)
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 
)

Recursively write a node and it's children to a string at depth.

Todo:
use better datastructure than TBStr for this.

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