Пример #1
0
/**
 * Tests serialization and deserialization of cascaded STL containers
 * like @c std::vector or @c std::map.
 */
void testComplexSTL() {
    std::map<int, std::string> m1, m2, m3;
    m2[1] = "one";
    m3[2] = "two";
    m3[3] = "three";

    std::vector<std::map<int, std::string> > v;
    v.push_back(m1);
    v.push_back(m2);
    v.push_back(m3);

    std::stringstream stream;

    XmlSerializer s;
    s.serialize("v", v);
    s.write(stream);

    // Reset all variables to default values...
    v.clear();
    test(v.size() == 0, "vector is not empty");

    XmlDeserializer d;
    d.read(stream);
    d.deserialize("v", v);

    test(v.size() == 3, "not all vector item deserialized");
    test(v[0].size() == 0, "incorrect size of first vector item");
    test(v[1].size() == 1, "incorrect size of second vector item");
    test(v[2].size() == 2, "incorrect size of third vector item");
    test(v[1][1] == "one", "first item of second vector item incorrect deserialized");
    test(v[2][2] == "two", "first item of thrid vector item incorrect deserialized");
    test(v[2][3] == "three", "second item of third vector item incorrect deserialized");
}
Пример #2
0
/**
 * Tests serialization and deserialization of pointers to abstract classes.
 */
void testIAbstractSerializable() {
    Abstract* a = new Specific();
    dynamic_cast<Specific*>(a)->i = 1;

    std::stringstream stream;

    AbstractFactory factory;

    XmlSerializer s;
    s.registerFactory(&factory);
    s.serialize("Abstract", a);
    s.write(stream);

    // Reset all variables to default values...
    delete a;
    a = 0;

    XmlDeserializer d;
    d.registerFactory(&factory);
    d.read(stream);
    d.deserialize("Abstract", a);

    test(a != 0, "a still null");
    Specific* specific = dynamic_cast<Specific*>(a);
    test(specific != 0, "cast to Specific* not possible");
    test(specific->i, 1, "a incorrect deserialized");

    delete a;
}
Пример #3
0
bool serializeSettings(const PropertyOwner* po, const std::string& filename) {
    std::ofstream stream(filename.c_str(), std::ios_base::out);
    if (stream.fail()) {
        LWARNINGC("VoreenSettings", "Unable to open file " << filename << " for writing.");
        return false;
    }

    bool success = true;
    try {
        XmlSerializer xmlSerializer;
        po->serialize(xmlSerializer);
        xmlSerializer.write(stream);
        if (stream.bad()) {
            LWARNINGC("VoreenSettings", "Unable to write to file: " << filename);
            success = false;
        }
        stream.close();
    }
    catch (SerializationException &e) {
        LWARNINGC("VoreenSettings", "SerializationException: " << e.what());
        stream.close();
        success = false;
    }
    return success;
}
Пример #4
0
void VolumeHistogramIntensityGradient::serialize(XmlSerializer& s) const {
    s.serialize("values", histValues_);
    s.serialize("maxValue", maxValue_);
    s.serialize("significantRangeIntensity", significantRangeIntensity_);
    s.serialize("significantRangeGradient", significantRangeGradient_);
    s.serialize("scaleFactor", scaleFactor_);
}
Пример #5
0
void LightSourceProperty::serialize(XmlSerializer& s) const {
    FloatVec4Property::serialize(s);
    s.serialize("Center", curCenter_);
    s.serialize("LightPos", lightPos_);
    s.serialize("FollowCam", followCam_);
    s.serialize("MaxDist", maxDist_);
}
Пример #6
0
/**
 * Tests serialization and deserialization of a @c std::map.
 */
