+
+void *Interpreter::GetObject(int typeId, const Value &v) {
+ if (v.IsLiteral()) {
+ if (v.GetLiteral().IsObject()) {
+ int typeId(TypeDescription::GetTypeId(v.GetLiteral().GetTypeName()));
+ const TypeDescription &td(TypeDescription::Get(typeId));
+ char *object(new char[td.Size()]);
+ td.Construct(object);
+ int id(values[typeId].size());
+ values[typeId].push_back(object);
+ ReadObject(typeId, id, object, *v.GetLiteral().GetProperties());
+ return object;
+ } else {
+ int typeId(0), id(0);
+ switch (v.GetLiteral().GetType()) {
+ case Literal::ARRAY_VALUES:
+ throw Error("cannot copy value arrays, sorry");
+ break;
+ case Literal::ARRAY_PROPS:
+ throw Error("cannot copy property list arrays, sorry");
+ break;
+ case Literal::BOOLEAN:
+ {
+ typeId = TypeDescription::GetTypeId("Boolean");
+ id = values[typeId].size();
+ const TypeDescription &td(TypeDescription::Get(typeId));
+ char *object(new char[td.Size()]);
+ values[typeId].push_back(new (object) bool(v.GetLiteral().GetBoolean()));
+ }
+ break;
+ case Literal::COLOR:
+ {
+ typeId = TypeDescription::GetTypeId("Color");
+ id = values[typeId].size();
+ const TypeDescription &td(TypeDescription::Get(typeId));
+ char *object(new char[td.Size()]);
+ values[typeId].push_back(new (object) Color(v.GetLiteral().GetRed(), v.GetLiteral().GetGreen(), v.GetLiteral().GetBlue(), v.GetLiteral().GetAlpha()));
+ }
+ break;
+ case Literal::NUMBER:
+ {
+ typeId = TypeDescription::GetTypeId("Number");
+ id = values[typeId].size();
+ const TypeDescription &td(TypeDescription::Get(typeId));
+ char *object(new char[td.Size()]);
+ values[typeId].push_back(new (object) int(v.GetLiteral().GetNumber()));
+ }
+ break;
+ case Literal::PATH:
+ {
+ typeId = TypeDescription::GetTypeId("Path");
+ id = values[typeId].size();
+ char *str(new char[v.GetLiteral().GetString().size() + 1]);
+ std::memcpy(str, v.GetLiteral().GetString().c_str(), v.GetLiteral().GetString().size());
+ str[v.GetLiteral().GetString().size()] = '\0';
+ values[typeId].push_back(str);
+ }
+ break;
+ case Literal::STRING:
+ {
+ typeId = TypeDescription::GetTypeId("String");
+ id = values[typeId].size();
+ char *str(new char[v.GetLiteral().GetString().size() + 1]);
+ std::memcpy(str, v.GetLiteral().GetString().c_str(), v.GetLiteral().GetString().size());
+ str[v.GetLiteral().GetString().size()] = '\0';
+ values[typeId].push_back(str);
+ }
+ break;
+ case Literal::VECTOR:
+ {
+ typeId = TypeDescription::GetTypeId("Vector");
+ id = values[typeId].size();
+ const TypeDescription &td(TypeDescription::Get(typeId));
+ char *object(new char[td.Size()]);
+ values[typeId].push_back(new (object) Vector<int>(v.GetLiteral().GetX(), v.GetLiteral().GetY()));
+ }
+ break;
+ case Literal::OBJECT:
+ {
+ typeId = TypeDescription::GetTypeId(v.GetLiteral().GetTypeName());
+ const TypeDescription &td(TypeDescription::Get(typeId));
+ id = values[typeId].size();
+ char *object(new char[td.Size()]);
+ td.Construct(object);
+ ReadObject(typeId, id, object, *v.GetLiteral().GetProperties());
+ }
+ break;
+ }
+ return values[typeId][id];
+ }