aboutsummaryrefslogtreecommitdiff
path: root/cutl/compiler/type-info.hxx
blob: f9700673c7c7ca9b0e428eb73b1e14d94878a502 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// file      : cutl/compiler/type-info.hxx
// author    : Boris Kolpackov <boris@codesynthesis.com>
// copyright : Copyright (c) 2009 Code Synthesis Tools CC
// license   : MIT; see accompanying LICENSE file

#ifndef CUTL_COMPILER_TYPE_INFO_HXX
#define CUTL_COMPILER_TYPE_INFO_HXX

#include <map>
#include <vector>
#include <typeinfo> // std::type_info

#include <cutl/static-ptr.hxx>
#include <cutl/compiler/type-id.hxx>

namespace cutl
{
  namespace compiler
  {
    //
    //
    class type_info;
    typedef type_info type_info_t;


    //
    //
    class base_info
    {
    public:
      base_info (type_id const&);

    public:
      type_info_t const&
      type_info () const;

    private:
      type_id type_id_;
      mutable type_info_t const* type_info_;
    };

    typedef base_info base_info_t;


    //
    //
    class type_info
    {
      typedef std::vector<base_info> bases;

    public:
      typedef
      bases::const_iterator
      base_iterator;

    public:
      type_info (type_id_t const&);

      type_id_t
      type_id () const;

      base_iterator
      begin_base () const;

      base_iterator
      end_base () const;

      void
      add_base (type_id_t const&);

    private:
      type_id_t type_id_;
      bases bases_;
    };


    //
    //
    class no_type_info {};

    type_info const&
    lookup (type_id const&);

    type_info const&
    lookup (std::type_info const&);

    template <typename X>
    type_info const&
    lookup (X const volatile&);

    template<typename X>
    type_info const&
    lookup ();

    void
    insert (type_info const&);

    namespace bits
    {
      struct default_type_info_id {};
      typedef std::map<type_id, type_info> type_info_map;
      static static_ptr<type_info_map, default_type_info_id> type_info_map_;
    }
  }
}

#include <cutl/compiler/type-info.ixx>

#endif // CUTL_COMPILER_TYPE_INFO_HXX