blob: 42679278ae286bba56280ab55f86b97c778d4c64 (
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
|
// file : CCF/CompilerElements/Context.hpp
// author : Boris Kolpackov <boris@dre.vanderbilt.edu>
// cvs-id : $id$
#ifndef CCF_COMPILER_ELEMENTS_CONTEXT_HPP
#define CCF_COMPILER_ELEMENTS_CONTEXT_HPP
#include <map>
#include <string>
#include <Utility/Hetero/Container.hpp>
namespace CCF
{
namespace CompilerElements
{
class Context
{
public:
Context ()
{
}
public:
class NotFound {};
class Typing {};
template <typename T>
T const&
get (std::string key) const throw (NotFound, Typing)
{
Map::const_iterator i = map_.find (key);
if (i == map_.end ()) throw NotFound ();
try
{
return i->second. template value<T> ();
}
catch (Utility::Hetero::Typing const&)
{
throw Typing ();
}
}
template <typename T>
T const&
get (std::string key, T const& def) const throw (Typing)
{
Map::const_iterator i = map_.find (key);
if (i == map_.end ()) return def;
try
{
return i->second. template value<T> ();
}
catch (Utility::Hetero::Typing const&)
{
throw Typing ();
}
}
template <typename T>
void
set (std::string key, T const& value) throw (Typing)
{
try
{
if (!map_.insert (std::pair<std::string,
Utility::Hetero::Container>(key, value)).second)
{
Map::iterator i = map_.find (key);
i->second.template value <T> () = value;
}
}
catch (Utility::Hetero::Typing const&)
{
throw Typing ();
}
}
private:
typedef
std::map<std::string, Utility::Hetero::Container>
Map;
Map map_;
private:
// Copy semanic is not supported.
Context (Context const&) throw ();
Context& operator= (Context const&) throw ();
};
}
}
#endif // CCF_COMPILER_ELEMENTS_CONTEXT_HPP
|