Implement the __get_objects function

refs #8127
This commit is contained in:
Gunnar Beutner 2014-12-19 13:08:31 +01:00
parent b78a8b6c77
commit 978aeed741
2 changed files with 17 additions and 0 deletions

View File

@ -46,6 +46,7 @@ REGISTER_SCRIPTFUNCTION(typeof, &ScriptUtils::TypeOf);
REGISTER_SCRIPTFUNCTION(keys, &ScriptUtils::Keys);
REGISTER_SCRIPTFUNCTION(random, &Utility::Random);
REGISTER_SCRIPTFUNCTION(__get_object, &ScriptUtils::GetObject);
REGISTER_SCRIPTFUNCTION(__get_objects, &ScriptUtils::GetObjects);
REGISTER_SCRIPTFUNCTION(assert, &ScriptUtils::Assert);
REGISTER_SCRIPTFUNCTION(string, &ScriptUtils::CastString);
REGISTER_SCRIPTFUNCTION(number, &ScriptUtils::CastNumber);
@ -253,6 +254,21 @@ DynamicObject::Ptr ScriptUtils::GetObject(const String& type, const String& name
return dtype->GetObject(name);
}
Array::Ptr ScriptUtils::GetObjects(const String& type)
{
DynamicType::Ptr dtype = DynamicType::GetByName(type);
if (!dtype)
BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid type name"));
Array::Ptr result = new Array();
BOOST_FOREACH(const DynamicObject::Ptr& object, dtype->GetObjects())
result->Add(object);
return result;
}
void ScriptUtils::Assert(const Value& arg)
{
if (!arg.ToBool())

View File

@ -48,6 +48,7 @@ public:
static Type::Ptr TypeOf(const Value& value);
static Array::Ptr Keys(const Dictionary::Ptr& dict);
static DynamicObject::Ptr GetObject(const String& type, const String& name);
static Array::Ptr GetObjects(const String& type);
static void Assert(const Value& arg);
private: