Material::Material(Reader *reader) : Serializable(objectName, reader) { diffuse = specular = 0; refract = 0; m_name = reader->attrib("name"); while (reader->hasChild()) { QString child = reader->child(); if (!diffuse && child == "diffuse") { reader->handleObject(); diffuse = ColorModel::createDiffuse(reader->attrib("model"), reader); } else if (!specular && child == "specular") { reader->handleObject(); specular = ColorModel::createSpecular(reader->attrib("model"), reader); } else if (!refract && child == "refract") { refract = new Refract(m_name, reader); } else { throw SerializeException("Unknown children"); } } if (!diffuse || !specular) throw SerializeException("Both diffuse and specular models should be defined"); reader->endObject(); }
Protocol deserialize(char* input) { if (input == nullptr) { ERR("Null input, nothing to deserialize"); throw SerializeException(); } // MSG("Deserialize: %s", input); std::string wrap(input); int i1 = wrap.find_first_of('#'); std::string src_id_str = wrap.substr(0, i1); // DBG("SID: %i %s", i1, src_id_str.c_str()); int i2 = wrap.find_first_of('#', i1 + 1); std::string dest_id_str = wrap.substr(i1 + 1, i2 - i1 - 1); // DBG("DID: %i %s", i2, dest_id_str.c_str()); int i3 = wrap.find_first_of('#', i2 + 1); std::string ts_str = wrap.substr(i2 + 1, i3 - i2 - 1); // DBG("TS: %i %s", i3, ts_str.c_str()); int i4 = wrap.find_first_of('#', i3 + 1); std::string name = wrap.substr(i3 + 1, i4 - i3 - 1); // DBG("NAME: %i %s", i4, name.c_str()); int i5 = wrap.find_first_of('#', i4 + 1); std::string message = wrap.substr(i4 + 1, i5 - i4 - 1); // DBG("MSG: %i %s", i5, message.c_str()); Protocol protocol; protocol.src_id = std::atoi(src_id_str.c_str()); protocol.dest_id = std::atoi(dest_id_str.c_str()); protocol.timestamp = std::stoll(ts_str.c_str()); protocol.name = name; protocol.message = message; return protocol; }
Scene::Scene(Reader* reader) : ShaderGenerator(":/scene.frag"), Serializable(objectName, reader) { light = 0; eye = 0; fog = 0; while (reader->hasChild()) { QString child = reader->child(); if (child == "fog") { fog = new Fog(reader); } else if (child == "light") { light = new ShaderCode(reader); } else if (child == "eye") { eye = new ShaderCode(reader); } else if (child == "material") { Material* mat = new Material(reader); if (material.contains(mat->name())) { delete mat; throw SerializeException("Material redeclaration"); } material.insert(mat->name(), mat); } else if (child == "item") { items += new Item(reader); } else { throw SerializeException("Unexpected children"); } } if (!fog || !light || !eye) throw SerializeException("Fog, light and eye are required"); reader->endObject(); }