From cb4be50abb58ba95f952d37c42f324c3a6663155 Mon Sep 17 00:00:00 2001
From: Adam Wardynski <award@.(B-4.4.46a)>
Date: Wed, 17 Nov 2010 18:53:10 +0100
Subject: [PATCH] Adding var_repr static function to each Value. The function
 returns string representation of a variable of given Value type, using
 provided variable name.

---
 libwccl/values/bool.cpp     |  8 ++++++++
 libwccl/values/position.cpp |  7 +++++++
 libwccl/values/strset.cpp   | 11 +++++++++--
 libwccl/values/tset.cpp     |  7 +++++++
 libwccl/values/value.h      |  5 +++--
 5 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/libwccl/values/bool.cpp b/libwccl/values/bool.cpp
index eb8e2a8..f1d2531 100644
--- a/libwccl/values/bool.cpp
+++ b/libwccl/values/bool.cpp
@@ -1,7 +1,15 @@
 #include <libwccl/values/bool.h>
+#include <sstream>
 
 namespace Wccl {
 
 const char* Bool::type_name = "Bool";
 
+std::string Bool::var_repr(const std::string &var_name)
+{
+	std::stringstream ss;
+	ss << "$b" << var_name;
+	return ss.str();
+}
+
 } /* end ns Wccl */
diff --git a/libwccl/values/position.cpp b/libwccl/values/position.cpp
index 329c65a..074f7b3 100644
--- a/libwccl/values/position.cpp
+++ b/libwccl/values/position.cpp
@@ -18,4 +18,11 @@ std::string Position::to_raw_string() const
 	}
 }
 
+std::string Position::var_repr(const std::string &var_name)
+{
+	std::stringstream ss;
+	ss << "$" << var_name;
+	return ss.str();
+}
+
 } /* end ns Wccl */
diff --git a/libwccl/values/strset.cpp b/libwccl/values/strset.cpp
index 02489f4..133b233 100644
--- a/libwccl/values/strset.cpp
+++ b/libwccl/values/strset.cpp
@@ -31,8 +31,8 @@ bool StrSet::intersects(const StrSet &other) const {
 	//need to actually compute it to check if it's empty.
 	//Doing it like below sounds faster than, say, sorting
 	//the sets and using set_intersection.
-	//it's faster to iterate through the smaller set and check in
-	//the larger than it is to do the opposite, hence the &?: below
+	//It's faster to iterate through the smaller set and check in
+	//the larger than it is to do the opposite, hence the &?: below.
 	const set_t& smaller = size() < other.size() ? set_ : other.set_;
 	const set_t& bigger = size() < other.size() ? other.set_ : set_;
 	foreach (const UnicodeString& u, smaller) {
@@ -56,4 +56,11 @@ bool StrSet::is_subset_of(const StrSet &other) const
 	return true;
 }
 
+std::string StrSet::var_repr(const std::string &var_name)
+{
+	std::stringstream ss;
+	ss << "$s" << var_name;
+	return ss.str();
+}
+
 } /* end ns Wccl */
diff --git a/libwccl/values/tset.cpp b/libwccl/values/tset.cpp
index 8b1090e..01a8a0a 100644
--- a/libwccl/values/tset.cpp
+++ b/libwccl/values/tset.cpp
@@ -15,6 +15,13 @@ std::string TSet::to_string(const Corpus2::Tagset& tagset) const
 	return tagset.tag_to_symbol_string(tag_);
 }
 
+std::string TSet::var_repr(const std::string &var_name)
+{
+	std::stringstream ss;
+	ss << "$t" << var_name;
+	return ss.str();
+}
+
 void TSet::insert_symbol(const Corpus2::Tagset& tagset, const std::string& s)
 {
 	tag_.combine_with(tagset.parse_symbol(s));
diff --git a/libwccl/values/value.h b/libwccl/values/value.h
index c645651..e7cee0f 100644
--- a/libwccl/values/value.h
+++ b/libwccl/values/value.h
@@ -5,7 +5,8 @@
 
 #define WCCL_VALUE_PREAMBLE \
 static const char* type_name; \
-const char* get_type_name() const { return type_name; }
+const char* get_type_name() const { return type_name; } \
+static std::string var_repr(const std::string &var_name);
 
 
 namespace Wccl {
@@ -35,7 +36,7 @@ public:
 
 	/**
 	 * String representation of the Value that does not require a tagset,
-	 * might be incompleta and/or contain internal info.
+	 * might be incomplete and/or contain internal info.
 	 *
 	 * Prefer to_string(tagset).
 	 */
-- 
GitLab