From c0d644bdddd4495890671937a30a2f6d237f8f8d Mon Sep 17 00:00:00 2001 From: twanvl Date: Thu, 19 Oct 2006 12:30:42 +0000 Subject: [PATCH] added support for std::map git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@26 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/script/value.hpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/script/value.hpp b/src/script/value.hpp index ae29f8a0..1d9b0f2f 100644 --- a/src/script/value.hpp +++ b/src/script/value.hpp @@ -170,6 +170,28 @@ class ScriptCollection : public ScriptValue { const Collection* value; }; +// ----------------------------------------------------------------------------- : Collections : maps + +/// Script value containing a map like collection +template +class ScriptMap : public ScriptValue { + public: + inline ScriptMap(const Collection* v) : value(v) {} + virtual ScriptType type() const { return SCRIPT_OBJECT; } + virtual String typeName() const { return _("collection"); } + virtual ScriptValueP getMember(const String& name) const { + Collection::const_iterator it = value->find(name); + if (it != value->end()) { + return toScript(it->second); + } else { + throw ScriptError(_("Collection has no member ") + name); + } + } + private: + /// Store a pointer to a collection, collections are only ever used for structures owned outside the script + const Collection* value; +}; + // ----------------------------------------------------------------------------- : Objects /// Script value containing an object (pointer) @@ -199,6 +221,8 @@ ScriptValueP toScript(const Color& v); inline ScriptValueP toScript(bool v) { return v ? script_true : script_false; } template inline ScriptValueP toScript(const vector* v) { return new_intrusive1 > >(v); } +template +inline ScriptValueP toScript(const map* v) { return new_intrusive1 > >(v); } template inline ScriptValueP toScript(const shared_ptr& v) { return new_intrusive1 >(v); }