aboutsummaryrefslogtreecommitdiff
path: root/cutl/compiler/context.hxx
blob: 4bae010e008ef1f372e22e93770f13b2bfeb7b08 (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
// file      : cutl/compiler/context.hxx
// author    : Boris Kolpackov <boris@codesynthesis.com>
// copyright : Copyright (c) 2009 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 <cutl/container/any.hxx>

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

    public:
      context () {}

    private:
      context (context const&);

      context&
      operator= (context const&);

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

      template <typename X>
      X&
      get (char const* key);

      template <typename X>
      X const&
      get (char const* key) const;

      template <typename X>
      X const&
      get (char const* key, X const& default_value) const;

      template <typename X>
      void
      set (char const* key, X const& value);

      void
      remove (char const* key);

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

      map map_;
    };
  }
}

#include <cutl/compiler/context.txx>

#endif // CUTL_COMPILER_CONTEXT_HXX