From 3a20e3be713ec1180852cd198df6d06c423114ea Mon Sep 17 00:00:00 2001
From: ilor <kailoran@gmail.com>
Date: Sat, 30 Oct 2010 21:08:43 +0200
Subject: [PATCH] update Value, add simple Bool and Position classes

---
 libwccl/CMakeLists.txt |  2 ++
 libwccl/bool.cpp       |  7 +++++++
 libwccl/bool.h         | 37 +++++++++++++++++++++++++++++++++++++
 libwccl/position.cpp   | 12 ++++++++++++
 libwccl/position.h     | 37 +++++++++++++++++++++++++++++++++++++
 libwccl/value.cpp      |  2 ++
 libwccl/value.h        | 11 +++++++++++
 7 files changed, 108 insertions(+)
 create mode 100644 libwccl/bool.cpp
 create mode 100644 libwccl/bool.h
 create mode 100644 libwccl/position.cpp
 create mode 100644 libwccl/position.h

diff --git a/libwccl/CMakeLists.txt b/libwccl/CMakeLists.txt
index 7760bcc..e8fcba5 100644
--- a/libwccl/CMakeLists.txt
+++ b/libwccl/CMakeLists.txt
@@ -11,7 +11,9 @@ link_directories(${Boost_LIBRARY_DIRS})
 set(LIBS ${LIBS} ${Boost_LIBRARIES})
 
 SET(libwccl_STAT_SRC
+	bool.cpp
 	main.cpp
+	position.cpp
 	sentencecontext.cpp
 	value.cpp
 	variables.cpp
diff --git a/libwccl/bool.cpp b/libwccl/bool.cpp
new file mode 100644
index 0000000..ab84cd3
--- /dev/null
+++ b/libwccl/bool.cpp
@@ -0,0 +1,7 @@
+#include <libwccl/bool.h>
+
+namespace Wccl {
+
+const char* Bool::type_name = "Bool";
+
+} /* end ns Wccl */
diff --git a/libwccl/bool.h b/libwccl/bool.h
new file mode 100644
index 0000000..d1b75b5
--- /dev/null
+++ b/libwccl/bool.h
@@ -0,0 +1,37 @@
+#ifndef LIBWCCL_BOOL_H
+#define LIBWCCL_BOOL_H
+
+#include <libwccl/value.h>
+
+namespace Wccl {
+
+class Bool : public Value
+{
+public:
+	WCCL_VALUE_PREAMBLE
+
+	explicit Bool(bool v = false)
+		: val_(v)
+	{
+	}
+
+	bool get_value() const {
+		return val_;
+	}
+
+	void set_value(bool v) {
+		val_ = v;
+	}
+
+	/// Value override
+	std::string to_raw_string() const {
+		return val_ ? "true" : "false";
+	}
+
+private:
+	bool val_;
+};
+
+} /* end ns Wccl */
+
+#endif // LIBWCCL_BOOL_H
diff --git a/libwccl/position.cpp b/libwccl/position.cpp
new file mode 100644
index 0000000..f2acf82
--- /dev/null
+++ b/libwccl/position.cpp
@@ -0,0 +1,12 @@
+#include <libwccl/position.h>
+#include <boost/lexical_cast.hpp>
+namespace Wccl {
+
+const char* Position::type_name = "Position";
+
+std::string Position::to_raw_string() const
+{
+	return boost::lexical_cast<std::string>(val_);
+}
+
+} /* end ns Wccl */
diff --git a/libwccl/position.h b/libwccl/position.h
new file mode 100644
index 0000000..ea0b06a
--- /dev/null
+++ b/libwccl/position.h
@@ -0,0 +1,37 @@
+#ifndef LIBWCCL_POSITION_H
+#define LIBWCCL_POSITION_H
+
+#include <libwccl/value.h>
+#include <cstdlib>
+
+namespace Wccl {
+
+class Position : public Value
+{
+public:
+	WCCL_VALUE_PREAMBLE
+
+	explicit Position(int v = 0)
+		: val_(v)
+	{
+	}
+
+	int get_value() const {
+		return val_;
+	}
+
+	void set_value(int v) {
+		val_ = v;
+	}
+
+	/// Value override
+	std::string to_raw_string() const;
+
+private:
+	int val_;
+};
+
+
+} /* end ns Wccl */
+
+#endif // LIBWCCL_POSITION_H
diff --git a/libwccl/value.cpp b/libwccl/value.cpp
index f46f947..89c49ac 100644
--- a/libwccl/value.cpp
+++ b/libwccl/value.cpp
@@ -2,4 +2,6 @@
 
 namespace Wccl {
 
+const char* Value::type_name = "Value";
+
 } /* end ns Wccl */
diff --git a/libwccl/value.h b/libwccl/value.h
index c761d78..4e9e54a 100644
--- a/libwccl/value.h
+++ b/libwccl/value.h
@@ -3,6 +3,11 @@
 
 #include <libcorpus2/tagset.h>
 
+#define WCCL_VALUE_PREAMBLE \
+static const char* type_name; \
+const char* get_type_name() const { return type_name; }
+
+
 namespace Wccl {
 
 /**
@@ -11,6 +16,12 @@ namespace Wccl {
 class Value
 {
 public:
+	static const char* type_name;
+
+	virtual const char* get_type_name() const {
+		return type_name;
+	}
+
 	virtual ~Value() {}
 
 	/**
-- 
GitLab