Hasty Badger
Small UI library (a branch of Turbo Badger)
 All Classes Namespaces Functions Variables Enumerations Enumerator Friends Groups Pages
tb_node_ref_tree.h
1 // ================================================================================
2 // == This file is a part of Turbo Badger. (C) 2011-2014, Emil SegerÃ¥s ==
3 // == See tb_core.h for more information. ==
4 // ================================================================================
5 
6 #ifndef TB_NODE_REF_TREE_H
7 #define TB_NODE_REF_TREE_H
8 
9 #include "tb_linklist.h"
10 #include "tb_node_tree.h"
11 #include "tb_id.h"
12 
13 namespace tb {
14 
15 class TBNode;
16 class TBNodeRefTreeListener;
17 
23 class TBNodeRefTree : public TBLinkOf<TBNodeRefTree>
24 {
25 public:
26  TBNodeRefTree(const char *name);
27  virtual ~TBNodeRefTree();
28 
29  const TBStr & GetName() const { return m_name; }
30  const TBID &GetNameID() const { return m_name_id; }
31 
33  bool ReadFile(const char *filename) { return m_node.ReadFile(filename); }
34  void ReadData(const char *data) { m_node.ReadData(data); }
35 
37  void AddListener(TBNodeRefTreeListener *listener) { m_listeners.AddLast(listener); }
38 
40  void RemoveListener(TBNodeRefTreeListener *listener) { m_listeners.Remove(listener); }
41 
44  virtual void SetValue(const char *request, const TBValue &value);
45 
48  virtual TBValue &GetValue(const char *request);
49 
52  static TBValue &GetValueFromTree(const char *request);
53 
55  static TBNodeRefTree *GetRefTree(const char *name, int name_len);
56 
59  static void ResolveConditions(TBNode *parent_node);
60 private:
61  friend class TBNode;
62  friend class TBNodeTarget;
65  static TBNode *FollowNodeRef(TBNode *node);
66 
67  void InvokeChangeListenersInternal(const char *request);
68  TBNode m_node;
69  TBStr m_name;
70  TBID m_name_id;
72  static TBLinkListOf<TBNodeRefTree> s_ref_trees;
73 };
74 
78 class TBNodeRefTreeListener : public TBLinkOf<TBNodeRefTreeListener>
79 {
80 public:
83  virtual void OnDataChanged(TBNodeRefTree *rt, const char *request) = 0;
84 };
85 
86 } // namespace tb
87 
88 #endif // TB_NODE_REF_TREE_H
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.
Definition: tb_node_tree.cpp:290
virtual void OnDataChanged(TBNodeRefTree *rt, const char *request)=0
Called when the value is changed for the given node in the given ref tree.
TBNodeRefTreeListener receive OnDataChanged when the value of a node in a TBNodeRefTree is changed...
Definition: tb_node_ref_tree.h:78
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.
Definition: tb_node_tree.cpp:304
void RemoveListener(TBNodeRefTreeListener *listener)
Remove a change listener from this tree.
Definition: tb_node_ref_tree.h:40
Definition: tb_node_tree.cpp:183
virtual TBValue & GetValue(const char *request)
Get the value of the given request.
Definition: tb_node_ref_tree.cpp:27
bool ReadFile(const char *filename)
Read the data file.
Definition: tb_node_ref_tree.h:33
TBID is a wrapper for a uint32_t to be used as ID.
Definition: tb_id.h:18
static TBValue & GetValueFromTree(const char *request)
Get the value of the given tree name and request (&gt;noderequest).
Definition: tb_node_ref_tree.cpp:37
virtual void SetValue(const char *request, const TBValue &value)
Set the value for the given request and invoke the change listener.
Definition: tb_node_ref_tree.cpp:49
static void ResolveConditions(TBNode *parent_node)
Go through the tree of nodes recursively and include or remove branches depending on any conditions...
Definition: tb_node_ref_tree.cpp:144
TBNodeRefTree is a named TBNode.
Definition: tb_node_ref_tree.h:23
TBStr is a simple string class.
Definition: tb_str.h:62
TBNode is a tree node with a string name and a value (TBValue).
Definition: tb_node_tree.h:30
TBValue holds value of a specific type.
Definition: tb_value.h:59
void AddListener(TBNodeRefTreeListener *listener)
Add a listener that is invoked on changes in this tree.
Definition: tb_node_ref_tree.h:37
static TBNodeRefTree * GetRefTree(const char *name, int name_len)
Return the tree with the given name, or nullptr if no matching tree exists.
Definition: tb_node_ref_tree.cpp:67