Permalink
Browse files

Added argument to tree schema validation

  • Loading branch information...
1 parent 932fa48 commit 11dbd07ed5469bec8ee95194c57c73a3f16dc53e @saleyn committed Jul 14, 2014
Showing with 17 additions and 10 deletions.
  1. +5 −3 bin/config_validator_codegen.py
  2. +12 −7 include/utxx/variant_tree.hpp
View
8 bin/config_validator_codegen.py
@@ -25,7 +25,7 @@
import time
from copy import deepcopy
import sys
-
+import re
def flatten(*n):
"""
@@ -71,6 +71,8 @@ def print_tree(root, stream = sys.stdout, ids=None, comments=False):
def print_element(e, stream = sys.stdout, with_offset=True, ids=None):
print >> stream, node_to_string(e, with_offset=with_offset, ids=ids)
+def format_name(name):
+ return re.sub('[-.,;:]', '_', name.upper())
class RenamedTemporaryFile(object):
"""
@@ -336,7 +338,7 @@ def run(self):
f.write(" //---------- Configuration Options ------------\n")
for n in names:
- u = n.upper()
+ u = format_name(n)
f.write(' static const char CFG_%s[]%s = "%s";\n' % (u, ' ' * (max_width - len(n) + 4), n))
f.write("\n")
f.write(" //---------- Configuration Values -------------\n")
@@ -467,7 +469,7 @@ def process_options(self, f, root, level=0, arg='m_options'):
'%s "%s", %s, %s, %s,\n'
"%s v(%s), v(%s), v(%s), l_names, l_values, l_children%d));\n"
"%s}\n" % (
- ws2, name.upper(), str_tp, self.string_to_type(valtp),
+ ws2, format_name(name), str_tp, self.string_to_type(valtp),
ws2, desc, unique, required, macros,
ws2,('"%s"' % default) if default else "",
('"%s"' % min) if min else "",
View
19 include/utxx/variant_tree.hpp
@@ -74,8 +74,8 @@ class basic_variant_tree : public basic_variant_tree_base<Ch>
typedef typename base::const_iterator const_iterator;
private:
- path_type m_root_path;
- const config::validator* m_schema_validator;
+ path_type m_root_path;
+ mutable const config::validator* m_schema_validator;
template <typename T>
@@ -285,8 +285,8 @@ class basic_variant_tree : public basic_variant_tree_base<Ch>
void root_path(const path_type& p) { m_root_path = p; }
/// Get schema validator
- const config::validator* validator() const { return m_schema_validator; }
- void validator(const config::validator* a) { m_schema_validator = a; }
+ const config::validator* validator() const { return m_schema_validator; }
+ void validator(const config::validator* a) const { m_schema_validator = a; }
base& to_base() { return static_cast<base&>(*this); }
const base& to_base() const { return static_cast<const base&>(*this); }
@@ -512,10 +512,15 @@ class basic_variant_tree : public basic_variant_tree_base<Ch>
}
/// Validate content of this tree against the custom validator
- void validate() const {
- if (!m_schema_validator)
+ /// @param a_schema if not NULL use this schema validator otherwise
+ /// use internal validator().
+ void validate(const config::validator* a_schema = NULL) const {
+ if (!a_schema && !m_schema_validator)
throw std::runtime_error("Unassigned validator!");
- m_schema_validator->validate(*this);
+ if (a_schema)
+ a_schema->validate(*this);
+ else
+ m_schema_validator->validate(*this);
}
/// For internal use

0 comments on commit 11dbd07

Please sign in to comment.