void testMap() {
    std::map<int, std::string> m;
    m[1] = "one";
    m[2] = "two";
    m[3] = "three";

    std::stringstream stream;

    XmlSerializer s;
    s.serialize("m", m);
    s.write(stream);

    // Reset all variables to default values...
    m.clear();
    test(m.size() == 0, "map is not empty");

    XmlDeserializer d;
    d.read(stream);
    d.deserialize("m", m);

    test(m.size() == 3, "not all map items deserialized");
    test(m[1] == "one", "first pair incorrect deserialized");
    test(m[2] == "two", "second pair incorrect deserialized");
    test(m[3] == "three", "third pair incorrect deserialized");
}
void TemplatePropertyTimeline<Camera>::serialize(XmlSerializer& s) const {
    tgtAssert(property_, "No property");
    s.serialize("activeOnRendering", activeOnRendering_);
    s.serialize("propertyOwner", property_->getOwner());
    s.serialize("propertyId", property_->getID());
    s.serialize("duration", duration_);
    s.serialize("timeline", timeline_);
}
Пример #8
0
void NumericProperty<T>::serialize(XmlSerializer& s) const {
    Property::serialize(s);

    s.serialize("value", value_);

    // serialize tracking mode, if it differs from default value
    if (!tracking_)
        s.serialize("tracking", tracking_);
}
Пример #9
0
void OpenCLSource::serialize(XmlSerializer& s) const {
    s.serialize("programModified", programModified_);
    std::string relPath = tgt::FileSystem::relativePath(tgt::FileSystem::dirName(programFilename_),
        tgt::FileSystem::dirName(s.getDocumentPath()));
    std::string relProgramFilename = relPath + "/" + tgt::FileSystem::fileName(programFilename_);
    s.serialize("programFilename", relProgramFilename);
    if (programModified_)
        s.serialize("programSource", programSource_);
}
Пример #10
0
std::string Geometry::getHash() const {
    XmlSerializer s;
    s.setUseAttributes(true);
    serialize(s);

    std::stringstream stream;
    s.write(stream);
    return VoreenHash::getHash(stream.str());
}
Пример #11
0
void GeometrySave::saveFile() {
    XmlSerializer s;
    const Geometry* geometry = inport_.getData();
    s.serialize("Geometry", geometry);

    std::fstream stream(fileProp_.get().c_str(), std::ios::out);
    s.write(stream);
    stream.close();
}
Пример #12
0
void VolumeURLProperty::serialize(XmlSerializer& s) const {
    Property::serialize(s);

    std::string relativeURL;
    if (!value_.empty()) {
        std::string basePath = tgt::FileSystem::dirName(s.getDocumentPath());
        relativeURL = VolumeURL::convertURLToRelativePath(value_, basePath);
    }
    s.serialize("url", relativeURL);
}
Пример #13
0
void PropertyLink::serialize(XmlSerializer& s) const {
    // Serialize source property reference...
    s.serialize("SourceProperty", src_);

    // Serialize destination property reference...
    s.serialize("DestinationProperty", dest_);

    // Serialize link evaluator...
    s.serialize("Evaluator", evaluator_);
}
Пример #14
0
void PlotEntitiesProperty::serialize(XmlSerializer& s) const {
    Property::serialize(s);

    s.serialize("entities", static_cast<int>(entities_));
    s.serialize("xCI", xColumnIndex_);
    s.serialize("yCI", yColumnIndex_);
    s.serialize("colorMap", colorMap_);
    s.serialize("plotEntitySettingsVector", value_, "plotEntitySettings");
    s.serialize("loadStrategy",static_cast<int>(loadStrategy_));
}
Пример #15
0
void PlotCellValue::serialize(XmlSerializer& s) const {
    s.serialize("isValue", isValue());
    s.serialize("isTag", isTag());
    s.serialize("isHighlighted", isHighlighted());

    if (isTag())
        s.serialize("tag", getTag());
    if (isValue())
        s.serialize("value", getValue());
}
Пример #16
0
void Animation::serialize(XmlSerializer& s) const {
    if (!isEmpty()) {
        s.serialize("processors", processors_, "Processor");
        s.serialize("undoSteps", undoSteps_);
        s.serialize("fps", fps_);
        s.serialize("duration", duration_);
        s.serialize("currentTime", currentTime_);
        s.serialize("isRendering", isRendering_);
    }
}
Пример #17
0
/// Save the user configuration settings.
///
/// @return  True if the configuration was saved successfully, false if not.
bool ConfigPc::SaveUserConfig()
{
    HELIUM_TRACE( TRACE_INFO, TXT( "ConfigPc: Saving user configuration.\n" ) );

    Config& rConfig = Config::GetStaticInstance();

    Package* pConfigPackage = rConfig.GetUserConfigPackage();
    if( !pConfigPackage )
    {
        HELIUM_TRACE( TRACE_WARNING, TXT( "ConfigPc: No user configuration exists to save.\n" ) );

        return false;
    }

    Path userDataDirectory;
    if ( !File::GetUserDataDirectory( userDataDirectory ) )
    {
        HELIUM_TRACE( TRACE_WARNING, TXT( "ConfigPc: No user data directory could be determined.\n" ) );
        return false;
    }

    GameObjectPath configPackagePath = pConfigPackage->GetPath();

    Path packageFilePath( userDataDirectory + configPackagePath.ToFilePathString().GetData() + HELIUM_XML_PACKAGE_FILE_EXTENSION );

    HELIUM_TRACE( TRACE_INFO, TXT( "ConfigPc: Saving configuration to \"%s\".\n" ), *packageFilePath );

    XmlSerializer serializer;
    if( !serializer.Initialize( packageFilePath.c_str() ) )
    {
        HELIUM_TRACE(
            TRACE_ERROR,
            TXT( "ConfigPc: Failed to initialize package serializer for writing to \"%s\".\n" ),
            *packageFilePath );

        return false;
    }

    for( GameObject* pConfigObject = pConfigPackage->GetFirstChild();
         pConfigObject != NULL;
         pConfigObject = pConfigObject->GetNextSibling() )
    {
        if( !pConfigObject->IsPackage() )
        {
            RecursiveSerializeObject( serializer, pConfigObject );
        }
    }

    serializer.Shutdown();

    HELIUM_TRACE( TRACE_INFO, TXT( "ConfigPc: User configuration saved.\n" ) );

    return true;
}
Пример #18
0
void Workspace::serialize(XmlSerializer& s) const {
    s.serialize("version", version_);

    // Serialize network...
    s.serialize("ProcessorNetwork", network_);

    // Serialize animation...
    s.serialize("Animation", animation_);

    s.serialize("GlobalDescription", description_);
}
Пример #19
0
void TransFunc1DKeys::serialize(XmlSerializer& s) const {
    TransFunc::serialize(s);

    // serialize keys...
    s.serialize("Keys", keys_, "key");

    // serialize thresholds...
    s.serialize("lower", lowerThreshold_);
    s.serialize("upper", upperThreshold_);

    s.serialize("domain", domain_);
}
Пример #20
0
void DicomDict::serialize(XmlSerializer &s) const {
    //put DictEntries into a Vector
    std::vector<DicomDictEntry> entryVector;

    std::map<std::string,DicomDictEntry>::const_iterator it;
    for (it = entries_.begin(); it != entries_.end(); ++it) {
        entryVector.push_back(it->second);
    }

    //serialize this vector
    s.setUseAttributes(false);
    s.serialize("Dict", entryVector, "entry");
}
Пример #21
0
PropertyState::PropertyState(Property* prop) 
    : Serializable()
{
    propertyOwner_ = prop->getOwner()->getName();
    propertyName_ = prop->getGuiName();
    propertyID_ = prop->getID();

    XmlSerializer s;

    prop->serializeValue(s);

    std::stringstream stream;
    s.write(stream);
    propertyValue_ = stream.str();
}
Пример #22
0
void PropertyVector::serialize(XmlSerializer& s) const {
    Property::serialize(s);

    // serialize the properties of the processor
    typedef std::map<std::string, Property*> PropertyMapType;

    PropertyMapType propertyMap;
    for (std::vector<Property*>::const_iterator it = properties_.begin(); it != properties_.end(); ++it)
        propertyMap[(*it)->getID()] = *it;

    const bool usePointerContentSerialization = s.getUsePointerContentSerialization();
    s.setUsePointerContentSerialization(true);
    s.serialize("ElementProperties", propertyMap, "Property", "name");
    s.setUsePointerContentSerialization(usePointerContentSerialization);
}
Пример #23
0
/**
 * Tests that deserialization of not serialized data attempt
 * leads to an @c XmlSerializationNoSuchDataException.
 */
