diff options
Diffstat (limited to 'libxsde/xsde/cxx/parser')
-rw-r--r-- | libxsde/xsde/cxx/parser/context.hxx | 3 | ||||
-rw-r--r-- | libxsde/xsde/cxx/parser/context.ixx | 7 | ||||
-rw-r--r-- | libxsde/xsde/cxx/parser/non-validating/parser.cxx | 12 | ||||
-rw-r--r-- | libxsde/xsde/cxx/parser/substitution-map-callback.hxx | 29 | ||||
-rw-r--r-- | libxsde/xsde/cxx/parser/substitution-map.cxx | 47 | ||||
-rw-r--r-- | libxsde/xsde/cxx/parser/substitution-map.hxx | 13 | ||||
-rw-r--r-- | libxsde/xsde/cxx/parser/substitution-map.ixx | 26 | ||||
-rw-r--r-- | libxsde/xsde/cxx/parser/validating/inheritance-map.cxx | 5 | ||||
-rw-r--r-- | libxsde/xsde/cxx/parser/validating/inheritance-map.hxx | 1 |
9 files changed, 121 insertions, 22 deletions
diff --git a/libxsde/xsde/cxx/parser/context.hxx b/libxsde/xsde/cxx/parser/context.hxx index 6019f34..34ded3e 100644 --- a/libxsde/xsde/cxx/parser/context.hxx +++ b/libxsde/xsde/cxx/parser/context.hxx @@ -140,6 +140,9 @@ namespace xsde public: void + start_wildcard_content (); + + void reset (XML_Parser); void diff --git a/libxsde/xsde/cxx/parser/context.ixx b/libxsde/xsde/cxx/parser/context.ixx index b3828f5..5e38ae2 100644 --- a/libxsde/xsde/cxx/parser/context.ixx +++ b/libxsde/xsde/cxx/parser/context.ixx @@ -47,6 +47,13 @@ namespace xsde } inline void context:: + start_wildcard_content () + { + current_.any_ = true; + current_.depth_++; + } + + inline void context:: reset (XML_Parser parser) { xml_parser_ = parser; diff --git a/libxsde/xsde/cxx/parser/non-validating/parser.cxx b/libxsde/xsde/cxx/parser/non-validating/parser.cxx index aec43e0..1bd20a5 100644 --- a/libxsde/xsde/cxx/parser/non-validating/parser.cxx +++ b/libxsde/xsde/cxx/parser/non-validating/parser.cxx @@ -195,11 +195,7 @@ namespace xsde { if (!_start_element_impl (ns, name, type)) { - context& c = _context (); - - c.current_.any_ = true; - c.current_.depth_++; - + _context ().start_wildcard_content (); _start_any_element (ns, name, type); } } @@ -210,11 +206,7 @@ namespace xsde { if (!_start_element_impl (ns, name)) { - context& c = _context (); - - c.current_.any_ = true; - c.current_.depth_++; - + _context ().start_wildcard_content (); _start_any_element (ns, name); } } diff --git a/libxsde/xsde/cxx/parser/substitution-map-callback.hxx b/libxsde/xsde/cxx/parser/substitution-map-callback.hxx new file mode 100644 index 0000000..97d22c9 --- /dev/null +++ b/libxsde/xsde/cxx/parser/substitution-map-callback.hxx @@ -0,0 +1,29 @@ +// file : xsde/cxx/parser/substitution-map-callback.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_SUBSTITUTION_MAP_CALLBACK_HXX +#define XSDE_CXX_PARSER_SUBSTITUTION_MAP_CALLBACK_HXX + +#include <xsde/cxx/ro-string.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + void + parser_smap_callback ( + bool (*callback) ( + const ro_string& root_ns, + const ro_string& root_name, + const ro_string& member_ns, + const ro_string& member_name, + const char*& type)); + } + } +} + +#endif // XSDE_CXX_PARSER_SUBSTITUTION_MAP_CALLBACK_HXX diff --git a/libxsde/xsde/cxx/parser/substitution-map.cxx b/libxsde/xsde/cxx/parser/substitution-map.cxx index 5cbe4a1..d58ac84 100644 --- a/libxsde/xsde/cxx/parser/substitution-map.cxx +++ b/libxsde/xsde/cxx/parser/substitution-map.cxx @@ -5,7 +5,7 @@ #include <xsde/cxx/config.hxx> -#include <string.h> // strlen, strcmp, strncmp +#include <string.h> // strlen, strcmp, strncmp, strchr #ifndef XSDE_EXCEPTIONS # include <assert.h> // assert @@ -17,6 +17,7 @@ #endif #include <xsde/cxx/parser/substitution-map.hxx> +#include <xsde/cxx/parser/substitution-map-callback.hxx> #include <xsde/cxx/parser/substitution-map-load.hxx> namespace xsde @@ -47,6 +48,22 @@ namespace xsde *type = v->type_; } + // Call the callback. + // + if (!r && callback_ != 0) + { + const char* t; + const char* p = strchr (root, ' '); + + ro_string rname (p ? root : 0, p ? p - root : 0); + ro_string rns (p ? p + 1 : root); + + r = callback_ (rns, rname, ns, name, t); + + if (r && type != 0 && *type == 0) + *type = t; + } + return r; } @@ -78,6 +95,20 @@ namespace xsde *type = v->type_; } + // Call the callback. + // + if (!r && callback_ != 0) + { + const char* t; + ro_string rns (root_ns); + ro_string rname (root_name); + + r = callback_ (rns, rname, ns, name, t); + + if (r && type != 0 && *type == 0) + *type = t; + } + return r; } @@ -249,7 +280,21 @@ namespace xsde #endif } + // Callback. // + void + parser_smap_callback ( + bool (*callback) ( + const ro_string& root_ns, + const ro_string& root_name, + const ro_string& member_ns, + const ro_string& member_name, + const char*& type)) + { + substitution_map_instance ().callback (callback); + } + + // Load. // size_t parser_smap_elements () diff --git a/libxsde/xsde/cxx/parser/substitution-map.hxx b/libxsde/xsde/cxx/parser/substitution-map.hxx index a6df80f..1e50c0e 100644 --- a/libxsde/xsde/cxx/parser/substitution-map.hxx +++ b/libxsde/xsde/cxx/parser/substitution-map.hxx @@ -27,6 +27,16 @@ namespace xsde const char* root, const char* type); + typedef bool (*callback_func) ( + const ro_string& root_ns, + const ro_string& root_name, + const ro_string& member_ns, + const ro_string& member_name, + const char*& type); + + void + callback (callback_func); + // Check and have the type set if found. // bool @@ -81,6 +91,9 @@ namespace xsde const value* find_ (const ro_string& member_ns, const ro_string& member_name) const; + + private: + callback_func callback_; }; diff --git a/libxsde/xsde/cxx/parser/substitution-map.ixx b/libxsde/xsde/cxx/parser/substitution-map.ixx index ddd0b4d..995da4e 100644 --- a/libxsde/xsde/cxx/parser/substitution-map.ixx +++ b/libxsde/xsde/cxx/parser/substitution-map.ixx @@ -11,7 +11,7 @@ namespace xsde { inline substitution_map:: substitution_map (size_t buckets) - : hashmap (buckets, sizeof (value)) + : hashmap (buckets, sizeof (value)), callback_ (0) { } @@ -26,6 +26,12 @@ namespace xsde hashmap::insert (member, &v); } + inline void substitution_map:: + callback (callback_func c) + { + callback_ = c; + } + inline bool substitution_map:: check (const ro_string& member_ns, const ro_string& member_name, @@ -33,9 +39,9 @@ namespace xsde const char*& type) const { - return empty () - ? false - : check_ (member_ns, member_name, root, &type); + return !empty () || callback_ != 0 + ? check_ (member_ns, member_name, root, &type) + : false; } inline bool substitution_map:: @@ -45,9 +51,9 @@ namespace xsde const char* root_name, const char*& type) const { - return empty () - ? false - : check_ (member_ns, member_name, root_ns, root_name, &type); + return !empty () || callback_ != 0 + ? check_ (member_ns, member_name, root_ns, root_name, &type) + : false; } inline bool substitution_map:: @@ -56,9 +62,9 @@ namespace xsde const char* root) const { - return empty () - ? false - : check_ (member_ns, member_name, root, 0); + return !empty () || callback_ != 0 + ? check_ (member_ns, member_name, root, 0) + : false; } inline substitution_map& diff --git a/libxsde/xsde/cxx/parser/validating/inheritance-map.cxx b/libxsde/xsde/cxx/parser/validating/inheritance-map.cxx index f23e841..c46ac1f 100644 --- a/libxsde/xsde/cxx/parser/validating/inheritance-map.cxx +++ b/libxsde/xsde/cxx/parser/validating/inheritance-map.cxx @@ -33,6 +33,11 @@ namespace xsde bool inheritance_map:: check (const char* derived, const char* base) const { + // Check for the special match-anything marker. + // + if (derived[0] == '*') + return true; + if (strcmp (derived, base) == 0) return true; diff --git a/libxsde/xsde/cxx/parser/validating/inheritance-map.hxx b/libxsde/xsde/cxx/parser/validating/inheritance-map.hxx index ba8335e..1462fb2 100644 --- a/libxsde/xsde/cxx/parser/validating/inheritance-map.hxx +++ b/libxsde/xsde/cxx/parser/validating/inheritance-map.hxx @@ -60,4 +60,3 @@ namespace xsde #include <xsde/cxx/parser/validating/inheritance-map.ixx> #endif // XSDE_CXX_PARSER_VALIDATING_INHERITANCE_MAP_HXX - |