summaryrefslogtreecommitdiff
path: root/libcutl/cutl/compiler/context.hxx
blob: 2933e3605c2b32dac0c5edabdb1a11e3bad3ed79 (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// file      : cutl/compiler/context.hxx
// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
// license   : MIT; see accompanying LICENSE file

#ifndef CUTL_COMPILER_CONTEXT_HXX
#define CUTL_COMPILER_CONTEXT_HXX

#include <map>
#include <string>
#include <cstddef> // std::size_t
#include <typeinfo>

#include <cutl/exception.hxx>
#include <cutl/container/any.hxx>

#include <cutl/details/export.hxx>

namespace cutl
{
  namespace compiler
  {
    class LIBCUTL_EXPORT context
    {
    public:
      struct LIBCUTL_EXPORT no_entry: exception {};
      struct LIBCUTL_EXPORT typing: exception {};

    public:
      context () {}

      void
      swap (context& c)
      {
        map_.swap (c.map_);
      }

    private:
      context (context const&);

      context&
      operator= (context const&);

    public:
      std::size_t
      count (char const* key) const
      {
        return count (std::string (key));
      }

      std::size_t
      count (std::string const& key) const
      {
        return map_.count (key);
      }

      template <typename X>
      X&
      get (char const* key)
      {
        return get<X> (std::string (key));
      }

      template <typename X>
      X&
      get (std::string const& key);

      template <typename X>
      X const&
      get (char const* key) const
      {
        return get<X> (std::string (key));
      }

      template <typename X>
      X const&
      get (std::string const& key) const;

      template <typename X>
      X const&
      get (char const* key, X const& default_value) const
      {
        return get<X> (std::string (key), default_value);
      }

      template <typename X>
      X const&
      get (std::string const& key, X const& default_value) const;

      template <typename X>
      X&
      set (char const* key, X const& value)
      {
        return set<X> (std::string (key), value);
      }

      template <typename X>
      X&
      set (std::string const& key, X const& value);

      void
      set (char const* key, container::any const& value)
      {
        return set (std::string (key), value);
      }

      void
      set (std::string const& key, container::any const& value);

      void
      remove (char const* key)
      {
        remove (std::string (key));
      }

      void
      remove (std::string const& key);

      std::type_info const&
      type_info (char const* key) const
      {
        return type_info (std::string (key));
      }

      std::type_info const&
      type_info (std::string const& key) const;

    private:
      typedef std::map<std::string, container::any> map;

      map map_;
    };
  }
}

#include <cutl/compiler/context.txx>

#endif // CUTL_COMPILER_CONTEXT_HXX