// file : xsd/cxx/tree/std-ostream-map.txx // author : Boris Kolpackov // copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #include #include namespace xsd { namespace cxx { namespace tree { // std_ostream_map // template std_ostream_map:: std_ostream_map () { // anyType and anySimpleType. // register_type ( typeid (type), &inserter_impl, false); typedef simple_type simple_type; register_type ( typeid (simple_type), &inserter_impl, false); // Strings // typedef string string; register_type ( typeid (string), &inserter_impl, false); typedef normalized_string normalized_string; register_type ( typeid (normalized_string), &inserter_impl, false); typedef token token; register_type ( typeid (token), &inserter_impl, false); typedef name name; register_type ( typeid (name), &inserter_impl, false); typedef nmtoken nmtoken; register_type ( typeid (nmtoken), &inserter_impl, false); typedef nmtokens nmtokens; register_type ( typeid (nmtokens), &inserter_impl, false); typedef ncname ncname; register_type ( typeid (ncname), &inserter_impl, false); typedef language language; register_type ( typeid (language), &inserter_impl, false); // ID/IDREF. // typedef id id; register_type ( typeid (id), &inserter_impl, false); typedef idref idref; register_type ( typeid (idref), &inserter_impl, false); typedef idrefs idrefs; register_type ( typeid (idrefs), &inserter_impl, false); // URI. // typedef uri uri; register_type ( typeid (uri), &inserter_impl, false); // Qualified name. // typedef qname qname; register_type ( typeid (qname), &inserter_impl, false); // Binary. // typedef base64_binary base64_binary; register_type ( typeid (base64_binary), &inserter_impl, false); typedef hex_binary hex_binary; register_type ( typeid (hex_binary), &inserter_impl, false); // Date/time. // typedef gday gday; register_type ( typeid (gday), &inserter_impl, false); typedef gmonth gmonth; register_type ( typeid (gmonth), &inserter_impl, false); typedef gyear gyear; register_type ( typeid (gyear), &inserter_impl, false); typedef gmonth_day gmonth_day; register_type ( typeid (gmonth_day), &inserter_impl, false); typedef gyear_month gyear_month; register_type ( typeid (gyear_month), &inserter_impl, false); typedef date date; register_type ( typeid (date), &inserter_impl, false); typedef time time; register_type ( typeid (time), &inserter_impl, false); typedef date_time date_time; register_type ( typeid (date_time), &inserter_impl, false); typedef duration duration; register_type ( typeid (duration), &inserter_impl, false); // Entity. // typedef entity entity; register_type ( typeid (entity), &inserter_impl, false); typedef entities entities; register_type ( typeid (entities), &inserter_impl, false); } template void std_ostream_map:: register_type (const type_id& tid, inserter i, bool replace) { if (replace || type_map_.find (&tid) == type_map_.end ()) type_map_[&tid] = i; } template void std_ostream_map:: unregister_type (const type_id& tid) { type_map_.erase (&tid); } template void std_ostream_map:: insert (std::basic_ostream& os, const type& x) { if (inserter i = find (typeid (x))) i (os, x); else throw no_type_info (std::basic_string (), std::basic_string ()); // @@ TODO } template typename std_ostream_map::inserter std_ostream_map:: find (const type_id& tid) const { typename type_map::const_iterator i (type_map_.find (&tid)); return i == type_map_.end () ? 0 : i->second; } // std_ostream_plate // template std_ostream_plate:: std_ostream_plate () { if (count == 0) map = new std_ostream_map; ++count; } template std_ostream_plate:: ~std_ostream_plate () { if (--count == 0) delete map; } // // template void inserter_impl (std::basic_ostream& os, const type& x) { os << static_cast (x); } // std_ostream_initializer // template std_ostream_initializer:: std_ostream_initializer () { std_ostream_map_instance ().register_type ( typeid (T), &inserter_impl); } template std_ostream_initializer:: ~std_ostream_initializer () { std_ostream_map_instance ().unregister_type (typeid (T)); } } } }