Skip to content
Snippets Groups Projects
value.h 2.55 KiB
Newer Older
#ifndef LIBWCCL_VALUES_VALUE_H
#define LIBWCCL_VALUES_VALUE_H
#define WCCL_VALUE_PREAMBLE \
static const char* type_name; \
const char* get_type_name() const { return type_name; } \
static std::string var_repr(const std::string &var_name); \
std::string make_var_repr(const std::string &var_name) const { \
	return var_repr(var_name); \
}
namespace Wccl {

/**
 * Abstract base class for WCCL value types
 *
 * Value subtypes should use the WCCL_VALUE_PREAMBLE macro in the beginning
 * of their public: section and define the relevant static data members
 * and functions in the respective cpp file.
 *
 * Value subtypes, but not Value itself, should have a value_type typedef
 * and a const value_type& get_value() const member function defined
 * for interoperability with templates and convenience functions.
 *
 * Values should be default-constructible with a documented default state.
	static const char* type_name;

	virtual const char* get_type_name() const {
		return type_name;
	}

	virtual std::string make_var_repr(const std::string&) const = 0;

	/**
	 * String representation function, in general, a tagset is required,
	 * but some classes might not need that, so by default just forward
	 * to to_raw_string();
	 */
	virtual std::string to_string(const Corpus2::Tagset& /*tagset*/) const {
		return to_raw_string();
	}

	/**
	 * Unicode variant of to_string
	 */
ilor's avatar
ilor committed
	virtual UnicodeString to_string_u(const Corpus2::Tagset& tagset) const {
		return UnicodeString::fromUTF8(to_string(tagset));
	/**
	 * String representation of the Value that does not require a tagset,
	 * might be incomplete and/or contain internal info.
	 *
	 * Prefer to_string(tagset).
	 */
	virtual std::string to_raw_string() const = 0;

	/**
	 * Unicode variant of to_raw_string
	 */
	virtual UnicodeString to_raw_string_u() const {
		return UnicodeString::fromUTF8(to_raw_string());
	}

	/**
	  * Compact string representation: sets are represented as hyphen-separated
	  * strings (sorted) with no brackets. The representation is suitable for
	  * generating compact output where some degree of ambiguity is allowed
	  * (note that type can't be unambiguously inferred from such strings).
	  */
	virtual std::string to_compact_string(const Corpus2::Tagset& /* tagset */)
			const {
		return to_raw_string();
	}

	virtual UnicodeString to_compact_string_u(const Corpus2::Tagset& tagset)
			const {
		return UnicodeString::fromUTF8(to_compact_string(tagset));
	}

protected:
	Value() {}
};

} /* end ns Wccl */

#endif // LIBWCCL_VALUE_H