Commit 2e870711 authored by twanvl's avatar twanvl

Added Alignment, Defaultable and Scriptable types, needed some reflection tweaks for the last two.

parent db72df28
......@@ -20,7 +20,7 @@ Field::Field()
, card_list_column (-1)
, card_list_width (100)
, card_list_allow (true)
// , card_list_align (ALIGN_LEFT)
, card_list_align (ALIGN_LEFT)
, tab_index (0)
{}
......@@ -38,7 +38,7 @@ IMPLEMENT_REFLECTION(Field) {
REFLECT(card_list_column);
REFLECT(card_list_width);
REFLECT(card_list_allow);
// REFLECT(card_list_align);
REFLECT(card_list_align);
REFLECT(tab_index);
}
......
......@@ -11,6 +11,7 @@
#include <util/prec.hpp>
#include <util/reflect.hpp>
#include <util/alignment.hpp>
DECLARE_POINTER_TYPE(Field);
DECLARE_POINTER_TYPE(Style);
......@@ -35,9 +36,9 @@ class Field {
UInt card_list_width; ///< Width of the card list column (pixels).
bool card_list_allow; ///< Is this field allowed to appear in the card list.
String card_list_name; ///< Alternate name to use in card list.
// Alignment card_list_align; ///< Alignment of the card list colummn.
Alignment card_list_align; ///< Alignment of the card list colummn.
int tab_index; ///< Tab index in editor
// Vector<DependendScript> dependendScripts; // scripts that depend on values of this field
// vector<Dependency> dependentScripts; // scripts that depend on values of this field
/// Creates a new Value corresponding to this Field
/** thisP is a smart pointer to this */
......
......@@ -7,6 +7,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <data/field/text.hpp>
#include <script/script.hpp>
// ----------------------------------------------------------------------------- : TextField
......@@ -37,8 +38,8 @@ String TextField::typeName() const {
IMPLEMENT_REFLECTION(TextField) {
REFLECT_BASE(Field);
REFLECT(multi_line);
// REFLECT(script);
// REFLECT_N("default", default_script);
REFLECT(script);
REFLECT_N("default", default_script);
REFLECT(move_cursor_with_sort);
REFLECT(default_name);
}
......@@ -61,4 +62,5 @@ ValueP TextValue::clone() const {
IMPLEMENT_REFLECTION(TextValue) {
REFLECT_BASE(Value);
REFLECT_NAMELESS(value);
}
......@@ -10,7 +10,9 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <util/defaultable.hpp>
#include <data/field.hpp>
#include <script/scriptable.hpp>
// ----------------------------------------------------------------------------- : TextField
......@@ -19,8 +21,8 @@ class TextField : public Field {
public:
TextField();
// Script script;
// Script default_script;
OptionalScript script;
OptionalScript default_script;
bool multi_line; ///< Are newlines allowed in the text?
bool move_cursor_with_sort; ///< When the text is reordered by a script should the cursor position be updated?
String default_name; ///< Name of "default" value
......@@ -43,7 +45,7 @@ class TextStyle : public Style {
// SymbolFontInfo symbol_font; ///< Symbol font for symbols in the text
bool always_symbol; ///< Should everything be drawn as symbols?
bool allow_formatting; ///< Is formating (bold/italic/..) allowed?
// Alignment alignment; ///< Alignment inside the box
Alignment alignment; ///< Alignment inside the box
int angle; ///< Angle of the text inside the box
int padding_left, padding_left_min; ///< Padding
int padding_right, padding_right_min; ///< Padding
......@@ -66,9 +68,9 @@ class TextStyle : public Style {
/// The Value in a TextField
class TextValue : public Value {
public:
virtual ValueP clone() const;
Defaultable<String> value; ///< The text of this value
String value;
virtual ValueP clone() const;
private:
DECLARE_REFLECTION();
};
......
......@@ -9,6 +9,7 @@
#include <data/game.hpp>
#include <data/field.hpp>
#include <util/io/package_manager.hpp>
#include <script/script.hpp>
#include <script/value.hpp>
// ----------------------------------------------------------------------------- : Game
......@@ -27,7 +28,7 @@ IMPLEMENT_REFLECTION(Game) {
// ioMseVersion(io, fileName, fileVersion);
REFLECT(full_name);
REFLECT_N("icon", icon_filename);
// REFLECT(init_script);
REFLECT(init_script);
REFLECT(set_fields);
REFLECT(card_fields);
// REFLECT_N("keyword parameter type", keyword_params);
......
......@@ -11,6 +11,7 @@
#include <util/prec.hpp>
#include <util/io/package.hpp>
#include <script/scriptable.hpp>
DECLARE_POINTER_TYPE(Field);
DECLARE_POINTER_TYPE(Game);
......@@ -19,10 +20,11 @@ DECLARE_POINTER_TYPE(Game);
class Game : public Packaged {
public:
String full_name;
String icon_filename;
vector<FieldP> set_fields;
vector<FieldP> card_fields;
String full_name; ///< Name of this game for menus etc.
String icon_filename; ///< Filename of icon to use in NewWindow
OptionalScript init_script; ///< Script of variables available to other scripts in this game
vector<FieldP> set_fields; ///< Fields for set information
vector<FieldP> card_fields; ///< Fields on each card
/// Loads the game with a particular name, for example "magic"
static GameP byName(const String& name);
......
......@@ -37,8 +37,8 @@ bool MSE::OnInit() {
wxInitAllImageHandlers();
initFileFormats();
settings.read();
Window* wnd = new SymbolWindow(nullptr);
//Window* wnd = new SetWindow(nullptr, new_shared1<Set>(Game::byName(_("magic"))));
//Window* wnd = new SymbolWindow(nullptr);
Window* wnd = new SetWindow(nullptr, new_shared1<Set>(Game::byName(_("magic"))));
wnd->Show();
return true;
}
......
......@@ -688,24 +688,6 @@
<Filter
Name="util"
Filter="">
<File
RelativePath=".\util\action_stack.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
</FileConfiguration>
<FileConfiguration
Name="Release Unicode|Win32">
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
</FileConfiguration>
</File>
<File
RelativePath=".\util\action_stack.hpp">
</File>
<File
RelativePath=".\util\dynamic_arg.hpp">
</File>
......@@ -718,15 +700,9 @@
<File
RelativePath=".\util\for_each.hpp">
</File>
<File
RelativePath=".\util\index_map.hpp">
</File>
<File
RelativePath=".\util\prec.hpp">
</File>
<File
RelativePath=".\util\real_point.hpp">
</File>
<File
RelativePath=".\util\reflect.hpp">
</File>
......@@ -757,9 +733,6 @@
<File
RelativePath=".\util\string.hpp">
</File>
<File
RelativePath=".\util\vector2d.hpp">
</File>
<File
RelativePath=".\util\version.hpp">
</File>
......@@ -836,6 +809,46 @@
RelativePath=".\util\io\writer.hpp">
</File>
</Filter>
<Filter
Name="types"
Filter="">
<File
RelativePath=".\util\action_stack.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
</FileConfiguration>
<FileConfiguration
Name="Release Unicode|Win32">
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
</FileConfiguration>
</File>
<File
RelativePath=".\util\action_stack.hpp">
</File>
<File
RelativePath=".\util\alignment.cpp">
</File>
<File
RelativePath=".\util\alignment.hpp">
</File>
<File
RelativePath=".\util\defaultable.hpp">
</File>
<File
RelativePath=".\util\index_map.hpp">
</File>
<File
RelativePath=".\util\real_point.hpp">
</File>
<File
RelativePath=".\util\vector2d.hpp">
</File>
</Filter>
</Filter>
<Filter
Name="gfx"
......@@ -937,6 +950,12 @@
<File
RelativePath=".\script\script.hpp">
</File>
<File
RelativePath=".\script\scriptable.cpp">
</File>
<File
RelativePath=".\script\scriptable.hpp">
</File>
<File
RelativePath=".\script\value.cpp">
</File>
......
......@@ -242,7 +242,7 @@ ScriptValueP Context::dependencies(const Dependency& dep, const Script& script)
// Get a variable (almost as normal)
case I_GET_VAR: {
ScriptValueP value = variables[i.data].value;
if (!value) value = scriptNil; // no errors here
if (!value) value = script_nil; // no errors here
stack.push_back(value);
break;
}
......
......@@ -283,9 +283,9 @@ void parseExpr(TokenIterator& input, Script& script, Precedence minPrec) {
if (minPrec <= PREC_UNARY && token == _("not")) {
parseOper(input, script, PREC_UNARY, I_UNARY, I_NOT); // unary not
} else if (token == _("true")) {
script.addInstruction(I_PUSH_CONST, scriptTrue); // boolean constant : true
script.addInstruction(I_PUSH_CONST, script_true); // boolean constant : true
} else if (token == _("false")) {
script.addInstruction(I_PUSH_CONST, scriptFalse); // boolean constant : false
script.addInstruction(I_PUSH_CONST, script_false); // boolean constant : false
} else if (token == _("if")) {
// if AAA then BBB else CCC
unsigned int jmpElse, jmpEnd;
......@@ -300,7 +300,7 @@ void parseExpr(TokenIterator& input, Script& script, Precedence minPrec) {
if (input.read() == _("else")) { // else
parseOper(input, script, PREC_SET); // CCC
} else {
script.addInstruction(I_PUSH_CONST, scriptNil);
script.addInstruction(I_PUSH_CONST, script_nil);
}
script.comeFrom(jmpEnd); // lbl_end:
} else if (token == _("for")) {
......@@ -315,7 +315,7 @@ void parseExpr(TokenIterator& input, Script& script, Precedence minPrec) {
expectToken(input, _("in")); // in
parseOper(input, script, PREC_SET); // BBB
script.addInstruction(I_UNARY, I_ITERATOR_C); // iterator_collection
script.addInstruction(I_PUSH_CONST, scriptNil); // push nil
script.addInstruction(I_PUSH_CONST, script_nil); // push nil
lblStart = script.getLabel(); // lbl_start:
script.addInstruction(I_LOOP, 0xFFFF); // loop
expectToken(input, _("do")); // do
......@@ -333,7 +333,7 @@ void parseExpr(TokenIterator& input, Script& script, Precedence minPrec) {
expectToken(input, _("to")); // to
parseOper(input, script, PREC_SET); // CCC
script.addInstruction(I_BINARY, I_ITERATOR_R); // iterator_range
script.addInstruction(I_PUSH_CONST, scriptNil); // push nil
script.addInstruction(I_PUSH_CONST, script_nil); // push nil
lblStart = script.getLabel(); // lbl_start:
script.addInstruction(I_LOOP, 0xFFFF); // loop
expectToken(input, _("do")); // do
......
......@@ -12,7 +12,7 @@
#include <util/prec.hpp>
#include <script/value.hpp>
DECLARE_POINTER_TYPE(Script);
DECLARE_INTRUSIVE_POINTER_TYPE(Script);
// ----------------------------------------------------------------------------- : Instructions
......
......@@ -25,7 +25,7 @@ ScriptValueP ScriptValue::next() { throw InternalError(_("Can't co
ScriptValueP ScriptValue::makeIterator() const { throw ScriptError( _("Can't convert from ")+typeName()+_(" to collection")); }
void ScriptValue::signalDependent(Context&, const Dependency&, const String& name) {}
ScriptValueP ScriptValue::dependencies( Context&, const Dependency&) const { return scriptNil; }
ScriptValueP ScriptValue::dependencies( Context&, const Dependency&) const { return script_nil; }
// ----------------------------------------------------------------------------- : Iterators
......@@ -81,8 +81,8 @@ ScriptValueP toScript(int v) {
}
// use integers to represent true/false
ScriptValueP scriptTrue = toScript((int)true);
ScriptValueP scriptFalse = toScript((int)false);
ScriptValueP script_true = toScript((int)true);
ScriptValueP script_false = toScript((int)false);
// ----------------------------------------------------------------------------- : Doubles
......@@ -165,10 +165,11 @@ class ScriptNil : public ScriptValue {
virtual operator String() const { return wxEmptyString; }
virtual operator double() const { return 0.0; }
virtual operator int() const { return 0; }
virtual ScriptValueP eval(Context&) const { return script_nil; } // nil() == nil
};
/// The preallocated nil value
ScriptValueP scriptNil(new ScriptNil);
ScriptValueP script_nil(new ScriptNil);
// ----------------------------------------------------------------------------- : EOF
......@@ -28,9 +28,7 @@ class Dependency;
// ----------------------------------------------------------------------------- : ScriptValue
//DECLARE_POINTER_TYPE(ScriptValue);
class ScriptValue;
typedef boost::intrusive_ptr<ScriptValue> ScriptValueP;
DECLARE_INTRUSIVE_POINTER_TYPE(ScriptValue);
enum ScriptType
{ SCRIPT_NIL
......@@ -104,9 +102,9 @@ inline void intrusive_ptr_release(ScriptValue* p) {
}
}
extern ScriptValueP scriptNil; ///< The preallocated nil value
extern ScriptValueP scriptTrue; ///< The preallocated true value
extern ScriptValueP scriptFalse; ///< The preallocated false value
extern ScriptValueP script_nil; ///< The preallocated nil value
extern ScriptValueP script_true; ///< The preallocated true value
extern ScriptValueP script_false; ///< The preallocated false value
// ----------------------------------------------------------------------------- : Iterators
......@@ -191,7 +189,7 @@ ScriptValueP toScript(int v);
ScriptValueP toScript(double v);
ScriptValueP toScript(const String& v);
ScriptValueP toScript(const Color& v);
inline ScriptValueP toScript(bool v) { return v ? scriptTrue : scriptFalse; }
inline ScriptValueP toScript(bool v) { return v ? script_true : script_false; }
template <typename T>
inline ScriptValueP toScript(const vector<T>* v) { return new_intrusive1<ScriptCollection<vector<T> > >(v); }
template <typename T>
......
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
// ----------------------------------------------------------------------------- : Includes
#include <util/alignment.hpp>
#include <util/reflect.hpp>
// ----------------------------------------------------------------------------- : Alignment
/// Convert a String to an Alignment
Alignment fromString(const String& str) {
int al = 0;
return static_cast<Alignment>(al);
}
/// Convert an Alignment to a String
String toString(Alignment align) {
String ret;
// vertical
if (align & ALIGN_TOP) ret += _(" top");
if (align & ALIGN_MIDDLE) ret += _(" middle");
if (align & ALIGN_BOTTOM) ret += _(" bottom");
// horizontal
if (align & ALIGN_LEFT) ret += _(" left");
if (align & ALIGN_LEFT) ret += _(" center");
if (align & ALIGN_LEFT) ret += _(" right");
if (align & ALIGN_LEFT) ret += _(" justify");
if (align & ALIGN_LEFT) ret += _(" justify-words");
// modifier
if (align & ALIGN_JUSTIFY_OVERFLOW) ret += _(" shrink-overflow");
if (align & ALIGN_STRETCH) ret += _(" stretch");
return ret.substr(1);
}
// we need custom io, because there can be both a horizontal and a vertical component
template <> void Reader::handle(Alignment& align) {
align = fromString(value);
}
template <> void Writer::handle(const Alignment& align) {
handle(toString(align));
}
template <> void GetMember::store(const Alignment& align) {
store(toString(align));
}
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
#ifndef HEADER_UTIL_ALIGNMENT
#define HEADER_UTIL_ALIGNMENT
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <util/real_point.hpp>
// ----------------------------------------------------------------------------- : Alignment
// Alignment in a textbox, specifies both horizontal and vertical alignment
enum Alignment
// horizontal
{ ALIGN_LEFT = 0x01
, ALIGN_CENTER = 0x02
, ALIGN_RIGHT = 0x04
, ALIGN_JUSTIFY = 0x08
, ALIGN_JUSTIFY_WORDS = 0x10
, ALIGN_HORIZONTAL = ALIGN_LEFT | ALIGN_CENTER | ALIGN_RIGHT | ALIGN_JUSTIFY | ALIGN_JUSTIFY_WORDS
// vertical
, ALIGN_TOP = 0x100
, ALIGN_MIDDLE = 0x200
, ALIGN_BOTTOM = 0x400
, ALIGN_VERTICAL = ALIGN_TOP | ALIGN_MIDDLE | ALIGN_BOTTOM
// modifiers
, ALIGN_JUSTIFY_OVERFLOW = 0x1000
, ALIGN_STRETCH = 0x2000
// common combinations
, ALIGN_TOP_LEFT = ALIGN_TOP | ALIGN_LEFT
};
/// How much should an object with obj_width be moved to be aligned in a box with box_width?
double align_delta_x(Alignment align, double box_width, double obj_width);
/// How much should an object with obj_height be moved to be aligned in a box with box_height?
double align_delta_t(Alignment align, double box_height, double obj_height);
/// Align a rectangle inside another rectangle
/** returns the topleft coordinates of the inner rectangle after alignment
*/
RealPoint align_in_rect(Alignment align, const RealSize& to_align, const RealRect& outer);
// ----------------------------------------------------------------------------- : EOF
#endif
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
#ifndef HEADER_UTIL_DEFAULTABLE
#define HEADER_UTIL_DEFAULTABLE
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <util/reflect.hpp>
// ----------------------------------------------------------------------------- : Defaultable
/// A value that can also be in a 'default' state.
/** TODO: Defaultable is automatically also Aged
*/
template <typename T>
class Defaultable {
public:
inline Defaultable() : is_default(true) {}
inline Defaultable(const T& v) : value(v), is_default(false) {}
/// Assigning a value takes this object out of the default state
inline void assign(const T& new_value) {
value = new_value;
is_default = false;
}
/// Get access to the value
inline const T& operator () () const { return value; }
/// Is this value in the default state?
inline bool isDefault() const { return is_default; }
private:
/// Is this value in the default state?
bool is_default;
/// The value
T value;
friend class Reader;
friend class Writer;
};
// we need some custom io, because the behaviour is different for each of Reader/Writer/GetMember
template <typename T>
void Reader::handle(Defaultable<T>& def) {
def.is_default = false;
handle(def.value);
}
template <typename T>
void Writer::handle(const Defaultable<T>& def) {
if (!def.isDefault()) {
handle(def());
}
}
template <typename T>
void GetMember::handle(const Defaultable<T>& def) {
store(def());
}
// ----------------------------------------------------------------------------- : EOF
#endif
......@@ -9,6 +9,7 @@
#include <util/io/get_member.hpp>
#include <util/vector2d.hpp>
#include <script/value.hpp>
#include <script/script.hpp>
// ----------------------------------------------------------------------------- : GetMember
......@@ -16,12 +17,16 @@ GetMember::GetMember(const String& name)
: targetName(name)
{}
void GetMember::store(const String& v) { value = toScript(v); }
void GetMember::store(const int v) { value = toScript(v); }
void GetMember::store(const unsigned int v) { value = toScript((int)v); }
void GetMember::store(const double v) { value = toScript(v); }
void GetMember::store(const bool v) { value = toScript(v); }
template <> void GetMember::store(const String& v) { value = toScript(v); }
//template <> void GetMember::store(const Char* const& v) { value = toScript(v); }
template <> void GetMember::store(const int& v) { value = toScript(v); }
template <> void GetMember::store(const unsigned int& v) { value = toScript((int)v); }
template <> void GetMember::store(const double& v) { value = toScript(v); }
template <> void GetMember::store(const bool& v) { value = toScript(v); }
void GetMember::store(const Vector2D& v) {
template <> void GetMember::store(const ScriptValueP& v) { value = v; }
template <> void GetMember::store(const ScriptP& v) { value = v; }
template <> void GetMember::store(const Vector2D& v) {
value = toScript(String::Format(_("(%.10lf,%.10lf)"), v.x, v.y));
}
......@@ -11,12 +11,11 @@
#include <util/prec.hpp>
class ScriptValue;
typedef boost::intrusive_ptr<ScriptValue> ScriptValueP;
DECLARE_INTRUSIVE_POINTER_TYPE(ScriptValue);
inline void intrusive_ptr_add_ref(ScriptValue* p);
inline void intrusive_ptr_release(ScriptValue* p);
class Vector2D;
template <typename T> class Defaultable;
// ----------------------------------------------------------------------------- : GetMember
......@@ -30,7 +29,7 @@ class GetMember {
/// Tell the reflection code we are not reading
inline bool reading() const { return false; }
/// The result, or scriptNil if the member was not found
/// The result, or script_nil if the member was not found
inline ScriptValueP result() { return value; }
// --------------------------------------------------- : Handling objects
......@@ -40,16 +39,13 @@ class GetMember {
void handle(const Char* name, const T& object) {
if (!value && name == targetName) store(object);
}
template <typename T>
void handle(const T&);
/// Handle an object: investigate children
template <typename T> void handle(const T&);
/// Handle a Defaultable: investigate children
template <typename T> void handle(const Defaultable<T>& def);
/// Store something in the return value
void store(const String& v);
void store(const Vector2D& v);
void store(const int v);
void store(const unsigned int v);
void store(const double v);
void store(const bool v);
template <typename T> void store(const T& v);
/// Store a vector in the return value
template <typename T> void store(const vector<T>& vector) {
value = toScript(&vector);
......@@ -76,7 +72,7 @@ class GetMember {
/// Implement enum reflection as used by GetMember
#define REFLECT_ENUM_GET_MEMBER(Enum) \
template<> void GetMember::handle<Enum>(const Enum& enum_) {\
template<> void GetMember::store<Enum>(const Enum& enum_) { \
EnumGetMember gm(*this); \
reflect_ ## Enum(const_cast<Enum&>(enum_), gm); \
}
......@@ -91,7 +87,7 @@ class EnumGetMember {
template <typename Enum>
inline void handle(const Char* name, Enum value, Enum enum_) {
if (enum_ == value) {
getMember.store(name);
getMember.store(String(name));
}
}
......
......@@ -63,6 +63,7 @@ void Reader::moveNext() {
void Reader::readLine() {
// fix UTF8 in ascii builds; skip BOM
line = decodeUTF8BOM(stream.ReadLine());
line_number += 1;
// read indentation
indent = 0;
while ((UInt)indent < line.size() && line.GetChar(indent) == _('\t')) {
......@@ -70,14 +71,13 @@ void Reader::readLine() {
}
// read key / value
size_t pos = line.find_first_of(_(':'), indent);
key = cannocial_name_form(trim(line.substr(indent, pos - indent)));
value = pos == String::npos ? _("") : trim_left(line.substr(pos+1));
// we read a line
line_number += 1;
// was it a comment?
if (!key.empty() && key.GetChar(0) == _('#')) {
if (!pos || line.GetChar(indent) == _('#')) {
// empty line or comment
key.clear();
return;
}
key = cannocial_name_form(trim(line.substr(indent, pos - indent)));
value = pos == String::npos ? _("") : trim_left(line.substr(pos+1));
}
// ----------------------------------------------------------------------------- : Handling basic types
......
......@@ -12,6 +12,8 @@
#include <util/prec.hpp>
#include <wx/txtstrm.h>
template <typename T> class Defaultable;
// ----------------------------------------------------------------------------- : Reader
typedef wxInputStream InputStream;
......@@ -57,6 +59,8 @@ class Reader {
template <typename T> void handle(shared_ptr<T>& pointer);
/// Reads a map from the input stream
//template <typename K, typename V> void handle(map<K,V>& map);
/// Reads a Defaultable from the input stream
template <typename T> void handle(Defaultable<T>& def);
private:
// --------------------------------------------------- : Data
......@@ -130,7 +134,16 @@ void Reader::handle(shared_ptr<T>& pointer) {
/// Implement reflection as used by Reader
#define REFLECT_OBJECT_READER(Cls) \
template<> void Reader::handle<Cls>(Cls& object) { \
object.reflect(*this); \
while (indent >= expected_indent) { \
UInt l = line_number; \
object.reflect(*this); \
if (l == line_number) { \
/* error */ \
do { \
moveNext(); \
} while (indent > expected_indent); \
} \
} \
}
// ----------------------------------------------------------------------------- : Reflection for enumerations
......
......@@ -12,6 +12,8 @@
#include <util/prec.hpp>
#include <wx/txtstrm.h>
template <typename T> class Defaultable;
// ----------------------------------------------------------------------------- : Writer
typedef wxOutputStream OutputStream;
......@@ -48,6 +50,8 @@ class Writer {
template <typename T> void handle(const shared_ptr<T>& pointer);
/// Write a map to the output stream
//template <typename K, typename V> void handle(map<K,V>& map);
/// Write an object of type Defaultable<T> to the output stream
template <typename T> void handle(const Defaultable<T>& def);
private:
// --------------------------------------------------- : Data
......
......@@ -82,6 +82,8 @@
#define REFLECT(var) tag.handle(_(#var), var)
/// Reflect a variable under the given name
#define REFLECT_N(name, var) tag.handle(_(name), var)
/// Reflect a variable without a name, should be used only once per class
#define REFLECT_NAMELESS(var) tag.handle(var)
/// Declare that the variables of a base class should also be reflected
#define REFLECT_BASE(Base) Base::reflect_impl(tag)
......
......@@ -68,6 +68,12 @@ inline shared_ptr<T> new_shared7(const A0& a0, const A1& a1, const A2& a2, const
#ifdef USE_INTRUSIVE_PTR
/// Declares the type TypeP as a intrusive_ptr<Type>
#define DECLARE_INTRUSIVE_POINTER_TYPE(Type) \
class Type; \
typedef intrusive_ptr<Type> Type##P;
/// Allocate a new intrusive-pointed object
template <typename T>
inline intrusive_ptr<T> new_intrusive() {
......@@ -85,6 +91,7 @@ inline shared_ptr<T> new_shared7(const A0& a0, const A1& a1, const A2& a2, const
}
#else
#define DECLARE_INTRUSIVE_POINTER_TYPE DECLARE_POINTER_TYPE
#define intrusive_ptr smart_ptr
#define new_intrusive new_smart
#define new_intrusive1 new_smart1
......
Markdown is supported
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