diff options
author | jai <jai@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2007-01-29 21:15:18 +0000 |
---|---|---|
committer | jai <jai@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2007-01-29 21:15:18 +0000 |
commit | b71531b42b3325fd6079a7039aae8641262c8adf (patch) | |
tree | a5b9aa16924c541fcb424ee9460b1ac7f5a89352 /modules/CIAO/CCF/CCF/CompilerElements/Context.hpp | |
parent | a0f67cc97c0050d907145e312135b60c0125e56e (diff) | |
download | ATCD-b71531b42b3325fd6079a7039aae8641262c8adf.tar.gz |
branching/taggingDS-main
Diffstat (limited to 'modules/CIAO/CCF/CCF/CompilerElements/Context.hpp')
-rw-r--r-- | modules/CIAO/CCF/CCF/CompilerElements/Context.hpp | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/modules/CIAO/CCF/CCF/CompilerElements/Context.hpp b/modules/CIAO/CCF/CCF/CompilerElements/Context.hpp new file mode 100644 index 00000000000..fe799e32b48 --- /dev/null +++ b/modules/CIAO/CCF/CCF/CompilerElements/Context.hpp @@ -0,0 +1,112 @@ +// 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 + { + typedef + std::map<std::string, Utility::Hetero::Container> + Map; + + public: + Context () + { + } + + public: + class NotFound {}; + class Typing {}; + + Map::size_type + count (char const* key) const throw () + { + return map_.count (key); + } + + template <typename T> + 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<T> (); + } + catch (Utility::Hetero::Typing const&) + { + throw Typing (); + } + + } + + template <typename T> + 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<T> (); + } + catch (Utility::Hetero::Typing const&) + { + throw Typing (); + } + } + + template <typename T> + void + set (char const* 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 (); + } + } + + 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 |