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