void testNoSuchDataException() {
    std::stringstream stream;

    XmlSerializer s;
    s.write(stream);

    XmlDeserializer d;
    d.read(stream);
    int i;
    try {
        d.deserialize("NotExistentKey", i);
        test(false, "No exception on deserialization of not existent key");
    }
    catch (XmlSerializationNoSuchDataException&) {
    }
}
Пример #24
0
void VolumeCollection::serialize(XmlSerializer& s) const {
    std::vector<VolumeHandle*> vhs;
    for (size_t i=0; i<volumeHandles_.size(); ++i) {
        if (dynamic_cast<VolumeHandle*>(volumeHandles_[i]))
            vhs.push_back(static_cast<VolumeHandle*>(volumeHandles_[i]));
    }
    s.serialize("VolumeHandles", vhs, "VolumeHandle");
}
Пример #25
0
void PropertyOwner::serialize(XmlSerializer& s) const {
    // create temporary property map for serialization
    std::map<std::string, Property*> propertyMap;
    for (std::vector<Property*>::const_iterator it = properties_.begin(); it != properties_.end(); ++it)
        propertyMap[(*it)->getID()] = *it;

    // serialize properties
    const bool usePointerContentSerialization = s.getUsePointerContentSerialization();
    s.setUsePointerContentSerialization(true);
    try {
        s.serialize("Properties", propertyMap, "Property", "name");
    }
    catch (SerializationException& e) {
        LWARNING(e.what());
    }
    s.setUsePointerContentSerialization(usePointerContentSerialization);
}
Пример #26
0
/**
 * Tests serialization and deserialization of graph with a cycle.
 */
