mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-12 05:36:59 -04:00
Added Alignment, Defaultable and Scriptable types, needed some reflection tweaks for the last two.
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@17 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
+10
-14
@@ -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);
|
||||
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));
|
||||
// we read a line
|
||||
line_number += 1;
|
||||
// was it a comment?
|
||||
if (!key.empty() && key.GetChar(0) == _('#')) {
|
||||
key.clear();
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Handling basic types
|
||||
|
||||
+14
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user