summaryrefslogtreecommitdiff
path: root/src/cnode/cnode.cpp
diff options
context:
space:
mode:
authorAn-Cheng Huang <ancheng@vyatta.com>2010-11-12 19:12:53 -0800
committerAn-Cheng Huang <ancheng@vyatta.com>2010-11-12 19:12:53 -0800
commit79a94470b0f3fd4f7924bb096c61b8e064b65750 (patch)
tree049225edbd21f873b9a4bcac6571603a35aa1e89 /src/cnode/cnode.cpp
parente08c1879028ddd3b594b01c82859f8431894f497 (diff)
downloadvyatta-cfg-79a94470b0f3fd4f7924bb096c61b8e064b65750.tar.gz
vyatta-cfg-79a94470b0f3fd4f7924bb096c61b8e064b65750.zip
initial work to parse config file into data structure.
Diffstat (limited to 'src/cnode/cnode.cpp')
-rw-r--r--src/cnode/cnode.cpp83
1 files changed, 77 insertions, 6 deletions
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;
}