From f0510d2f90467de8e8f260b47d79a9baaf9bef17 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 17 Sep 2009 07:15:29 +0200 Subject: Start tracking XSD with git --- libxsd/xsd/cxx/parser/substitution-map.hxx | 230 +++++++++++++++++++++++++++++ 1 file changed, 230 insertions(+) create mode 100644 libxsd/xsd/cxx/parser/substitution-map.hxx (limited to 'libxsd/xsd/cxx/parser/substitution-map.hxx') diff --git a/libxsd/xsd/cxx/parser/substitution-map.hxx b/libxsd/xsd/cxx/parser/substitution-map.hxx new file mode 100644 index 0000000..60c0ec8 --- /dev/null +++ b/libxsd/xsd/cxx/parser/substitution-map.hxx @@ -0,0 +1,230 @@ +// file : xsd/cxx/parser/substitution-map.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_PARSER_SUBSTITUTION_MAP_HXX +#define XSD_CXX_PARSER_SUBSTITUTION_MAP_HXX + +#include +#include // std::size_t + +#include + +namespace xsd +{ + namespace cxx + { + namespace parser + { + template + struct substitution_map_key + { + substitution_map_key (const C* ns, const C* name) + : ns_ (ns), name_ (name) + { + } + + substitution_map_key (const ro_string& ns, + const ro_string& name) + : ns_ (ns.data (), ns.size ()), + name_ (name.data (), name.size ()) + { + } + + substitution_map_key (const substitution_map_key& x) + : ns_ (x.ns_.data (), x.ns_.size ()), + name_ (x.name_.data (), x.name_.size ()) + { + } + + private: + substitution_map_key& + operator= (const substitution_map_key&); + + public: + const ro_string& + ns () const + { + return ns_; + } + + const ro_string& + name () const + { + return name_; + } + + private: + const ro_string ns_; + const ro_string name_; + }; + + template + inline bool + operator< (const substitution_map_key& x, + const substitution_map_key& y) + { + int r (x.name ().compare (y.name ())); + return r < 0 || (r == 0 && x.ns () < y.ns ()); + } + + template + struct substitution_map_value + { + substitution_map_value (const C* ns, const C* name, const C* type) + : ns_ (ns), name_ (name), type_ (type) + { + } + + substitution_map_value (const substitution_map_value& x) + : ns_ (x.ns_.data (), x.ns_.size ()), + name_ (x.name_.data (), x.name_.size ()), + type_ (x.type_.data (), x.type_.size ()) + { + } + + substitution_map_value& + operator= (const substitution_map_value& x) + { + if (this != &x) + { + ns_.assign (x.ns_.data (), x.ns_.size ()); + name_.assign (x.name_.data (), x.name_.size ()); + type_.assign (x.type_.data (), x.type_.size ()); + } + + return *this; + } + + public: + const ro_string& + ns () const + { + return ns_; + } + + const ro_string& + name () const + { + return name_; + } + + const ro_string& + type () const + { + return type_; + } + + private: + ro_string ns_; + ro_string name_; + ro_string type_; + }; + + template + struct substitution_map + { + void + insert (const C* member_ns, + const C* member_name, + const C* root_ns, + const C* root_name, + const C* member_type) + { + key k (member_ns, member_name); + value v (root_ns, root_name, member_type); + map_.insert (std::pair (k, v)); + } + + // Check and get the type set if found. + // + bool + check (const ro_string& ns, + const ro_string& name, + const C* root_ns, + const C* root_name, + const ro_string*& type) const + { + + return map_.empty () + ? false + : check_ (ns, name, root_ns, root_name, &type); + } + + // Check but don't care about the type. + // + bool + check (const ro_string& ns, + const ro_string& name, + const C* root_ns, + const C* root_name) const + { + + return map_.empty () + ? false + : check_ (ns, name, root_ns, root_name, 0); + } + + private: + bool + check_ (const ro_string& ns, + const ro_string& name, + const C* root_ns, + const C* root_name, + const ro_string** type) const; + + private: + typedef substitution_map_key key; + typedef substitution_map_value value; + typedef std::map map; + + map map_; + }; + + + // Translation unit initializer. + // + template + struct substitution_map_init + { + static substitution_map* map; + static std::size_t count; + + substitution_map_init (); + ~substitution_map_init (); + }; + + template + substitution_map* substitution_map_init::map = 0; + + template + std::size_t substitution_map_init::count = 0; + + template + inline substitution_map& + substitution_map_instance () + { + return *substitution_map_init::map; + } + + + // Map entry initializer. + // + template + struct substitution_map_entry + { + substitution_map_entry (const C* member_ns, + const C* member_name, + const C* root_ns, + const C* root_name, + const C* member_type); + }; + } + } +} + +#include + +#endif // XSD_CXX_PARSER_SUBSTITUTION_MAP_HXX + -- cgit v1.1