aboutsummaryrefslogtreecommitdiff
path: root/cutl/compiler/context.cxx
blob: 51311fc7f1bf5d529474b1a1d85632fdcd0aec3e (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
// file      : cutl/compiler/context.cxx
// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
// license   : MIT; see accompanying LICENSE file

#include <cutl/compiler/context.hxx>

using namespace std;

namespace cutl
{
  namespace compiler
  {
    void context::
    set (string const& key, container::any const& value)
    {
      using container::any;

      std::pair<map::iterator, bool> r (
        map_.insert (map::value_type (key, value)));

      any& x (r.first->second);

      if (!r.second)
      {
        if (value.type_info () != x.type_info ())
          throw typing ();

        x = value;
      }
    }

    void context::
    remove (string const& key)
    {
      map::iterator i (map_.find (key));

      if (i == map_.end ())
        throw no_entry ();

      map_.erase (i);
    }

    type_info const& context::
    type_info (string const& key) const
    {
      map::const_iterator i (map_.find (key));

      if (i == map_.end ())
        throw no_entry ();

      return i->second.type_info ();
    }
  }
}