added FieldP to values and styles, implemented reflection for IndexMap

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@36 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2006-10-19 18:44:27 +00:00
parent 46a6ed39dc
commit ff96f1522a
30 changed files with 290 additions and 122 deletions
+33 -3
View File
@@ -63,9 +63,11 @@ shared_ptr<Field> read_new<Field>(Reader& reader);
/// Style information needed to display a Value in a Field.
class Style {
public:
Style(const FieldP&);
virtual ~Style();
int z_index; ///< Stacking of values of this field, higher = on top
const FieldP fieldP; ///< Field this style is for, should have the right type!
int z_index; ///< Stacking of values of this field, higher = on top
Scriptable<double> left, top; ///< Position of this field
Scriptable<double> width, height; ///< Position of this field
Scriptable<bool> visible; ///< Is this field visible?
@@ -74,14 +76,20 @@ class Style {
DECLARE_REFLECTION_VIRTUAL();
};
void initObject(const FieldP&, StyleP&);
void init_object(const FieldP&, StyleP&);
inline const FieldP& get_key (const StyleP& s) { return s->fieldP; }
inline const String& get_key_name(const StyleP& s) { return s->fieldP->name; }
template <> StyleP read_new<Style>(Reader&);
// ----------------------------------------------------------------------------- : Value
/// A specific value 'in' a Field.
class Value {
public:
inline Value(const FieldP& field) : fieldP(field) {}
virtual ~Value();
const FieldP fieldP; ///< Field this value is for, should have the right type!
/// Convert this value to a string for use in tables
virtual String toString() const = 0;
@@ -90,7 +98,29 @@ class Value {
DECLARE_REFLECTION_VIRTUAL();
};
void initObject(const FieldP&, ValueP&);
void init_object(const FieldP&, ValueP&);
inline const FieldP& get_key (const ValueP& v) { return v->fieldP; }
inline const String& get_key_name(const ValueP& v) { return v->fieldP->name; }
template <> ValueP read_new<Value>(Reader&);
// ----------------------------------------------------------------------------- : Utilities
// implement newStyle and newValue
#define FIELD_TYPE(Type) \
StyleP Type ## Field::newStyle(const FieldP& thisP) const { \
assert(thisP.get() == this); \
return new_shared1<Type ## Style>(static_pointer_cast<Type ## Field>(thisP)); \
} \
ValueP Type ## Field::newValue(const FieldP& thisP) const { \
assert(thisP.get() == this); \
return new_shared1<Type ## Value>(static_pointer_cast<Type ## Field>(thisP)); \
}
// implement field() which returns a field with the right (derived) type
#define HAS_FIELD(Type) \
inline Type ## Field& field() const { \
return *static_cast<Type ## Field*>(fieldP.get()); \
}
// ----------------------------------------------------------------------------- : EOF
#endif