aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-09-11 11:02:01 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-09-11 11:02:01 +0200
commit148c3e25b35be03c5b7e52095d865a9924f0927e (patch)
tree3c4444ab6de56565c2589745fe936336478b4417
parent3e0ec6220c1bcc32f45ffd26c08b99af556a8101 (diff)
Add support for setting compiler::context value as container::any
-rw-r--r--cutl/compiler/context.cxx27
-rw-r--r--cutl/compiler/context.hxx9
2 files changed, 33 insertions, 3 deletions
diff --git a/cutl/compiler/context.cxx b/cutl/compiler/context.cxx
index 9623588..468923b 100644
--- a/cutl/compiler/context.cxx
+++ b/cutl/compiler/context.cxx
@@ -5,12 +5,33 @@
#include <cutl/compiler/context.hxx>
+using namespace std;
+
namespace cutl
{
namespace compiler
{
void context::
- remove (std::string const& key)
+ 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));
@@ -20,8 +41,8 @@ namespace cutl
map_.erase (i);
}
- std::type_info const& context::
- type_info (std::string const& key) const
+ type_info const& context::
+ type_info (string const& key) const
{
map::const_iterator i (map_.find (key));
diff --git a/cutl/compiler/context.hxx b/cutl/compiler/context.hxx
index 6a861e4..586fa6d 100644
--- a/cutl/compiler/context.hxx
+++ b/cutl/compiler/context.hxx
@@ -99,6 +99,15 @@ namespace cutl
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));