'ported' scripting code to work with unicode and the rest of MSE

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@14 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2006-10-10 17:22:05 +00:00
parent c0e8417189
commit 33abea6221
19 changed files with 259 additions and 109 deletions
+16
View File
@@ -64,5 +64,21 @@ class ParseError : public Error {
inline ParseError(const String& str) : Error(str) {}
};
/// Parse error in a script
class ScriptParseError : public ParseError {
public:
inline ScriptParseError(const String& str) : ParseError(str) {}
inline ScriptParseError(const String& exp, const String& found)
: ParseError(_("Expected '") + exp + _("' instead of '") + found + _("'")) {}
};
// ----------------------------------------------------------------------------- : Script errors
/// A runtime error in a script
class ScriptError : public Error {
public:
inline ScriptError(const String& str) : Error(str) {}
};
// ----------------------------------------------------------------------------- : EOF
#endif
+5
View File
@@ -7,6 +7,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/io/get_member.hpp>
#include <util/vector2d.hpp>
#include <script/value.hpp>
// ----------------------------------------------------------------------------- : GetMember
@@ -20,3 +21,7 @@ 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); }
void GetMember::store(const Vector2D& v) {
value = toScript(String::Format(_("(%.10lf,%.10lf)"), v.x, v.y));
}
+7 -4
View File
@@ -16,6 +16,8 @@ typedef boost::intrusive_ptr<ScriptValue> ScriptValueP;
inline void intrusive_ptr_add_ref(ScriptValue* p);
inline void intrusive_ptr_release(ScriptValue* p);
class Vector2D;
// ----------------------------------------------------------------------------- : GetMember
/// Find a member with a specific name using reflection
@@ -43,6 +45,7 @@ class GetMember {
/// 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);
@@ -71,9 +74,9 @@ class GetMember {
// ----------------------------------------------------------------------------- : Reflection for enumerations
/// Implement enum reflection as used by Writer
#define REFLECT_ENUM_WRITER(Enum) \
template<> void Writer::handle<Enum>(const Enum& enum_) { \
/// Implement enum reflection as used by GetMember
#define REFLECT_ENUM_GET_MEMBER(Enum) \
template<> void GetMember::handle<Enum>(const Enum& enum_) {\
EnumGetMember gm(*this); \
reflect_ ## Enum(const_cast<Enum&>(enum_), gm); \
}
@@ -88,7 +91,7 @@ class EnumGetMember {
template <typename Enum>
inline void handle(const Char* name, Enum value, Enum enum_) {
if (enum_ == value) {
writer.store(name);
getMember.store(name);
}
}
+1 -3
View File
@@ -105,7 +105,5 @@ template <> void Writer::handle(const bool& value) {
// ----------------------------------------------------------------------------- : Handling less basic util types
template <> void Writer::handle(const Vector2D& vec) {
String formated;
formated.Printf(_("(%.10lf,%.10lf)"), vec.x, vec.y);
handle(formated);
handle(String::Format(_("(%.10lf,%.10lf)"), vec.x, vec.y));
}
+14 -2
View File
@@ -16,6 +16,7 @@
#include "io/reader.hpp"
#include "io/writer.hpp"
#include "io/get_member.hpp"
// ----------------------------------------------------------------------------- : Declaring reflection
@@ -27,8 +28,10 @@
template<class Tag> void reflect_impl(Tag& tag); \
friend class Reader; \
friend class Writer; \
friend class GetMember; \
void reflect(Reader& reader); \
void reflect(Writer& writer)
void reflect(Writer& writer); \
void reflect(GetMember& getMember)
/// Declare that a class supports reflection, which can be overridden in derived classes
#define DECLARE_REFLECTION_VIRTUAL() \
@@ -36,8 +39,10 @@
template<class Tag> void reflect_impl(Tag& tag); \
friend class Reader; \
friend class Writer; \
friend class GetMember; \
virtual void reflect(Reader& reader); \
virtual void reflect(Writer& writer)
virtual void reflect(Writer& writer); \
virtual void reflect(GetMember& getMember)
// ----------------------------------------------------------------------------- : Implementing reflection
@@ -47,6 +52,7 @@
* Currently creates the methods:
* - Reader::handle(Cls&)
* - Writer::handle(Cls&)
* - GetMember::handle(Cls&)
* Usage:
* @code
* IMPLEMENT_REFLECTION(MyClass) {
@@ -58,6 +64,7 @@
#define IMPLEMENT_REFLECTION(Cls) \
REFLECT_OBJECT_READER(Cls) \
REFLECT_OBJECT_WRITER(Cls) \
REFLECT_OBJECT_GET_MEMBER(Cls) \
/* Extra level, so it can be declared virtual */ \
void Cls::reflect(Reader& reader) { \
reflect_impl(reader); \
@@ -65,6 +72,9 @@
void Cls::reflect(Writer& writer) { \
reflect_impl(writer); \
} \
void Cls::reflect(GetMember& getMember) { \
reflect_impl(getMember); \
} \
template <class Tag> \
void Cls::reflect_impl(Tag& tag)
@@ -93,12 +103,14 @@
* Currently creates the methods:
* - Reader::handle(Enum&
* - Writer::handle(const Enum&)
* - GetMember::handle(const Enum&)
*/
#define IMPLEMENT_REFLECTION_ENUM(Enum) \
template <class Tag> \
void reflect_ ## Enum (Enum& enum_, Tag& tag); \
REFLECT_ENUM_READER(Enum) \
REFLECT_ENUM_WRITER(Enum) \
REFLECT_ENUM_GET_MEMBER(Enum) \
template <class Tag> \
void reflect_ ## Enum (Enum& enum_, Tag& tag)
+35 -1
View File
@@ -14,7 +14,14 @@
// ----------------------------------------------------------------------------- : Includes
// MOVEME
/// Using intrusive_ptr where possible? (as opposed to smart_ptr)
#define USE_INTRUSIVE_PTR
#include <boost/shared_ptr.hpp>
#ifdef USE_INTRUSIVE_PTR
#include <boost/intrusive_ptr.hpp>
#endif
using namespace boost;
// ----------------------------------------------------------------------------- : Declaring
@@ -31,7 +38,6 @@ template <typename T>
inline shared_ptr<T> new_shared() {
return shared_ptr<T>(new T());
}
/// Allocate a new shared-pointed object, given one argument to pass to the ctor of T
template <typename T, typename A0>
inline shared_ptr<T> new_shared1(const A0& a0) {
@@ -58,5 +64,33 @@ inline shared_ptr<T> new_shared7(const A0& a0, const A1& a1, const A2& a2, const
return shared_ptr<T>(new T(a0, a1, a2, a3, a4, a5, a6));
}
// ----------------------------------------------------------------------------- : Intrusive pointers
#ifdef USE_INTRUSIVE_PTR
/// Allocate a new intrusive-pointed object
template <typename T>
inline intrusive_ptr<T> new_intrusive() {
return intrusive_ptr<T>(new T());
}
/// Allocate a new intrusive-pointed object, given one argument to pass to the ctor of T
template <typename T, typename A0>
inline intrusive_ptr<T> new_intrusive1(const A0& a0) {
return intrusive_ptr<T>(new T(a0));
}
/// Allocate a new intrusive-pointed object, given two arguments to pass to the ctor of T
template <typename T, typename A0, typename A1>
inline intrusive_ptr<T> new_intrusive2(const A0& a0, const A1& a1) {
return intrusive_ptr<T>(new T(a0, a1));
}
#else
#define intrusive_ptr smart_ptr
#define new_intrusive new_smart
#define new_intrusive1 new_smart1
#define new_intrusive2 new_smart2
#define new_intrusive3 new_smart3
#endif
// ----------------------------------------------------------------------------- : EOF
#endif