Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef TPROPERTY_INCLUDED
Toshihiro Shimizu 890ddd
#define TPROPERTY_INCLUDED
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tconvert.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef TNZCORE_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Toshihiro Shimizu 890ddd
#pragma warning(push)
Toshihiro Shimizu 890ddd
#pragma warning(disable : 4251)
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
class TRangeProperty;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
typedef TRangeProperty<int> TIntProperty;</int>
Toshihiro Shimizu 890ddd
typedef TRangeProperty<double> TDoubleProperty;</double>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TBoolProperty;
Toshihiro Shimizu 890ddd
class DVAPI TStringProperty;
Toshihiro Shimizu 890ddd
class DVAPI TEnumProperty;
Toshihiro Shimizu 890ddd
class DVAPI TDoublePairProperty;
Toshihiro Shimizu 890ddd
class DVAPI TIntPairProperty;
Toshihiro Shimizu 890ddd
class DVAPI TStyleIndexProperty;
Toshihiro Shimizu 890ddd
class DVAPI TPointerProperty;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TIStream;
Toshihiro Shimizu 890ddd
class TOStream;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TProperty
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	class Visitor
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	public:
Toshihiro Shimizu 890ddd
		virtual void visit(TDoubleProperty *p) = 0;
Toshihiro Shimizu 890ddd
		virtual void visit(TIntProperty *p) = 0;
Toshihiro Shimizu 890ddd
		virtual void visit(TBoolProperty *p) = 0;
Toshihiro Shimizu 890ddd
		virtual void visit(TStringProperty *p) = 0;
Toshihiro Shimizu 890ddd
		virtual void visit(TEnumProperty *p) = 0;
Toshihiro Shimizu 890ddd
		virtual void visit(TDoublePairProperty *p) = 0;
Toshihiro Shimizu 890ddd
		virtual void visit(TIntPairProperty *p) = 0;
Toshihiro Shimizu 890ddd
		virtual void visit(TStyleIndexProperty *p) = 0;
Toshihiro Shimizu 890ddd
		virtual void visit(TPointerProperty *p) = 0;
Toshihiro Shimizu 890ddd
		virtual ~Visitor() {}
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	class Listener
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	public:
Toshihiro Shimizu 890ddd
		virtual void onPropertyChanged() = 0;
Toshihiro Shimizu 890ddd
		virtual ~Listener() {}
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// eccezioni
Toshihiro Shimizu 890ddd
	class TypeError
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
	class RangeError
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
	TProperty(std::string name)
Toshihiro Shimizu 890ddd
		: m_name(name)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_qstringName = QString::fromStdString(name);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual ~TProperty() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual TProperty *clone() const = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Used only for translation in Qt
Toshihiro Shimizu 890ddd
	QString getQStringName() const { return m_qstringName; }
