summaryrefslogtreecommitdiff
path: root/src/cnode/cnode.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/cnode/cnode.hpp')
-rw-r--r--src/cnode/cnode.hpp56
1 files changed, 33 insertions, 23 deletions
diff --git a/src/cnode/cnode.hpp b/src/cnode/cnode.hpp
index a684514..2d38737 100644
--- a/src/cnode/cnode.hpp
+++ b/src/cnode/cnode.hpp
@@ -16,24 +16,29 @@
#ifndef _CNODE_HPP_
#define _CNODE_HPP_
+#include <cstdio>
#include <vector>
#include <string>
#include <cstore/cstore.hpp>
+#include <cnode/cnode-util.hpp>
+#include <commit/commit-algorithm.hpp>
namespace cnode {
-using namespace cstore;
-
-class CfgNode {
+class CfgNode : public TreeNode<CfgNode>, public commit::CommitData {
public:
- CfgNode(Cpath& path_comps, char *name, char *val, char *comment,
- int deact, Cstore *cstore, bool tag_if_invalid = false);
- CfgNode(Cstore& cstore, Cpath& path_comps, bool active = false,
- bool recursive = true);
+ // constructor for parser
+ CfgNode(cstore::Cpath& path_comps, char *name, char *val, char *comment,
+ int deact, cstore::Cstore *cstore, bool tag_if_invalid = false);
+ // constructor for active/working config
+ CfgNode(cstore::Cstore& cstore, cstore::Cpath& path_comps,
+ bool active = false, bool recursive = true);
+
~CfgNode() {};
bool isTag() const { return _is_tag; }
+ bool isTagNode() const { return (_is_tag && !_is_value); }
bool isLeaf() const { return _is_leaf; }
bool isMulti() const { return _is_multi; }
bool isValue() const { return _is_value; }
@@ -41,22 +46,29 @@ public:
bool isDeactivated() const { return _is_deactivated; }
bool isLeafTypeless() const { return _is_leaf_typeless; }
bool isInvalid() const { return _is_invalid; }
- bool isEmpty() const { return _is_empty; }
+ bool isEmpty() const { return (!_is_leaf && numChildNodes() == 0); }
bool exists() const { return _exists; }
- const string& getName() const { return _name; }
- const string& getValue() const { return _value; }
- const vector<string>& getValues() const { return _values; }
- const string& getComment() const { return _comment; }
- const vector<CfgNode *>& getChildNodes() const { return _child_nodes; }
+ const std::string& getName() const { return _name; }
+ const std::string& getValue() const { return _value; }
+ const std::vector<std::string>& getValues() const { return _values; }
+ const std::string& getComment() const { return _comment; }
void addMultiValue(char *val) { _values.push_back(val); }
- void addChildNode(CfgNode *cnode) {
- _child_nodes.push_back(cnode);
- _is_empty = false;
- }
void setValue(char *val) { _value = val; }
+ // XXX testing
+ void rprint(size_t lvl) {
+ for (size_t i = 0; i < lvl; i++) {
+ printf(" ");
+ }
+ printf("[%u][%s][%d]\n", getPriority(),
+ getCommitPath().to_string().c_str(), getCommitState());
+ for (size_t i = 0; i < numChildNodes(); i++) {
+ childAt(i)->rprint(lvl + 1);
+ }
+ }
+
private:
bool _is_tag;
bool _is_leaf;
@@ -66,13 +78,11 @@ private:
bool _is_deactivated;
bool _is_leaf_typeless;
bool _is_invalid;
- bool _is_empty;
bool _exists;
- string _name;
- string _value;
- vector<string> _values;
- string _comment;
- vector<CfgNode *> _child_nodes;
+ std::string _name;
+ std::string _value;
+ std::vector<std::string> _values;
+ std::string _comment;
};
} // namespace cnode