diff --git a/libwccl/CMakeLists.txt b/libwccl/CMakeLists.txt index 5ed26c712a614d56ed3d13ad962a7d64019c1adf..05392c1df5906af204878102176e5a80dd4b5637 100644 --- a/libwccl/CMakeLists.txt +++ b/libwccl/CMakeLists.txt @@ -17,6 +17,7 @@ SET(libwccl_STAT_SRC values/bool.cpp values/position.cpp values/positionref.cpp + values/strset.cpp values/value.cpp variables.cpp ) diff --git a/libwccl/values/strset.cpp b/libwccl/values/strset.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4823999e83064837b99714dc68a50795f8330be3 --- /dev/null +++ b/libwccl/values/strset.cpp @@ -0,0 +1,25 @@ +#include <libwccl/values/strset.h> +#include <libpwrutils/foreach.h> +#include <libpwrutils/util.h> +#include <sstream> + + +namespace Wccl { + +const char* StrSet::type_name = "StrSet"; + +std::string StrSet::to_raw_string() const +{ + std::stringstream ss; + ss << "{"; + bool comma = false; + foreach (const UnicodeString& u, set_) { + if (comma) { + ss << ","; + } + ss << '\"' << PwrNlp::to_utf8(u) << '\"'; //TODO escaping + } + return ss.str(); +} + +} /* end ns Wccl */ diff --git a/libwccl/values/strset.h b/libwccl/values/strset.h new file mode 100644 index 0000000000000000000000000000000000000000..a180c47ab3e8a72c884749d4b0e03b2b7f890e29 --- /dev/null +++ b/libwccl/values/strset.h @@ -0,0 +1,64 @@ +#ifndef LIBWCCL_VALUES_STRSET_H +#define LIBWCCL_VALUES_STRSET_H + +#include <libwccl/values/value.h> +#include <boost/unordered_set.hpp> +#include <libcorpus2/lexeme.h> // for unicodestring hash + +namespace Wccl { + +class StrSet : public Value +{ +public: + WCCL_VALUE_PREAMBLE + + typedef boost::unordered_set<UnicodeString> set_t; + + StrSet() + : set_() + { + } + + explicit StrSet(const set_t& s) + : set_(s) + { + } + + const set_t& contents() const { + return set_; + } + + set_t& contents() { + return set_; + } + + void set_contents(const set_t& set) { + set_ = set; + } + + void swap(StrSet& ss) { + ss.set_.swap(set_); + } + + void insert(const UnicodeString& u) { + set_.insert(u); + } + + void insert_utf8(const std::string& u) { + insert(UnicodeString::fromUTF8(u)); + } + + int size() const { + return set_.size(); + } + + /// Value override + std::string to_raw_string() const; + +private: + set_t set_; +}; + +} /* end ns Wccl */ + +#endif // LIBWCCL_VALUES_STRSET_H diff --git a/libwccl/variables.h b/libwccl/variables.h index ea77194746658e8dc06fadd7782bcb2e2399a9f4..5773541ab44fee29c19f842665795e3e643c3c36 100644 --- a/libwccl/variables.h +++ b/libwccl/variables.h @@ -5,6 +5,7 @@ #include <libwccl/exception.h> #include <libwccl/values/position.h> #include <libwccl/values/positionref.h> +#include <libwccl/values/strset.h> #include <iostream> #include <map> #include <string> @@ -84,11 +85,13 @@ class Variables : detail::Vmap<Value> , detail::Vmap<Bool> , detail::Vmap<Position> , detail::Vmap<PositionRef> + , detail::Vmap<StrSet> { public: /// Valid value types, should match the inheritance. /// the type Value must be first, order of other items is not important - typedef boost::mpl::list<Value, Bool, Position, PositionRef> types; + typedef boost::mpl::list<Value, + Bool, Position, PositionRef, StrSet> types; /// Constructor, creates an empty instance. Variables();