diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2012-04-23 16:48:00 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2012-04-23 16:48:00 +0200 |
commit | 1896d36996ab48ed7271e855d7e32b4e61f64896 (patch) | |
tree | 6d085eb0349d23bc26fe101b2451235939f17d40 /odb/polymorphic-map.txx | |
parent | c2be6303f97e470960ee77805128c46d3ea5c102 (diff) |
Polymorphic inheritance support
Diffstat (limited to 'odb/polymorphic-map.txx')
-rw-r--r-- | odb/polymorphic-map.txx | 72 |
1 files changed, 72 insertions, 0 deletions
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 <odb/exceptions.hxx> // no_type_info + +namespace odb +{ + // + // polymorphic_map + // + + template <typename R> + const typename polymorphic_map<R>::info_type& polymorphic_map<R>:: + 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 <typename R> + const typename polymorphic_map<R>::info_type& polymorphic_map<R>:: + 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 <typename R> + void polymorphic_entry_impl<R>:: + insert (const info_type& i) + { + polymorphic_map<root_type>*& pm (root_traits::map); + + if (pm == 0) + pm = new polymorphic_map<root_type>; + else + pm->ref_count_++; + + pm->type_map_[&i.type] = &i; + pm->discriminator_map_[&i.discriminator] = &i; + } + + template <typename R> + void polymorphic_entry_impl<R>:: + erase (const info_type& i) + { + polymorphic_map<root_type>*& 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; + } + } +} |