From 148c3e25b35be03c5b7e52095d865a9924f0927e Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 11 Sep 2011 11:02:01 +0200 Subject: Add support for setting compiler::context value as container::any --- cutl/compiler/context.cxx | 27 ++++++++++++++++++++++++--- cutl/compiler/context.hxx | 9 +++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) (limited to 'cutl/compiler') 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 +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 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)); -- cgit v1.1