void ProvidersTest::test_EntityProperty() { Atlas::Message::Element value; auto provider = CreateProvider( { "entity" }); provider->value(value, QueryContext { *m_b1 }); assert(value.Ptr() == m_b1); //entity.type provider = CreateProvider( { "entity", "type" }); provider->value(value, QueryContext { *m_b1 }); assert(value.Ptr() == m_barrelType); //entity.id provider = CreateProvider( { "entity", "id" }); provider->value(value, QueryContext { *m_b1 }); assert(value.Int() == 1); //entity.mass provider = CreateProvider( { "entity", "mass" }); provider->value(value, QueryContext { *m_b1 }); assert(value.Int() == 30); //entity.burn_speed provider = CreateProvider( { "entity", "burn_speed" }); provider->value(value, QueryContext { *m_b1 }); assert(value.Float() == 0.3); }
void ServerInfo::processServer(const RootEntity &svr) { Atlas::Message::Element element; if (!svr->copyAttr("ruleset", element) && element.isString()) { _ruleset = element.String(); } else { return; } _name = svr->getName(); if (!svr->copyAttr("clients", element) && element.isInt()) { _clients = (int)element.Int(); } else { return; } if (!svr->copyAttr("server", element) && element.isString()) { _server = element.String(); } else { return; } if (!svr->copyAttr("uptime", element) && element.isFloat()) { _uptime = element.Float(); } else { return; } m_status = VALID; if (!svr->copyAttr("entities", element) && element.isInt()) { _entities = element.Int(); } if (!svr->copyAttr("version", element) && element.isString()) { m_version = element.String(); } if (!svr->copyAttr("builddate", element) && element.isString()) { m_buildDate = element.String(); } if (!svr->copyAttr("assets", element) && element.isList()) { for (auto& url : element.List()) { if (url.isString()) { m_assets.emplace_back(url.String()); } } } }
Py::Object CyPy_Element::wrap(Atlas::Message::Element value) { if (value.isNone()) { return Py::None(); } else if (value.isString()) { return Py::String(value.String()); } else if (value.isInt()) { return Py::Long(value.Int()); } else if (value.isFloat()) { return Py::Float(value.Float()); } else if (value.isList()) { return CyPy_ElementList::wrap(value.List()); } else { return CyPy_ElementMap::wrap(value.Map()); } }
Py::Object CyPy_Element::asPyObject(const Atlas::Message::Element& obj, bool useNativePythonType) { switch (obj.getType()) { case Element::TYPE_INT: return Py::Long(obj.Int()); case Element::TYPE_FLOAT: return Py::Float(obj.Float()); case Element::TYPE_STRING: return Py::String(obj.String()); case Element::TYPE_MAP: return mapAsPyObject(obj.Map(), useNativePythonType); case Element::TYPE_LIST: return listAsPyObject(obj.List(), useNativePythonType); default: break; } return Py::None(); }