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/tree/comparison-map.hxx | 109 +++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 libxsd/xsd/cxx/tree/comparison-map.hxx (limited to 'libxsd/xsd/cxx/tree/comparison-map.hxx') diff --git a/libxsd/xsd/cxx/tree/comparison-map.hxx b/libxsd/xsd/cxx/tree/comparison-map.hxx new file mode 100644 index 0000000..f8461a0 --- /dev/null +++ b/libxsd/xsd/cxx/tree/comparison-map.hxx @@ -0,0 +1,109 @@ +// file : xsd/cxx/tree/comparison-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_TREE_COMPARISON_MAP_HXX +#define XSD_CXX_TREE_COMPARISON_MAP_HXX + +#include +#include // std::size_t +#include + +#include + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template + struct comparison_map + { + typedef std::type_info type_id; + typedef bool (*comparator) (const type&, const type&); + + comparison_map (); + + void + register_type (const type_id&, comparator, bool override = true); + + bool + compare (const type&, const type&); + + public: + comparator + find (const type_id&) const; + + private: + struct type_id_comparator + { + bool + operator() (const type_id* x, const type_id* y) const + { + // XL C++ on AIX has buggy type_info::before() in that + // it returns true for two different type_info objects + // that happened to be for the same type. + // +#if defined(__xlC__) && defined(_AIX) + return *x != *y && x->before (*y); +#else + return x->before (*y); +#endif + } + }; + + typedef + std::map + type_map; + + type_map type_map_; + }; + + // + // + template + struct comparison_plate + { + static comparison_map* map; + static std::size_t count; + + comparison_plate (); + ~comparison_plate (); + }; + + template + comparison_map* comparison_plate::map = 0; + + template + std::size_t comparison_plate::count = 0; + + + // + // + template + inline comparison_map& + comparison_map_instance () + { + return *comparison_plate::map; + } + + // + // + template + bool + comparator_impl (const type&, const type&); + + template + struct comparison_initializer + { + comparison_initializer (); + }; + } + } +} + +#include + +#endif // XSD_CXX_TREE_COMPARISON_MAP_HXX -- cgit v1.1