diff options
author | Jörg Frings-Fürst <jff@merkur> | 2014-05-18 16:08:14 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <jff@merkur> | 2014-05-18 16:08:14 +0200 |
commit | a15cf65c44d5c224169c32ef5495b68c758134b7 (patch) | |
tree | 3419f58fc8e1b315ba8171910ee044c5d467c162 /xsd/libxsd/xsd/cxx/tree/std-ostream-map.hxx |
Imported Upstream version 3.3.0.2upstream/3.3.0.2
Diffstat (limited to 'xsd/libxsd/xsd/cxx/tree/std-ostream-map.hxx')
-rw-r--r-- | xsd/libxsd/xsd/cxx/tree/std-ostream-map.hxx | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/xsd/libxsd/xsd/cxx/tree/std-ostream-map.hxx b/xsd/libxsd/xsd/cxx/tree/std-ostream-map.hxx new file mode 100644 index 0000000..28619a5 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/std-ostream-map.hxx @@ -0,0 +1,114 @@ +// file : xsd/cxx/tree/std-ostream-map.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 XSD_CXX_TREE_STD_OSTREAM_MAP_HXX +#define XSD_CXX_TREE_STD_OSTREAM_MAP_HXX + +#include <map> +#include <cstddef> // std::size_t +#include <ostream> +#include <typeinfo> + +#include <xsd/cxx/tree/elements.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C> + struct std_ostream_map + { + typedef std::type_info type_id; + typedef void (*inserter) (std::basic_ostream<C>&, const type&); + + std_ostream_map (); + + void + register_type (const type_id&, inserter, bool override = true); + + void + unregister_type (const type_id&); + + void + insert (std::basic_ostream<C>&, const type&); + + public: + inserter + 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<const type_id*, inserter, type_id_comparator> + type_map; + + type_map type_map_; + }; + + // + // + template<unsigned long id, typename C> + struct std_ostream_plate + { + static std_ostream_map<C>* map; + static std::size_t count; + + std_ostream_plate (); + ~std_ostream_plate (); + }; + + template<unsigned long id, typename C> + std_ostream_map<C>* std_ostream_plate<id, C>::map = 0; + + template<unsigned long id, typename C> + std::size_t std_ostream_plate<id, C>::count = 0; + + + // + // + template<unsigned long id, typename C> + inline std_ostream_map<C>& + std_ostream_map_instance () + { + return *std_ostream_plate<id, C>::map; + } + + // + // + template<typename C, typename T> + void + inserter_impl (std::basic_ostream<C>&, const type&); + + template<unsigned long id, typename C, typename T> + struct std_ostream_initializer + { + std_ostream_initializer (); + ~std_ostream_initializer (); + }; + } + } +} + +#include <xsd/cxx/tree/std-ostream-map.txx> + +#endif // XSD_CXX_TREE_STD_OSTREAM_MAP_HXX |