From 9675e5a4b23fc2e0ef715013e9c6d28a6fd08a60 Mon Sep 17 00:00:00 2001
From: Adam Wardynski <award@.(win7-laptop)>
Date: Fri, 29 Apr 2011 18:38:49 +0200
Subject: [PATCH] Class to hold collection of lexicons.

---
 libwccl/CMakeLists.txt       |  1 +
 libwccl/lexicon/lexicons.cpp | 35 +++++++++++++++++++++++++++++++++++
 libwccl/lexicon/lexicons.h   | 35 +++++++++++++++++++++++++++++++++++
 3 files changed, 71 insertions(+)
 create mode 100644 libwccl/lexicon/lexicons.cpp
 create mode 100644 libwccl/lexicon/lexicons.h

diff --git a/libwccl/CMakeLists.txt b/libwccl/CMakeLists.txt
index fb2d134..7d27222 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 0000000..836e270
--- /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 0000000..1fd0c5f
--- /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
-- 
GitLab