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

Adding var_repr static function to each Value.

The function returns string representation of a variable of given Value type, using provided variable name.
parent 753a9d37
No related branches found
No related tags found
No related merge requests found
#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 */
......@@ -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 */
......@@ -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 */
......@@ -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));
......
......@@ -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).
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment