diff options
Diffstat (limited to 'src/cnode')
-rw-r--r-- | src/cnode/cnode-algorithm.cpp | 12 | ||||
-rw-r--r-- | src/cnode/cnode.cpp | 83 | ||||
-rw-r--r-- | src/cnode/cnode.hpp | 5 |
3 files changed, 90 insertions, 10 deletions
diff --git a/src/cnode/cnode-algorithm.cpp b/src/cnode/cnode-algorithm.cpp index d1101d7..c830ce4 100644 --- a/src/cnode/cnode-algorithm.cpp +++ b/src/cnode/cnode-algorithm.cpp @@ -260,7 +260,8 @@ _diff_show_other(CfgNode *cfg1, CfgNode *cfg2, int level, bool show_def, * (3) has a "name". */ const string& name = cfg->getName(); - bool print_this = (((cfg1 && !cfg1->isTag()) || (cfg2 && !cfg2->isTag())) + bool print_this = (((cfg1 && (!cfg1->isTag() || cfg1->isValue())) + || (cfg2 && (!cfg2->isTag() || cfg2->isValue()))) && level >= 0 && name.size() > 0); if (print_this) { _diff_print_comment(cfg1, cfg2, level); @@ -288,13 +289,15 @@ _diff_show_other(CfgNode *cfg1, CfgNode *cfg2, int level, bool show_def, Cstore::MapT<string, CfgNode *> nmap1, nmap2; for (size_t i = 0; i < cnodes1.size(); i++) { string key - = (cfg->isTag() ? cnodes1[i]->getValue() : cnodes1[i]->getName()); + = ((cfg->isTag() && !cfg->isValue()) + ? cnodes1[i]->getValue() : cnodes1[i]->getName()); map[key] = true; nmap1[key] = cnodes1[i]; } for (size_t i = 0; i < cnodes2.size(); i++) { string key - = (cfg->isTag() ? cnodes2[i]->getValue() : cnodes2[i]->getName()); + = ((cfg->isTag() && !cfg->isValue()) + ? cnodes2[i]->getValue() : cnodes2[i]->getName()); map[key] = true; nmap2[key] = cnodes2[i]; } @@ -312,7 +315,8 @@ _diff_show_other(CfgNode *cfg1, CfgNode *cfg2, int level, bool show_def, CfgNode *c1 = (in1 ? nmap1[cnodes[i]] : NULL); CfgNode *c2 = (in2 ? nmap2[cnodes[i]] : NULL); - int next_level = (cfg->isTag() ? ((level >= 0) ? level : 0) : (level + 1)); + int next_level = ((cfg->isTag() && !cfg->isValue()) + ? ((level >= 0) ? level : 0) : (level + 1)); _show_diff(c1, c2, next_level, show_def, hide_secret); } diff --git a/src/cnode/cnode.cpp b/src/cnode/cnode.cpp index 2948a14..0f6976d 100644 --- a/src/cnode/cnode.cpp +++ b/src/cnode/cnode.cpp @@ -26,11 +26,82 @@ using namespace std; using namespace cnode; +/* XXX + from cstore: extra level for tag node + delayed processing for _is_empty, _is_leaf_typeless + */ + ////// constructors/destructors +CfgNode::CfgNode(vector<string>& path_comps, char *name, char *val, + char *comment, int deact, Cstore *cstore) + : _is_tag(false), _is_leaf(false), _is_multi(false), _is_value(false), + _is_default(false), _is_deactivated(false), _is_leaf_typeless(false), + _is_invalid(false), _is_empty(false) +{ + if (name && name[0]) { + // name must be non-empty + path_comps.push_back(name); + } + if (val) { + // value could be empty + path_comps.push_back(val); + } + + while (1) { + if (path_comps.size() == 0) { + // nothing to do for root node + break; + } + + vtw_def def; + if (cstore->validateTmplPath(path_comps, false, def)) { + // got the def + _is_value = def.is_value; + _is_tag = def.tag; + _is_leaf = (!def.tag && def.def_type != ERROR_TYPE); + _is_multi = def.multi; + + /* XXX given the current definition of "default", the concept of + * "default" doesn't really apply to config files. + */ + _is_default = false; + _is_deactivated = deact; + if (name) { + _name = name; + } + if (val) { + if (_is_multi) { + _values.push_back(val); + } else { + _value = val; + } + } + if (comment) { + _comment = comment; + } + // ignore return + } else { + // not a valid node + _is_invalid = true; + break; + } + + break; + } + + // restore path_comps + if (val) { + path_comps.pop_back(); + } + if (name && name[0]) { + path_comps.pop_back(); + } +} + CfgNode::CfgNode(Cstore& cstore, vector<string>& path_comps, bool active, bool recursive) : _is_tag(false), _is_leaf(false), _is_multi(false), _is_value(false), - _is_default(false), _is_deactivated(false), _is_leaf_typeless(false), + _is_default(false), _is_deactivated(false), _is_leaf_typeless(false), _is_invalid(false), _is_empty(false) { /* first get the def (only if path is not empty). if path is empty, i.e., @@ -41,17 +112,17 @@ CfgNode::CfgNode(Cstore& cstore, vector<string>& path_comps, if (cstore.validateTmplPath(path_comps, false, def)) { // got the def _is_value = def.is_value; - _is_tag = (def.tag && !_is_value); - _is_leaf = (!_is_tag && !_is_value && def.def_type != ERROR_TYPE); - _is_multi = (_is_leaf && def.multi); + _is_tag = def.tag; + _is_leaf = (!def.tag && def.def_type != ERROR_TYPE); + _is_multi = def.multi; _is_default = cstore.cfgPathDefault(path_comps, active); _is_deactivated = cstore.cfgPathDeactivated(path_comps, active); cstore.cfgPathGetComment(path_comps, _comment, active); // ignore return if (_is_leaf && _is_value) { - /* recursion should never reach here. if path is specified by user, - * nothing further to do. + /* "leaf value" so recursion should never reach here. if path is + * specified by user, nothing further to do. */ return; } diff --git a/src/cnode/cnode.hpp b/src/cnode/cnode.hpp index 0be02ca..aab2d4d 100644 --- a/src/cnode/cnode.hpp +++ b/src/cnode/cnode.hpp @@ -25,6 +25,8 @@ namespace cnode { class CfgNode { public: + CfgNode(vector<string>& path_comps, char *name, char *val, char *comment, + int deact, Cstore *cstore); CfgNode(Cstore& cstore, std::vector<string>& path_comps, bool active = false, bool recursive = true); ~CfgNode() {}; @@ -45,6 +47,9 @@ public: const std::string& getComment() const { return _comment; } const std::vector<CfgNode *>& getChildNodes() const { return _child_nodes; } + void addMultiValue(char *val) { _values.push_back(val); } + void addChildNode(CfgNode *cnode) { _child_nodes.push_back(cnode); } + private: bool _is_tag; bool _is_leaf; |