summaryrefslogtreecommitdiff
path: root/libxsd/xsd/cxx/parser/validating/inheritance-map.txx
blob: 2490c077f3dacdadefaaf01a407ea59e7f66aea1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// file      : xsd/cxx/parser/validating/inheritance-map.txx
// copyright : Copyright (c) 2005-2017 Code Synthesis Tools CC
// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file

namespace xsd
{
  namespace cxx
  {
    namespace parser
    {
      namespace validating
      {
        template <typename C>
        bool inheritance_map<C>::
        check (const C* derived, const ro_string<C>& base) const
        {
          if (base == derived)
            return true;

          typename map::const_iterator i (map_.find (derived));

          if (i != map_.end ())
          {
            if (base == i->second)
              return true;
            else
              return check (i->second, base);
          }

          return false;
        }

        // inheritance_map_init
        //
        template<typename C>
        inheritance_map_init<C>::
        inheritance_map_init ()
        {
          if (count == 0)
            map = new inheritance_map<C>;

          ++count;
        }

        template<typename C>
        inheritance_map_init<C>::
        ~inheritance_map_init ()
        {
          if (--count == 0)
            delete map;
        }

        // inheritance_map_entry
        //
        template<typename C>
        inheritance_map_entry<C>::
        inheritance_map_entry (const C* derived, const C* base)
            : derived_ (derived)
        {
          inheritance_map_instance<C> ().insert (derived, base);
        }

        template<typename C>
        inheritance_map_entry<C>::
        ~inheritance_map_entry ()
        {
          inheritance_map_instance<C> ().erase (derived_);
        }
      }
    }
  }
}