void testCycle() {
    Node node1;
    Node node2;
    Node node3;
    node1.successor = &node2;
    node2.successor = &node3;
    node3.successor = &node1;
    node1.predecessor = &node3;
    node2.predecessor = &node1;
    node3.predecessor = &node2;

    std::stringstream stream;

    XmlSerializer s;
    s.serialize("tree", node1);
    s.write(stream);

    // ATTENTION: Since every successor and predecessor is deserialized as a pointer reference,
    //            therefore new memory is allocated for node2 and node3. This means that you
    //            cannot check pointer addresses to these objects. But, you can check whether
    //            an equivalent data tree is deserialized.

    // Reset all variables to default values...
    node1.successor = 0;
    node1.predecessor = 0;

    XmlDeserializer d;
    d.read(stream);
    d.deserialize("tree", node1);

    test(node1.successor != 0, "node1.successor still null");
    test(node1.predecessor != 0, "node1.predecessor still null");

    Node* pnode1 = &node1;
    Node* pnode2 = node1.successor;
    Node* pnode3 = node1.predecessor;

    test(pnode2->predecessor == pnode1, "node1 is not the predecessor of node2");
    test(pnode2->successor == pnode3, "node3 is not the successor of node2");
    test(pnode3->predecessor == pnode2, "node2 is not the predecessor of node3");
    test(pnode3->successor == pnode1, "node1 is not the successor of node3");

    delete pnode2;
    delete pnode3;
}
Пример #27
0
void Property::serialize(XmlSerializer& s) const {
    if(serializeValue_)
        return;

    if (guiName_ != initialGuiName_)
        s.serialize("guiName", guiName_);

    if (lod_ != USER)
        s.serialize("lod", lod_);

    for (std::set<PropertyWidget*>::const_iterator it = widgets_.begin(); it != widgets_.end(); ++it) {
        (*it)->updateMetaData();
        // FIXME What exactly is this supposed to do? The return value is not used... FL
        (*it)->getWidgetMetaData();
    }

    metaDataContainer_.serialize(s);
}
void MutualInformationRegistration::serialize(XmlSerializer& s) const {
    VolumeProcessor::serialize(s);

    ParametersType parameters = transform_->GetParameters();
    ParametersType fixedParameters = transform_->GetFixedParameters();

    std::vector<double> params;
    std::vector<double> fixedParams;

    for(size_t i=0; i<parameters.GetSize(); i++)
        params.push_back(parameters[i]);

    for(size_t i=0; i<fixedParameters.GetSize(); i++)
        fixedParams.push_back(fixedParameters[i]);

    s.serialize("parameters", params);
    s.serialize("fixedParameters", fixedParams);
}
Пример #29
0
void Processor::serialize(XmlSerializer& s) const {
    // meta data
    metaDataContainer_.serialize(s);

    // misc settings
    s.serialize("name", id_);

    // serialize properties
    PropertyOwner::serialize(s);


    // ---
    // the following entities are static resources (i.e. already existing at this point)
    // that should therefore not be dynamically created by the serializer
    //
    const bool usePointerContentSerialization = s.getUsePointerContentSerialization();
    s.setUsePointerContentSerialization(true);

    // serialize inports using a temporary map
    std::map<std::string, Port*> inportMap;
    for (std::vector<Port*>::const_iterator it = inports_.begin(); it != inports_.end(); ++it)
        inportMap[(*it)->getID()] = *it;
    try {
        s.serialize("Inports", inportMap, "Port", "name");
    }
    catch (SerializationException& e) {
        LWARNING(e.what());
    }

    // serialize outports using a temporary map
    std::map<std::string, Port*> outportMap;
    for (std::vector<Port*>::const_iterator it = outports_.begin(); it != outports_.end(); ++it)
        outportMap[(*it)->getID()] = *it;
    try {
        s.serialize("Outports", outportMap, "Port", "name");
    }
    catch (SerializationException& e) {
        LWARNING(e.what());
    }

    // serialize interaction handlers using a temporary map
    map<string, InteractionHandler*> handlerMap;
    const std::vector<InteractionHandler*>& handlers = getInteractionHandlers();
    for (vector<InteractionHandler*>::const_iterator it = handlers.begin(); it != handlers.end(); ++it)
        handlerMap[(*it)->getID()] = *it;
    try {
        s.serialize("InteractionHandlers", handlerMap, "Handler", "name");
    }
    catch (SerializationException& e) {
        LWARNING(e.what());
    }

    s.setUsePointerContentSerialization(usePointerContentSerialization);
    // --- static resources end ---

}
Пример #30
0
std::string Cache::getPropertyState() {
    // create temporary property map for serialization
    std::map<std::string, Property*> propertyMap;
    for (size_t i=0; i < properties_.size(); ++i) {
        Property* p = processor_->getProperty(properties_[i]);
        if(p)
            propertyMap[properties_[i]] = p;
    }

    // serialize properties
    XmlSerializer s;

    const bool usePointerContentSerialization = s.getUsePointerContentSerialization();
    s.setUsePointerContentSerialization(true);
    try {
        s.serialize("Properties", propertyMap, "Property", "name");
    }
    catch (SerializationException& e) {
        LWARNING(e.what());
    }
    s.setUsePointerContentSerialization(usePointerContentSerialization);

    std::stringstream stream;
    s.write(stream);
    return stream.str();
}