Skip to content
Snippets Groups Projects
Commit 9675e5a4 authored by Adam Wardynski's avatar Adam Wardynski
Browse files

Class to hold collection of lexicons.

parent 380efc1e
Branches
No related merge requests found
......@@ -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
......
#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 */
#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
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment