Skip to content
Snippets Groups Projects
Commit 29a28efd authored by ilor's avatar ilor
Browse files

simple strset impl.

parent b367ef94
Branches
No related merge requests found
...@@ -17,6 +17,7 @@ SET(libwccl_STAT_SRC ...@@ -17,6 +17,7 @@ SET(libwccl_STAT_SRC
values/bool.cpp values/bool.cpp
values/position.cpp values/position.cpp
values/positionref.cpp values/positionref.cpp
values/strset.cpp
values/value.cpp values/value.cpp
variables.cpp variables.cpp
) )
......
#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 */
#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
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <libwccl/exception.h> #include <libwccl/exception.h>
#include <libwccl/values/position.h> #include <libwccl/values/position.h>
#include <libwccl/values/positionref.h> #include <libwccl/values/positionref.h>
#include <libwccl/values/strset.h>
#include <iostream> #include <iostream>
#include <map> #include <map>
#include <string> #include <string>
...@@ -84,11 +85,13 @@ class Variables : detail::Vmap<Value> ...@@ -84,11 +85,13 @@ class Variables : detail::Vmap<Value>
, detail::Vmap<Bool> , detail::Vmap<Bool>
, detail::Vmap<Position> , detail::Vmap<Position>
, detail::Vmap<PositionRef> , detail::Vmap<PositionRef>
, detail::Vmap<StrSet>
{ {
public: public:
/// Valid value types, should match the inheritance. /// Valid value types, should match the inheritance.
/// the type Value must be first, order of other items is not important /// 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. /// Constructor, creates an empty instance.
Variables(); Variables();
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment