mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-12 13:37:00 -04:00
added support for std::map
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@26 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -170,6 +170,28 @@ class ScriptCollection : public ScriptValue {
|
|||||||
const Collection* value;
|
const Collection* value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------- : Collections : maps
|
||||||
|
|
||||||
|
/// Script value containing a map like collection
|
||||||
|
template <typename Collection>
|
||||||
|
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
|
// ----------------------------------------------------------------------------- : Objects
|
||||||
|
|
||||||
/// Script value containing an object (pointer)
|
/// 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; }
|
inline ScriptValueP toScript(bool v) { return v ? script_true : script_false; }
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline ScriptValueP toScript(const vector<T>* v) { return new_intrusive1<ScriptCollection<vector<T> > >(v); }
|
inline ScriptValueP toScript(const vector<T>* v) { return new_intrusive1<ScriptCollection<vector<T> > >(v); }
|
||||||
|
template <typename K, typename V>
|
||||||
|
inline ScriptValueP toScript(const map<K,V>* v) { return new_intrusive1<ScriptMap<map<K,V> > >(v); }
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline ScriptValueP toScript(const shared_ptr<T>& v) { return new_intrusive1<ScriptObject<T> >(v); }
|
inline ScriptValueP toScript(const shared_ptr<T>& v) { return new_intrusive1<ScriptObject<T> >(v); }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user