// file : xsd/cxx/tree/std-ostream-map.hxx // 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 #include // std::size_t #include #include #include namespace xsd { namespace cxx { namespace tree { template struct std_ostream_map { typedef std::type_info type_id; typedef void (*inserter) (std::basic_ostream&, const type&); std_ostream_map (); void register_type (const type_id&, inserter, bool replace = true); void unregister_type (const type_id&); void insert (std::basic_ostream&, 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 type_map; type_map type_map_; }; // // template struct std_ostream_plate { static std_ostream_map* map; static std::size_t count; std_ostream_plate (); ~std_ostream_plate (); }; template std_ostream_map* std_ostream_plate::map = 0; template std::size_t std_ostream_plate::count = 0; // // template inline std_ostream_map& std_ostream_map_instance () { return *std_ostream_plate::map; } // // template void inserter_impl (std::basic_ostream&, const type&); template struct std_ostream_initializer { std_ostream_initializer (); ~std_ostream_initializer (); }; } } } #include #endif // XSD_CXX_TREE_STD_OSTREAM_MAP_HXX