#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 */