From 1896d36996ab48ed7271e855d7e32b4e61f64896 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 23 Apr 2012 16:48:00 +0200 Subject: Polymorphic inheritance support --- odb/polymorphic-map.txx | 72 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 odb/polymorphic-map.txx (limited to 'odb/polymorphic-map.txx') diff --git a/odb/polymorphic-map.txx b/odb/polymorphic-map.txx new file mode 100644 index 0000000..7b1b81a --- /dev/null +++ b/odb/polymorphic-map.txx @@ -0,0 +1,72 @@ +// file : odb/polymorphic-map.txx +// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#include // no_type_info + +namespace odb +{ + // + // polymorphic_map + // + + template + const typename polymorphic_map::info_type& polymorphic_map:: + find (const std::type_info& t) const + { + typename type_map::const_iterator i (type_map_.find (&t)); + + if (i != type_map_.end ()) + return *i->second; + else + throw no_type_info (); + } + + template + const typename polymorphic_map::info_type& polymorphic_map:: + find (const discriminator_type& d) const + { + typename discriminator_map::const_iterator i ( + discriminator_map_.find (&d)); + + if (i != discriminator_map_.end ()) + return *i->second; + else + throw no_type_info (); + } + + // + // polymorphic_entry_impl + // + + template + void polymorphic_entry_impl:: + insert (const info_type& i) + { + polymorphic_map*& pm (root_traits::map); + + if (pm == 0) + pm = new polymorphic_map; + else + pm->ref_count_++; + + pm->type_map_[&i.type] = &i; + pm->discriminator_map_[&i.discriminator] = &i; + } + + template + void polymorphic_entry_impl:: + erase (const info_type& i) + { + polymorphic_map*& pm (root_traits::map); + + pm->discriminator_map_.erase (&i.discriminator); + pm->type_map_.erase (&i.type); + + if (--pm->ref_count_ == 0) + { + delete pm; + pm = 0; + } + } +} -- cgit v1.1