/** * Tests that direct deseralization of a pointer to an abstract class leads to * a @c XMLSerializationMemoryAllocationException. */ void testMemoryAllocationException() { Abstract* a = new Specific(); std::stringstream stream; XmlSerializer s; s.serialize("Abstract", a); s.write(stream); // Reset all variables to default values... delete a; a = 0; XmlDeserializer d; d.read(stream); try { d.deserialize("Abstract", a); delete a; test(false, "No exception raised on abstract class memory allocation try"); } catch (XmlSerializationMemoryAllocationException&) { } }
Processor* Processor::clone() const { try { std::stringstream stream; // first serialize XmlSerializer s; s.serialize("this", this); s.write(stream); // then deserialize again XmlDeserializer d; d.read(stream); Processor* proc = 0; d.deserialize("this", proc); proc->setDescriptions(); return proc; } catch (std::exception& e) { LERROR("Failed to clone processor '" << getID() << "': " << e.what()); return 0; } }
/** * Tests serialization and deserialization of a @c std::set. */ void testSet() { const int SETELEMENTCOUNT = 5; std::set<int> set; for (int i = 0; i < SETELEMENTCOUNT; ++i) set.insert(i); std::stringstream stream; XmlSerializer s; s.serialize("set", set); s.write(stream); // Reset all variables to default values... set.clear(); test(set.size() == 0, "set is not empty"); XmlDeserializer d; d.read(stream); d.deserialize("set", set); test((int)set.size() == SETELEMENTCOUNT, "not all set items deserialized"); bool deserializedValues[SETELEMENTCOUNT]; for (int i = 0; i < SETELEMENTCOUNT; ++i) deserializedValues[i] = false; for (std::set<int>::iterator it = set.begin(); it != set.end(); ++it) if (*it >= 0 && *it < SETELEMENTCOUNT) deserializedValues[*it] = true; for (int i = 0; i < SETELEMENTCOUNT; ++i) { std::stringstream itemStream; itemStream << i; test(deserializedValues[i], "int item '" + itemStream.str() + "' not deserialized"); } }
/** * Tests serialization and deserialization of @c AbstractSerializable null pointers. */ void testBugAbstractSerializableNullPointerSerialization() { Abstract* a = 0; std::stringstream stream; AbstractFactory factory; XmlSerializer s; s.setUseAttributes(true); s.registerFactory(&factory); s.serialize("Abstract", a); s.write(stream); XmlDeserializer d; d.setUseAttributes(true); d.registerFactory(&factory); d.read(stream); try { d.deserialize("Abstract", a); } catch (XmlSerializationMemoryAllocationException&) { test(false, "bug occured, since memory allocation exception is thrown for 0 pointer"); } }
void VolumeHistogramIntensity::serialize(XmlSerializer& s) const { s.serialize("histograms", histograms_, "channel"); }
void MeshListGeometry::serialize(XmlSerializer& s) const { s.serialize("meshes", meshes_); }
void PlotSelectionEntry::serialize(XmlSerializer& s) const { s.serialize("selection", selection_); s.serialize("highlight", highlight_); s.serialize("renderLabel", renderLabel_); s.serialize("zoomTo", zoomTo_); }
void PlotFunctionDiscret::DiscretizeValues::serialize(XmlSerializer& s) const { s.serialize("Interval",interval); s.serialize("Stepwidth",stepwidth); s.serialize("Columns",columns); }
void PropertyKeyValue<tgt::Camera>::serialize(XmlSerializer& s) const { // base class props s.serialize("time", time_); s.serialize("smooth", smooth_); s.serialize("before", before_); s.serialize("after", after_); // camera s.serialize("projectionMode", (int)value_.getProjectionMode()); s.serialize("position", value_.getPosition()); s.serialize("focus", value_.getFocus()); s.serialize("upVector", value_.getUpVector()); s.serialize("frustLeft", value_.getFrustLeft()); s.serialize("frustRight", value_.getFrustRight()); s.serialize("frustBottom", value_.getFrustBottom()); s.serialize("frustTop", value_.getFrustTop()); s.serialize("frustNear", value_.getNearDist()); s.serialize("frustFar", value_.getFarDist()); s.serialize("fovy", value_.getFovy()); }
void PlotDataFitFunction::FittingValues::serialize(XmlSerializer& s) const { s.serialize("regressionType",regressionType); s.serialize("column",column); s.serialize("Dimension",dimension); }
void TransFuncBanana::serialize(XmlSerializer& s) const { TransFuncPrimitive::serialize(s); for (int i = 0; i < 4; ++i) s.serialize("coords", coords_[i]); }
void TransFuncPrimitive::serialize(XmlSerializer& s) const { s.serialize("fuzzy", fuzziness_); s.serialize("color", color_); }
void VolumeCollection::serialize(XmlSerializer& s) const { s.serialize("VolumeHandles", volumeHandles_, "VolumeHandle"); }
/** * Tests serialization and deserialization of polymorphic classes. */ void testPolymorphism() { Parent p; p.pdata = 1; Child c; c.pdata = 2; c.cdata = 3; Parent* pp = &p; Parent* pc = &c; Parent* child1 = new Child(); child1->pdata = 4; dynamic_cast<Child*>(child1)->cdata = 5; Child* child2 = new Child(); child2->pdata = 6; child2->cdata = 7; Factory factory; std::stringstream stream; try { XmlSerializer s; s.registerFactory(&factory); s.serialize("p", p); s.serialize("c", c); s.serialize("pp", pp); s.serialize("pc", pc); s.serialize("child1", child1); s.serialize("child2", child2); s.write(stream); delete child1; delete child2; } catch (...) { delete child1; delete child2; throw; } // Reset all variables to default values... p.pdata = 0; c.pdata = 0; c.cdata = 0; pp = 0; pc = 0; child1 = 0; child2 = 0; XmlDeserializer d; d.registerFactory(&factory); d.read(stream); d.deserialize("p", p); d.deserialize("c", c); d.deserialize("pp", pp); d.deserialize("pc", pc); d.deserialize("child1", child1); d.deserialize("child2", child2); test(p.pdata, 1, "p.pdata incorrect deserialized"); test(c.pdata, 2, "c.pdata incorrect deserialized"); test(c.cdata, 3, "c.cdata incorrect deserialized"); test(pp != 0, "pp still null"); test(pp == &p, "pp does not point to p"); test(pc != 0, "pc still null"); test(pc == &c, "pc does not point to c"); test(child1 != 0, "child1 still null"); test(child1->pdata, 4, "child1.pdata incorrect deserialized"); test(dynamic_cast<Child*>(child1) != 0, "child1 deserialized without using correct polymorphic type"); test(dynamic_cast<Child*>(child1)->cdata, 5, "child2.cdata incorrect deserialized"); test(child2 != 0, "child2 still null"); test(child2->pdata, 6, "child2.pdata incorrect deserialized"); test(child2->cdata, 7, "child2.cdata incorrect deserialized"); delete child1; delete child2; }
/** * @see Serializable::serialize */ virtual void serialize(XmlSerializer& s) const { Parent::serialize(s); s.serialize("cdata", cdata); }
void PortConnection::serialize(XmlSerializer& s) const { s.serialize("Outport", outport_); s.serialize("Inport", inport_); }
void MeshGeometry::serialize(XmlSerializer& s) const { s.serialize("faces", faces_); }
void AnimatedProcessor::serialize(XmlSerializer& s) const { s.serialize("processor", processor_); s.serialize("properties", properties_, "Property"); }
void PositionMetaData::serialize(XmlSerializer& s) const { s.serialize("x", x_); s.serialize("y", y_); }
void OctreeBrickPoolManagerDiskLimitedRam::serialize(XmlSerializer& s) const { OctreeBrickPoolManagerDisk::serialize(s); s.serialize("maxRamUsed", maxRamUsed_); s.serialize("nextVirtualMemoryAddress", nextVirtualMemoryAddress_); }
void CameraProperty::serialize(XmlSerializer& s) const { Property::serialize(s); s.serialize("projectionMode", (int)value_.getProjectionMode()); s.serialize("position", value_.getPosition()); s.serialize("focus", value_.getFocus()); s.serialize("upVector", value_.getUpVector()); s.serialize("frustLeft", value_.getFrustLeft()); s.serialize("frustRight", value_.getFrustRight()); s.serialize("frustBottom", value_.getFrustBottom()); s.serialize("frustTop", value_.getFrustTop()); s.serialize("frustNear", value_.getNearDist()); s.serialize("frustFar", value_.getFarDist()); s.serialize("fovy", value_.getFovy()); s.serialize("eyeMode", (int)value_.getStereoEyeMode()); s.serialize("eyeSeparation", value_.getStereoEyeSeparation()); s.serialize("axisMode", (int)value_.getStereoAxisMode()); }
void VolumePreview::serialize(XmlSerializer& s) const { s.serialize("height", height_); s.serializeBinaryBlob("prevData", prevData_); }
void CameraProperty::serialize(XmlSerializer& s) const { Property::serialize(s); s.serialize("projectionMode", (int)value_.getProjectionMode()); s.serialize("position", value_.getPosition()); s.serialize("focus", value_.getFocus()); s.serialize("upVector", value_.getUpVector()); s.serialize("maxValue", maxValue_); s.serialize("minValue", minValue_); s.serialize("frustLeft", value_.getFrustLeft()); s.serialize("frustRight", value_.getFrustRight()); s.serialize("frustBottom", value_.getFrustBottom()); s.serialize("frustTop", value_.getFrustTop()); s.serialize("frustNear", value_.getNearDist()); s.serialize("frustFar", value_.getFarDist()); s.serialize("fovy", value_.getFovy()); s.serialize("eyeMode", (int)value_.getStereoEyeMode()); s.serialize("eyeSeparation", value_.getStereoEyeSeparation()); s.serialize("axisMode", (int)value_.getStereoAxisMode()); s.serialize("trackball", trackball_); s.serialize("centerOption", (int)centerOption_); s.serialize("adaptOnChange", adaptOnChange_); s.serialize("sceneLLF", currentSceneBounds_.getLLF()); s.serialize("sceneURB", currentSceneBounds_.getURB()); }
void ColorMap::serialize(XmlSerializer& s) const { s.serialize("colors", colors_); s.serialize("name", name_); }
void PlotSelection::serialize(XmlSerializer& s) const { s.serialize("isTablePositionFlag", isTablePositionFlag_); s.serialize("tablePosition", tablePosition_); s.serialize("selection", selection_); }
void PropertyState::serialize(XmlSerializer& s) const { s.serialize("propertyOwner", propertyOwner_); s.serialize("propertyName", propertyName_); s.serialize("propertyID", propertyID_); s.serialize("propertyValue", propertyValue_); }
void ColorMapProperty::serialize(XmlSerializer& s) const { Property::serialize(s); s.serialize("colors", value_); }
void PlotEntitySettings::serialize(XmlSerializer& s) const { s.serialize("entity", static_cast<int>(entity_)); s.serialize("colorMap", colorMap_); s.serialize("mainColumnIndex", mainColumnIndex_); s.serialize("candleTopColumnIndex", candleTopColumnIndex_); s.serialize("candleBottomColumnIndex", candleBottomColumnIndex_); s.serialize("stickTopColumnIndex", stickTopColumnIndex_); s.serialize("stickBottomColumnIndex", stickBottomColumnIndex_); s.serialize("optionalCI", optionalColumnIndex_); s.serialize("secondOptionalCI", secondOptionalColumnIndex_); s.serialize("firstColor", firstColor_); s.serialize("secondColor", secondColor_); s.serialize("lineStyle", static_cast<int>(lineStyle_)); s.serialize("splineFlag", splineFlag_); s.serialize("errorbarFlag", errorbarFlag_); s.serialize("wireOnlyFlag", wireOnlyFlag_); s.serialize("heightmapFlag", heightmapFlag_); s.serialize("candleStickFlag", candleStickFlag_); s.serialize("minGlyphSize", minGlyphSize_); s.serialize("maxGlyphSize", maxGlyphSize_); s.serialize("glyphStyle", static_cast<int>(glyphStyle_)); //see FileDialogProperty // convert path to an relative one with respect to the document's path std::string path = texturePath_; if (!path.empty() && !s.getDocumentPath().empty()) path = tgt::FileSystem::relativePath(path, tgt::FileSystem::dirName(s.getDocumentPath())); // cleanup path: replace backslashes std::string::size_type pos = path.find("\\"); while (pos != std::string::npos) { path[pos] = '/'; pos = path.find("\\"); } s.serialize("texturePath", path); s.serialize("useTextureFlag", useTextureFlag_); }
void VolumeHistogramIntensityGradient::serialize(XmlSerializer& s) const { s.serialize("histogram", hist_); }
void PortConnection::PortEntry::serialize(XmlSerializer& s) const { s.serialize("name", port_->getID()); s.serialize("Processor", port_->getProcessor()); }