diff --git a/libwccl/CMakeLists.txt b/libwccl/CMakeLists.txt index fb2d134db1d2d533a0ff7f94ee8d51133ffb7b54..7d272225ef745d87af65480f8fa3498a77c59247 100644 --- a/libwccl/CMakeLists.txt +++ b/libwccl/CMakeLists.txt @@ -28,6 +28,7 @@ endif(WIN32) SET(libwccl_STAT_SRC exception.cpp lexicon/lexicon.cpp + lexicon/lexicons.cpp ops/formatters.cpp ops/functions/bool/iteration.cpp ops/functions/bool/iterations/atleast.cpp diff --git a/libwccl/lexicon/lexicons.cpp b/libwccl/lexicon/lexicons.cpp new file mode 100644 index 0000000000000000000000000000000000000000..836e2706777effff904bdfd5aa7ba2f5406f7635 --- /dev/null +++ b/libwccl/lexicon/lexicons.cpp @@ -0,0 +1,35 @@ +#include <libwccl/lexicon/lexicons.h> +#include <libwccl/exception.h> + +namespace Wccl { + +const Lexicon& Lexicons::get(const std::string& name) const +{ + map_t::const_iterator i = lexicons_.find(name); + if (i == lexicons_.end()) { + throw InvalidArgument("name", "No lexicon of given name: " + name); + } + return *i->second; +} + +boost::shared_ptr<const Lexicon> Lexicons::get_ptr(const std::string& name) const +{ + map_t::const_iterator i = lexicons_.find(name); + if (i == lexicons_.end()) { + throw InvalidArgument("name", "No lexicon of given name: " + name); + } + return i->second; +} + +void Lexicons::insert(const boost::shared_ptr<Lexicon>& lexicon) +{ + BOOST_ASSERT(lexicon); + if (has_lexicon(lexicon->name())) { + throw InvalidArgument( + "lexicon", + "Lexicon named \"" + lexicon->name() + "\" already added."); + } + lexicons_[lexicon->name()] = lexicon; +} + +} /* end ns Wccl */ diff --git a/libwccl/lexicon/lexicons.h b/libwccl/lexicon/lexicons.h new file mode 100644 index 0000000000000000000000000000000000000000..1fd0c5ff01b2975458de1a2ee69a4fcac4818dbf --- /dev/null +++ b/libwccl/lexicon/lexicons.h @@ -0,0 +1,35 @@ +#ifndef LIBWCCL_LEXICON_LEXICONS_H +#define LIBWCCL_LEXICON_LEXICONS_H + +#include <libwccl/lexicon/lexicon.h> +#include <boost/shared_ptr.hpp> + +namespace Wccl { + +class Lexicons : boost::noncopyable +{ +public: + typedef boost::unordered_map<std::string, boost::shared_ptr<Lexicon> > map_t; + + Lexicons() + : lexicons_() + { + } + + bool has_lexicon(const std::string& name) const { + return lexicons_.find(name) != lexicons_.end(); + } + + const Lexicon& get(const std::string& name) const; + + boost::shared_ptr<const Lexicon> get_ptr(const std::string& name) const; + + void insert(const boost::shared_ptr<Lexicon>& lexicon); + +private: + map_t lexicons_; +}; + +} /* end ns Wccl */ + +#endif // LIBWCCL_LEXICON_LEXICONS_H