Skip to content
Snippets Groups Projects
strset.h 1.55 KiB
Newer Older
ilor's avatar
ilor committed
#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;

ilor's avatar
ilor committed
	typedef set_t value_type;

ilor's avatar
ilor committed
	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;
	}

	const set_t& get_value() const {
		return contents();
	}

	void set_value(const set_t& set) {
		set_contents(set);
	}

ilor's avatar
ilor committed
	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();
	}

	/**
	 * @return true if each string from this set exists in the other set
	 *         (note that an empty set is a subset of anything)
	 */
	/**
	 * @return true if there is at least one common string between this set and
	 *         the other set (an empty set intersects with nothing)
	 */
	bool equals(const StrSet& other) const {
		return set_ == other.set_;
ilor's avatar
ilor committed
	/// Value override
	std::string to_raw_string() const;

private:
	set_t set_;
};

} /* end ns Wccl */

#endif // LIBWCCL_VALUES_STRSET_H