Toshihiro Shimizu 890ddd
	void setQStringName(const QString &str) { m_qstringName = str; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
	std::string getName() const { return m_name; }
Shinya Kitaoka 3bfa54
	virtual std::string getValueAsString() = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void accept(Visitor &v) = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void addListener(Listener *listener);
Toshihiro Shimizu 890ddd
	void removeListener(Listener *listener);
Toshihiro Shimizu 890ddd
	void notifyListeners() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
	std::string getId() const { return m_id; }
Shinya Kitaoka 3bfa54
	void setId(std::string id) { m_id = id; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 3bfa54
	std::string m_name;
Toshihiro Shimizu 890ddd
	QString m_qstringName;
Shinya Kitaoka 3bfa54
	std::string m_id;
Toshihiro Shimizu 890ddd
	std::vector<listener *=""> m_listeners;</listener>
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
class TRangeProperty : public TProperty
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	typedef std::pair<t, t=""> Range;</t,>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRangeProperty(
Shinya Kitaoka 3bfa54
		std::string name,
Toshihiro Shimizu 890ddd
		T minValue, T maxValue,
Toshihiro Shimizu 890ddd
		T value, bool isMaxRangeLimited = true)
Toshihiro Shimizu 890ddd
		: TProperty(name), m_range(minValue, maxValue), m_value(minValue), m_isMaxRangeLimited(isMaxRangeLimited)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		setValue(value);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TProperty *clone() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return new TRangeProperty<t>(*this);</t>
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	Range getRange() const { return m_range; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setValue(T v, bool cropEnabled = false)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (cropEnabled && m_isMaxRangeLimited)
Toshihiro Shimizu 890ddd
			v = tcrop(v, m_range.first, m_range.second);
Toshihiro Shimizu 890ddd
		if (cropEnabled && !m_isMaxRangeLimited)
Toshihiro Shimizu 890ddd
			v = v < m_range.first ? m_range.first : v;
Toshihiro Shimizu 890ddd
		if (v < m_range.first || (v > m_range.second && m_isMaxRangeLimited))
Toshihiro Shimizu 890ddd
			throw RangeError();
Toshihiro Shimizu 890ddd
		m_value = v;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	T getValue() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return m_value;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
	std::string getValueAsString()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return toString(m_value);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void accept(Visitor &v) { v.visit(this); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool isMaxRangeLimited() const { return m_isMaxRangeLimited; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	Range m_range;
Toshihiro Shimizu 890ddd
	T m_value;
Toshihiro Shimizu 890ddd
	bool m_isMaxRangeLimited;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Toshihiro Shimizu 890ddd
template class DVAPI TRangeProperty<int>;</int>
Toshihiro Shimizu 890ddd
template class DVAPI TRangeProperty<double>;</double>
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TDoublePairProperty : public TProperty
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	typedef std::pair<double, double=""> Range;</double,>
Toshihiro Shimizu 890ddd
	typedef std::pair<double, double=""> Value;</double,>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TDoublePairProperty(
Shinya Kitaoka 3bfa54
		std::string name,
Toshihiro Shimizu 890ddd
		double minValue, double maxValue,
Toshihiro Shimizu 890ddd
		double v0, double v1,
Toshihiro Shimizu 890ddd
		bool isMaxRangeLimited = true)
Toshihiro Shimizu 890ddd
		: TProperty(name), m_range(Range(minValue, maxValue)), m_isMaxRangeLimited(isMaxRangeLimited)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		setValue(Value(v0, v1));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TProperty *clone() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return new TDoublePairProperty(*this);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	Range getRange() const { return m_range; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool isMaxRangeLimited() const { return m_isMaxRangeLimited; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setValue(const Value &value)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (value.first < m_range.first || (m_isMaxRangeLimited && value.first > m_range.second) ||
Toshihiro Shimizu 890ddd
			value.second < m_range.first || (m_isMaxRangeLimited && value.second > m_range.second))
Toshihiro Shimizu 890ddd
			throw RangeError();
Toshihiro Shimizu 890ddd
		m_value = value;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	Value getValue() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return m_value;
Toshihiro Shimizu 890ddd
	}
Shinya Kitaoka 3bfa54
	std::string getValueAsString()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return toString(m_value.first) + "," + toString(m_value.second);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	void accept(Visitor &v) { v.visit(this); };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	Range m_range;
Toshihiro Shimizu 890ddd
	Value m_value;
Toshihiro Shimizu 890ddd
	bool m_isMaxRangeLimited;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TIntPairProperty : public TProperty
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	typedef std::pair<int, int=""> Range;</int,>
Toshihiro Shimizu 890ddd
	typedef std::pair<int, int=""> Value;</int,>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TIntPairProperty(
Shinya Kitaoka 3bfa54
		std::string name,
Toshihiro Shimizu 890ddd
		int minValue, int maxValue,
Toshihiro Shimizu 890ddd
		int v0, int v1,
Toshihiro Shimizu 890ddd
		bool isMaxRangeLimited = true)
Toshihiro Shimizu 890ddd
		: TProperty(name), m_range(minValue, maxValue), m_isMaxRangeLimited(isMaxRangeLimited)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		setValue(Value(v0, v1));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TProperty *clone() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return new TIntPairProperty(*this);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	Range getRange() const { return m_range; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool isMaxRangeLimited() const { return m_isMaxRangeLimited; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setValue(const Value &value)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (value.first < m_range.first || (m_isMaxRangeLimited && value.first > m_range.second) ||
Toshihiro Shimizu 890ddd
			value.second < m_range.first || (m_isMaxRangeLimited && value.second > m_range.second))
Toshihiro Shimizu 890ddd
			throw RangeError();
Toshihiro Shimizu 890ddd
		m_value = value;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	Value getValue() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return m_value;
Toshihiro Shimizu 890ddd
	}
Shinya Kitaoka 3bfa54
	std::string getValueAsString()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return toString(m_value.first) + "," + toString(m_value.second);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	void accept(Visitor &v) { v.visit(this); };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	Range m_range;
Toshihiro Shimizu 890ddd
	Value m_value;
Toshihiro Shimizu 890ddd
	bool m_isMaxRangeLimited;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TBoolProperty : public TProperty
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 3bfa54
	TBoolProperty(std::string name, bool value)
Toshihiro Shimizu 890ddd
		: TProperty(name), m_value(value)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TProperty *clone() const { return new TBoolProperty(*this); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setValue(bool v) { m_value = v; }
Toshihiro Shimizu 890ddd
	bool getValue() const { return m_value; }
Shinya Kitaoka 3bfa54
	std::string getValueAsString()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return toString(m_value);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	void accept(Visitor &v) { v.visit(this); };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	bool m_value;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TStringProperty : public TProperty
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 3bfa54
	TStringProperty(std::string name, std::wstring value)
Toshihiro Shimizu 890ddd
		: TProperty(name), m_value(value)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TProperty *clone() const { return new TStringProperty(*this); }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
	void setValue(std::wstring v) { m_value = v; }
Shinya Kitaoka 3bfa54
	std::wstring getValue() const { return m_value; }
Shinya Kitaoka 3bfa54
	std::string getValueAsString()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return toString(m_value);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	void accept(Visitor &v) { v.visit(this); };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 3bfa54
	std::wstring m_value;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TStyleIndexProperty : public TProperty
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 3bfa54
	TStyleIndexProperty(std::string name, std::wstring value)
Toshihiro Shimizu 890ddd
		: TProperty(name), m_value(value)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TProperty *clone() const { return new TStyleIndexProperty(*this); }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
	void setValue(std::wstring v) { m_value = v; }
Shinya Kitaoka 3bfa54
	std::wstring getValue() const { return m_value; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
	std::string getValueAsString()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return toString(m_value);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void accept(Visitor &v) { v.visit(this); };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 3bfa54
	std::wstring m_value;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TPointerProperty : public TProperty
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 3bfa54
	TPointerProperty(std::string name, void *value)
Toshihiro Shimizu 890ddd
		: TProperty(name), m_value(value)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TProperty *clone() const { return new TPointerProperty(*this); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setValue(void *v) { m_value = v; }
Toshihiro Shimizu 890ddd
	void *getValue() const { return m_value; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
	std::string getValueAsString()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return toString((unsigned long long)m_value);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void accept(Visitor &v) { v.visit(this); };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	void *m_value;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TEnumProperty : public TProperty
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 3bfa54
	typedef std::vector<std::wstring> Range;</std::wstring>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
	TEnumProperty(const std::string &name)
Toshihiro Shimizu 890ddd
		: TProperty(name), m_index(-1) {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
	TEnumProperty(const std::string &name, const Range &range, const std::wstring &v)
Toshihiro Shimizu 890ddd
		: TProperty(name), m_range(range), m_index(indexOf(v))
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_index < 0)
Toshihiro Shimizu 890ddd
			throw RangeError();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
	TEnumProperty(const std::string &name,
Toshihiro Shimizu 890ddd
				  Range::const_iterator i0, Range::const_iterator i1,
Shinya Kitaoka 3bfa54
					const std::wstring &v)
Toshihiro Shimizu 890ddd
		: TProperty(name), m_range(i0, i1), m_index(indexOf(v))
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_index < 0)
Toshihiro Shimizu 890ddd
			throw RangeError();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TProperty *clone() const { return new TEnumProperty(*this); }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
	int indexOf(const std::wstring &value)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		Range::const_iterator it = std::find(m_range.begin(), m_range.end(), value);
Toshihiro Shimizu 890ddd
		return (it == m_range.end()) ? -1 : it - m_range.begin();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
	bool isValue(const std::wstring &value)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		bool ret = std::find(m_range.begin(), m_range.end(), value) != m_range.end();
Toshihiro Shimizu 890ddd
		return ret;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
	void addValue(std::wstring value)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_index == -1)
Toshihiro Shimizu 890ddd
			m_index = 0;
Toshihiro Shimizu 890ddd
		m_range.push_back(value);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void deleteAllValues()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_range.clear();
Toshihiro Shimizu 890ddd
		m_index = -1;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setIndex(int index)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (index < 0 || index >= (int)m_range.size())
Toshihiro Shimizu 890ddd
			throw RangeError();
Toshihiro Shimizu 890ddd
		m_index = index;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
	void setValue(const std::wstring &value)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		int idx = indexOf(value);
Toshihiro Shimizu 890ddd
		if (idx < 0)
Toshihiro Shimizu 890ddd
			throw RangeError();
Toshihiro Shimizu 890ddd
		m_index = idx;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	const Range &getRange() const { return m_range; }
Shinya Kitaoka 3bfa54
	std::wstring getValue() const { return (m_index < 0) ? L"" : m_range[m_index]; }
Shinya Kitaoka 3bfa54
	std::string getValueAsString() { return toString(m_range[m_index]); }
Toshihiro Shimizu 890ddd
	int getIndex() const { return m_index; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void accept(Visitor &v) { v.visit(this); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	static void enableRangeSaving(bool on);
Toshihiro Shimizu 890ddd
	static bool isRangeSavingEnabled();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	Range m_range;
Toshihiro Shimizu 890ddd
	int m_index;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TPropertyGroup
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	typedef std::vector<std::pair<tproperty *,="" bool="">> PropertyVector;</std::pair<tproperty>
Shinya Kitaoka 3bfa54
	typedef std::map<std::string, *="" tproperty=""> PropertyTable;</std::string,>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// exception
Toshihiro Shimizu 890ddd
	class PropertyNotFoundError
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPropertyGroup();
Toshihiro Shimizu 890ddd
	virtual ~TPropertyGroup();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual TPropertyGroup *clone() const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//! get ownership
Toshihiro Shimizu 890ddd
	void add(TProperty *p);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//! don't get ownership
Toshihiro Shimizu 890ddd
	void bind(TProperty &p);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//! returns 0 if the property doesn't exist
Shinya Kitaoka 3bfa54
	TProperty *getProperty(std::string name);
Toshihiro Shimizu 890ddd
	TProperty *getProperty(int i) { return (i >= (int)m_properties.size()) ? 0 : m_properties[i].first; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setProperties(TPropertyGroup *g);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void accept(TProperty::Visitor &v);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getPropertyCount() const { return (int)m_properties.size(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void loadData(TIStream &is);
Toshihiro Shimizu 890ddd
	void saveData(TOStream &os) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void clear();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	PropertyTable m_table;
Toshihiro Shimizu 890ddd
	PropertyVector m_properties;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	// not implemented
Toshihiro Shimizu 890ddd
	TPropertyGroup(const TPropertyGroup &);
Toshihiro Shimizu 890ddd
	TPropertyGroup &operator=(const TPropertyGroup &);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Toshihiro Shimizu 890ddd
#pragma warning(pop)
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif