Commit a62018a2 authored by Mike Kremer's avatar Mike Kremer

Added deserialize function.

git-svn-id: http://www.openvolumemesh.org/svnrepo/OpenVolumeMesh/trunk@101 66977474-1d4b-4f09-8fe9-267525286df2
parent a3f0dbc8
/*===========================================================================*\
* *
* OpenVolumeMesh *
* Copyright (C) 2011 by Computer Graphics Group, RWTH Aachen *
* www.openvolumemesh.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenVolumeMesh. *
* *
* OpenVolumeMesh is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenVolumeMesh is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenVolumeMesh. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 36 $ *
* $Date: 2012-01-10 18:00:06 +0100 (Di, 10 Jan 2012) $ *
* $LastChangedBy: kremer $ *
* *
\*===========================================================================*/
#include "OpenVolumeMeshStatus.hh"
namespace OpenVolumeMesh {
std::ostream& operator<<(std::ostream& _ostr, const OpenVolumeMeshStatus& _status) {
_ostr << _status.selected() << " " << _status.tagged() << " " << _status.deleted() << std::endl;
return _ostr;
}
std::istream& operator>>(std::istream& _istr, OpenVolumeMeshStatus& _status) {
bool b = false;
_istr >> b;
_status.set_selected(b);
_istr >> b;
_status.set_tagged(b);
_istr >> b;
_status.set_deleted(b);
return _istr;
}
} // Namespace OpenVolumeMesh
......@@ -79,10 +79,9 @@ private:
bool deleted_;
};
inline std::ostream& operator<<(std::ostream& _ostr, const OpenVolumeMeshStatus& _status) {
_ostr << _status.selected() << " " << _status.tagged() << " " << _status.deleted() << std::endl;
return _ostr;
}
std::ostream& operator<<(std::ostream& _ostr, const OpenVolumeMeshStatus& _status);
std::istream& operator>>(std::istream& _istr, OpenVolumeMeshStatus& _status);
} // Namespace OpenVolumeMesh
......
......@@ -77,6 +77,8 @@ public:
virtual std::ostream& serialize(std::ostream& _ostr) const = 0;
virtual std::istream& deserialize(std::istream& _istr) = 0;
protected:
virtual void set_non_persistent() = 0;
......
......@@ -112,6 +112,14 @@ public:
return _ostr;
}
// Function to deserialize a property
virtual std::istream& deserialize(std::istream& _istr) {
std::string str;
_istr >> str;
name_ = str;
return _istr;
}
public:
// I/O support
......
......@@ -47,6 +47,7 @@
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cassert>
......@@ -147,6 +148,17 @@ public:
return _ostr;
}
// Function to deserialize a property
virtual std::istream& deserialize(std::istream& _istr) {
OpenVolumeMeshBaseProperty::deserialize(_istr);
for(unsigned int i = 0; i < n_elements(); ++i) {
value_type val;
_istr >> val;
data_[i] = val;
}
return _istr;
}
public:
// data access interface
......
......@@ -64,6 +64,7 @@ public:
VertexPropertyT(const std::string& _name, ResourceManager& _resMan, VertexPropHandle _handle);
~VertexPropertyT() {}
virtual std::ostream& serialize(std::ostream& _ostr) const;
virtual std::istream& deserialize(std::istream& _istr);
};
template<class T>
class EdgePropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, EdgePropHandle> {
......@@ -71,6 +72,7 @@ public:
EdgePropertyT(const std::string& _name, ResourceManager& _resMan, EdgePropHandle _handle);
~EdgePropertyT() {}
virtual std::ostream& serialize(std::ostream& _ostr) const;
virtual std::istream& deserialize(std::istream& _istr);
};
template<class T>
class HalfEdgePropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfEdgePropHandle> {
......@@ -78,6 +80,7 @@ public:
HalfEdgePropertyT(const std::string& _name, ResourceManager& _resMan, HalfEdgePropHandle _handle);
~HalfEdgePropertyT() {}
virtual std::ostream& serialize(std::ostream& _ostr) const;
virtual std::istream& deserialize(std::istream& _istr);
};
template<class T>
class FacePropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, FacePropHandle> {
......@@ -85,6 +88,7 @@ public:
FacePropertyT(const std::string& _name, ResourceManager& _resMan, FacePropHandle _handle);
~FacePropertyT() {}
virtual std::ostream& serialize(std::ostream& _ostr) const;
virtual std::istream& deserialize(std::istream& _istr);
};
template<class T>
class HalfFacePropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfFacePropHandle> {
......@@ -92,6 +96,7 @@ public:
HalfFacePropertyT(const std::string& _name, ResourceManager& _resMan, HalfFacePropHandle _handle);
~HalfFacePropertyT() {}
virtual std::ostream& serialize(std::ostream& _ostr) const;
virtual std::istream& deserialize(std::istream& _istr);
};
template<class T>
class CellPropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, CellPropHandle> {
......@@ -99,6 +104,7 @@ public:
CellPropertyT(const std::string& _name, ResourceManager& _resMan, CellPropHandle _handle);
~CellPropertyT() {}
virtual std::ostream& serialize(std::ostream& _ostr) const;
virtual std::istream& deserialize(std::istream& _istr);
};
template<class T>
class MeshPropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, MeshPropHandle> {
......@@ -106,6 +112,7 @@ public:
MeshPropertyT(const std::string& _name, ResourceManager& _resMan, MeshPropHandle _handle);
~MeshPropertyT() {}
virtual std::ostream& serialize(std::ostream& _ostr) const;
virtual std::istream& deserialize(std::istream& _istr);
};
} // Namespace OpenVolumeMesh
......
......@@ -56,11 +56,17 @@ VertexPropertyT<T>::VertexPropertyT(const std::string& _name, ResourceManager& _
template<class T>
std::ostream& VertexPropertyT<T>::serialize(std::ostream& _ostr) const {
_ostr << "VProp " << std::endl;
_ostr << "VProp" << std::endl;
_ostr << PropertyPtr<OpenVolumeMeshPropertyT<T>, VertexPropHandle>::h_->ptr_->serialize(_ostr);
return _ostr;
}
template<class T>
std::istream& VertexPropertyT<T>::deserialize(std::istream& _istr) {
PropertyPtr<OpenVolumeMeshPropertyT<T>, VertexPropHandle>::h_->ptr_->deserialize(_istr);
return _istr;
}
template<class T>
EdgePropertyT<T>::EdgePropertyT(const std::string& _name, ResourceManager& _resMan, EdgePropHandle _handle) :
PropertyPtr<OpenVolumeMeshPropertyT<T>, EdgePropHandle>(new OpenVolumeMeshPropertyT<T>(_name), _resMan, _handle) {
......@@ -69,11 +75,17 @@ EdgePropertyT<T>::EdgePropertyT(const std::string& _name, ResourceManager& _resM
template<class T>
std::ostream& EdgePropertyT<T>::serialize(std::ostream& _ostr) const {
_ostr << "EProp " << std::endl;
_ostr << "EProp" << std::endl;
_ostr << PropertyPtr<OpenVolumeMeshPropertyT<T>, EdgePropHandle>::h_->ptr_->serialize(_ostr);
return _ostr;
}
template<class T>
std::istream& EdgePropertyT<T>::deserialize(std::istream& _istr) {
PropertyPtr<OpenVolumeMeshPropertyT<T>, EdgePropHandle>::h_->ptr_->deserialize(_istr);
return _istr;
}
template<class T>
HalfEdgePropertyT<T>::HalfEdgePropertyT(const std::string& _name, ResourceManager& _resMan, HalfEdgePropHandle _handle) :
PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfEdgePropHandle>(new OpenVolumeMeshPropertyT<T>(_name), _resMan, _handle) {
......@@ -82,11 +94,17 @@ HalfEdgePropertyT<T>::HalfEdgePropertyT(const std::string& _name, ResourceManage
template<class T>
std::ostream& HalfEdgePropertyT<T>::serialize(std::ostream& _ostr) const {
_ostr << "HEProp " << std::endl;
_ostr << "HEProp" << std::endl;
_ostr << PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfEdgePropHandle>::h_->ptr_->serialize(_ostr);
return _ostr;
}
template<class T>
std::istream& HalfEdgePropertyT<T>::deserialize(std::istream& _istr) {
PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfEdgePropHandle>::h_->ptr_->deserialize(_istr);
return _istr;
}
template<class T>
FacePropertyT<T>::FacePropertyT(const std::string& _name, ResourceManager& _resMan, FacePropHandle _handle) :
PropertyPtr<OpenVolumeMeshPropertyT<T>, FacePropHandle>(new OpenVolumeMeshPropertyT<T>(_name), _resMan, _handle) {
......@@ -95,11 +113,17 @@ FacePropertyT<T>::FacePropertyT(const std::string& _name, ResourceManager& _resM
template<class T>
std::ostream& FacePropertyT<T>::serialize(std::ostream& _ostr) const {
_ostr << "FProp " << std::endl;
_ostr << "FProp" << std::endl;
_ostr << PropertyPtr<OpenVolumeMeshPropertyT<T>, FacePropHandle>::h_->ptr_->serialize(_ostr);
return _ostr;
}
template<class T>
std::istream& FacePropertyT<T>::deserialize(std::istream& _istr) {
PropertyPtr<OpenVolumeMeshPropertyT<T>, FacePropHandle>::h_->ptr_->deserialize(_istr);
return _istr;
}
template<class T>
HalfFacePropertyT<T>::HalfFacePropertyT(const std::string& _name, ResourceManager& _resMan, HalfFacePropHandle _handle) :
PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfFacePropHandle>(new OpenVolumeMeshPropertyT<T>(_name), _resMan, _handle) {
......@@ -108,11 +132,17 @@ HalfFacePropertyT<T>::HalfFacePropertyT(const std::string& _name, ResourceManage
template<class T>
std::ostream& HalfFacePropertyT<T>::serialize(std::ostream& _ostr) const {
_ostr << "HFProp " << std::endl;
_ostr << "HFProp" << std::endl;
_ostr << PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfFacePropHandle>::h_->ptr_->serialize(_ostr);
return _ostr;
}
template<class T>
std::istream& HalfFacePropertyT<T>::deserialize(std::istream& _istr) {
PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfFacePropHandle>::h_->ptr_->deserialize(_istr);
return _istr;
}
template<class T>
CellPropertyT<T>::CellPropertyT(const std::string& _name, ResourceManager& _resMan, CellPropHandle _handle) :
PropertyPtr<OpenVolumeMeshPropertyT<T>, CellPropHandle>(new OpenVolumeMeshPropertyT<T>(_name), _resMan, _handle) {
......@@ -121,11 +151,17 @@ CellPropertyT<T>::CellPropertyT(const std::string& _name, ResourceManager& _resM
template<class T>
std::ostream& CellPropertyT<T>::serialize(std::ostream& _ostr) const {
_ostr << "CProp " << std::endl;
_ostr << "CProp" << std::endl;
_ostr << PropertyPtr<OpenVolumeMeshPropertyT<T>, CellPropHandle>::h_->ptr_->serialize(_ostr);
return _ostr;
}
template<class T>
std::istream& CellPropertyT<T>::deserialize(std::istream& _istr) {
PropertyPtr<OpenVolumeMeshPropertyT<T>, CellPropHandle>::h_->ptr_->deserialize(_istr);
return _istr;
}
template<class T>
MeshPropertyT<T>::MeshPropertyT(const std::string& _name, ResourceManager& _resMan, MeshPropHandle _handle) :
PropertyPtr<OpenVolumeMeshPropertyT<T>, MeshPropHandle>(new OpenVolumeMeshPropertyT<T>(_name), _resMan, _handle) {
......@@ -134,9 +170,15 @@ MeshPropertyT<T>::MeshPropertyT(const std::string& _name, ResourceManager& _resM
template<class T>
std::ostream& MeshPropertyT<T>::serialize(std::ostream& _ostr) const {
_ostr << "MProp " << std::endl;
_ostr << "MProp" << std::endl;
_ostr << PropertyPtr<OpenVolumeMeshPropertyT<T>, MeshPropHandle>::h_->ptr_->serialize(_ostr);
return _ostr;
}
template<class T>
std::istream& MeshPropertyT<T>::deserialize(std::istream& _istr) {
PropertyPtr<OpenVolumeMeshPropertyT<T>, MeshPropHandle>::h_->ptr_->deserialize(_istr);
return _istr;
}
} // Namespace OpenVolumeMesh
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment