summaryrefslogtreecommitdiff
path: root/libcult/cult/rtti/type-info.cxx
blob: 5bc4040d4c5d21abe6066cecbbc912d43827279f (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
// file      : cult/rtti/type-info.cxx
// author    : Boris Kolpackov <boris@kolpackov.net>
// copyright : Copyright (c) 2005-2010 Boris Kolpackov
// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file

#include <cult/rtti/type-info.hxx>

#include <cult/mm/static-ptr.hxx>

#include <cult/containers/map.hxx>

namespace Cult
{
  namespace RTTI
  {
    Access const Access::private_ (Access::private__);
    Access const Access::protected_ (Access::protected__);
    Access const Access::public_ (Access::public__);

    typedef
    Containers::Map<TypeId, TypeInfo>
    TypeInfoMap;

    static MM::StaticPtr<TypeInfoMap> map_;

    TypeInfo const&
    lookup (TypeId const& type_id)
    {
      TypeInfoMap::ConstIterator i (map_->find (type_id));

      if (i == map_->end ()) throw NoInfo ();

      return i->second;
    }

    Void
    insert (TypeInfo const& type_info)
    {
      map_->insert (TypeInfoMap::Pair (type_info.type_id (), type_info));
    }
  }
}