Cleaned up indentation to be readable again

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@586 fdac6126-5c0c-442c-9429-916003d36597
This commit is contained in:
Jan Möbius
2012-05-22 09:15:15 +00:00
parent 399f63279d
commit b1dfc57365
2 changed files with 153 additions and 247 deletions

View File

@@ -62,14 +62,14 @@ namespace OMFormat {
Chunk::Integer_Size needed_bits( size_t s ) Chunk::Integer_Size needed_bits( size_t s )
{ {
if (s <= 0x000100) return Chunk::Integer_8; if (s <= 0x000100) return Chunk::Integer_8;
if (s <= 0x010000) return Chunk::Integer_16; if (s <= 0x010000) return Chunk::Integer_16;
#if 0 #if 0
// !Not tested yet! This most probably won't work! // !Not tested yet! This most probably won't work!
// NEED a 64bit system! // NEED a 64bit system!
if ( (sizeof( size_t ) == 8) && (s >= 0x100000000) ) if ( (sizeof( size_t ) == 8) && (s >= 0x100000000) )
return Chunk::Integer_64; return Chunk::Integer_64;
#endif #endif
return Chunk::Integer_32; return Chunk::Integer_32;

View File

@@ -82,24 +82,18 @@ _OMReader_::_OMReader_()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool bool _OMReader_::read(const std::string& _filename, BaseImporter& _bi, Options& _opt)
_OMReader_::read(const std::string& _filename,
BaseImporter& _bi,
Options& _opt)
{ {
// check whether importer can give us an OpenMesh BaseKernel // check whether importer can give us an OpenMesh BaseKernel
if (!_bi.kernel()) return false; if (!_bi.kernel())
return false;
_opt += Options::Binary; // only binary format supported! _opt += Options::Binary; // only binary format supported!
// Open file // Open file
std::ifstream ifs( _filename.c_str(), std::ios::binary ); std::ifstream ifs(_filename.c_str(), std::ios::binary);
if (!ifs.is_open() || !ifs.good()) if (!ifs.is_open() || !ifs.good()) {
{ omerr() << "[OMReader] : cannot not open file " << _filename << std::endl;
omerr() << "[OMReader] : cannot not open file "
<< _filename
<< std::endl;
return false; return false;
} }
@@ -115,28 +109,24 @@ _OMReader_::read(const std::string& _filename,
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool bool _OMReader_::read(std::istream& _is, BaseImporter& _bi, Options& _opt)
_OMReader_::read(std::istream& _is,
BaseImporter& _bi,
Options& _opt)
{ {
// check whether importer can give us an OpenMesh BaseKernel // check whether importer can give us an OpenMesh BaseKernel
if (!_bi.kernel()) return false; if (!_bi.kernel())
return false;
_opt += Options::Binary; // only binary format supported! _opt += Options::Binary; // only binary format supported!
if (!_is.good()) if (!_is.good()) {
{ omerr() << "[OMReader] : cannot read from stream " << std::endl;
omerr() << "[OMReader] : cannot read from stream "
<< std::endl;
return false; return false;
} }
// Pass stream to read method, remember result // Pass stream to read method, remember result
bool result = read_binary(_is, _bi, _opt); bool result = read_binary(_is, _bi, _opt);
if(result) _opt += Options::Binary; if (result)
_opt += Options::Binary;
return result; return result;
} }
@@ -145,9 +135,7 @@ _OMReader_::read(std::istream& _is,
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool bool _OMReader_::read_ascii(std::istream& /* _is */, BaseImporter& /* _bi */, Options& /* _opt */) const
_OMReader_::read_ascii( std::istream& /* _is */, BaseImporter& /* _bi */,
Options& /* _opt */) const
{ {
// not supported yet! // not supported yet!
return false; return false;
@@ -156,60 +144,55 @@ _OMReader_::read_ascii( std::istream& /* _is */, BaseImporter& /* _bi */,
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool bool _OMReader_::read_binary(std::istream& _is, BaseImporter& _bi, Options& _opt) const
_OMReader_::read_binary( std::istream& _is, BaseImporter& _bi,
Options& _opt) const
{ {
bool swap = _opt.check(Options::Swap) || (Endian::local() == Endian::MSB); bool swap = _opt.check(Options::Swap) || (Endian::local() == Endian::MSB);
// intialize byte counter // Initialize byte counter
bytes_ = 0; bytes_ = 0;
bytes_ += restore( _is, header_, swap ); bytes_ += restore(_is, header_, swap);
size_t data_bytes; size_t data_bytes;
while( !_is.eof() ) while (!_is.eof()) {
{ bytes_ += restore(_is, chunk_header_, swap);
bytes_ += restore( _is, chunk_header_, swap );
if ( _is.eof() ) if (_is.eof())
break; break;
// Is this a named property restore the name // Is this a named property restore the name
if ( chunk_header_.name_ ) if (chunk_header_.name_) {
{
OMFormat::Chunk::PropertyName pn; OMFormat::Chunk::PropertyName pn;
bytes_ += restore( _is, property_name_, swap ); bytes_ += restore(_is, property_name_, swap);
} }
// Read in the property data. If it is an anonymous or unknown named // Read in the property data. If it is an anonymous or unknown named
// property, then skip data. // property, then skip data.
data_bytes = bytes_; data_bytes = bytes_;
switch( chunk_header_.entity_ ) switch (chunk_header_.entity_) {
{
case OMFormat::Chunk::Entity_Vertex: case OMFormat::Chunk::Entity_Vertex:
if (!read_binary_vertex_chunk( _is, _bi, _opt, swap )) if (!read_binary_vertex_chunk(_is, _bi, _opt, swap))
return false; return false;
break; break;
case OMFormat::Chunk::Entity_Face: case OMFormat::Chunk::Entity_Face:
if (!read_binary_face_chunk( _is, _bi, _opt, swap )) if (!read_binary_face_chunk(_is, _bi, _opt, swap))
return false; return false;
break; break;
case OMFormat::Chunk::Entity_Edge: case OMFormat::Chunk::Entity_Edge:
if (!read_binary_edge_chunk( _is, _bi, _opt, swap )) if (!read_binary_edge_chunk(_is, _bi, _opt, swap))
return false; return false;
break; break;
case OMFormat::Chunk::Entity_Halfedge: case OMFormat::Chunk::Entity_Halfedge:
if (!read_binary_halfedge_chunk( _is, _bi, _opt, swap )) if (!read_binary_halfedge_chunk(_is, _bi, _opt, swap))
return false; return false;
break; break;
case OMFormat::Chunk::Entity_Mesh: case OMFormat::Chunk::Entity_Mesh:
if (!read_binary_mesh_chunk( _is, _bi, _opt, swap )) if (!read_binary_mesh_chunk(_is, _bi, _opt, swap))
return false; return false;
break; break;
default: default:
return false; return false;
} }
data_bytes = bytes_ - data_bytes; data_bytes = bytes_ - data_bytes;
} }
@@ -221,15 +204,13 @@ _OMReader_::read_binary( std::istream& _is, BaseImporter& _bi,
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool bool _OMReader_::can_u_read(const std::string& _filename) const
_OMReader_::can_u_read(const std::string& _filename) const
{ {
// !!! Assuming BaseReader::can_u_parse( std::string& ) // !!! Assuming BaseReader::can_u_parse( std::string& )
// does not call BaseReader::read_magic()!!! // does not call BaseReader::read_magic()!!!
if ( this->BaseReader::can_u_read( _filename ) ) if (this->BaseReader::can_u_read(_filename)) {
{ std::ifstream ifile(_filename.c_str());
std::ifstream ifile( _filename.c_str() ); if (ifile && can_u_read(ifile))
if ( ifile && can_u_read( ifile ) )
return true; return true;
} }
return false; return false;
@@ -237,32 +218,29 @@ _OMReader_::can_u_read(const std::string& _filename) const
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool bool _OMReader_::can_u_read(std::istream& _is) const
_OMReader_::can_u_read(std::istream& _is) const
{ {
std::vector<char> evt; std::vector<char> evt;
evt.reserve(20); evt.reserve(20);
// read first 4 characters into a buffer // read first 4 characters into a buffer
while( evt.size() < 4 ) while (evt.size() < 4)
evt.push_back( static_cast<char>(_is.get()) ); evt.push_back(static_cast<char>(_is.get()));
// put back all read characters // put back all read characters
std::vector<char>::reverse_iterator it = evt.rbegin(); std::vector<char>::reverse_iterator it = evt.rbegin();
while (it != evt.rend() ) while (it != evt.rend())
_is.putback( *it++ ); _is.putback(*it++);
// evaluate header information // evaluate header information
OMFormat::Header *hdr = (OMFormat::Header*)&evt[0]; OMFormat::Header *hdr = (OMFormat::Header*) &evt[0];
// first two characters must be 'OM' // first two characters must be 'OM'
if (hdr->magic_[0] != 'O' || hdr->magic_[1] != 'M') if (hdr->magic_[0] != 'O' || hdr->magic_[1] != 'M')
return false; return false;
// 3rd characters defines the mesh type: // 3rd characters defines the mesh type:
switch(hdr->mesh_) switch (hdr->mesh_) {
{
case 'T': // Triangle Mesh case 'T': // Triangle Mesh
case 'Q': // Quad Mesh case 'Q': // Quad Mesh
case 'P': // Polygonal Mesh case 'P': // Polygonal Mesh
@@ -272,13 +250,12 @@ _OMReader_::can_u_read(std::istream& _is) const
} }
// 4th characters encodes the version // 4th characters encodes the version
return supports( hdr->version_ ); return supports(hdr->version_);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool bool _OMReader_::supports(const OMFormat::uint8 /* version */) const
_OMReader_::supports( const OMFormat::uint8 /* version */ ) const
{ {
return true; return true;
} }
@@ -286,82 +263,64 @@ _OMReader_::supports( const OMFormat::uint8 /* version */ ) const
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool bool _OMReader_::read_binary_vertex_chunk(std::istream &_is, BaseImporter &_bi, Options &_opt, bool _swap) const
_OMReader_::read_binary_vertex_chunk( std::istream &_is,
BaseImporter &_bi,
Options &_opt,
bool _swap) const
{ {
using OMFormat::Chunk; using OMFormat::Chunk;
assert( chunk_header_.entity_ == Chunk::Entity_Vertex ); assert( chunk_header_.entity_ == Chunk::Entity_Vertex);
OpenMesh::Vec3f v3f; OpenMesh::Vec3f v3f;
OpenMesh::Vec2f v2f; OpenMesh::Vec2f v2f;
OpenMesh::Vec3uc v3uc; // rgb OpenMesh::Vec3uc v3uc; // rgb
OMFormat::Chunk::PropertyName custom_prop; OMFormat::Chunk::PropertyName custom_prop;
size_t vidx=0; size_t vidx = 0;
switch (chunk_header_.type_) switch (chunk_header_.type_) {
{
case Chunk::Type_Pos: case Chunk::Type_Pos:
assert( OMFormat::dimensions(chunk_header_) assert( OMFormat::dimensions(chunk_header_) == size_t(OpenMesh::Vec3f::dim()));
== size_t(OpenMesh::Vec3f::dim()) );
for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx) for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx) {
{ bytes_ += vector_restore(_is, v3f, _swap);
bytes_ += vector_restore( _is, v3f, _swap ); _bi.add_vertex(v3f);
_bi.add_vertex(v3f);
} }
break; break;
case Chunk::Type_Normal: case Chunk::Type_Normal:
assert( OMFormat::dimensions(chunk_header_) assert( OMFormat::dimensions(chunk_header_) == size_t(OpenMesh::Vec3f::dim()));
== size_t(OpenMesh::Vec3f::dim()) );
_opt += Options::VertexNormal; _opt += Options::VertexNormal;
for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx) for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx) {
{ bytes_ += vector_restore(_is, v3f, _swap);
bytes_ += vector_restore( _is, v3f, _swap ); _bi.set_normal(VertexHandle(vidx), v3f);
_bi.set_normal(VertexHandle(vidx), v3f);
} }
break; break;
case Chunk::Type_Texcoord: case Chunk::Type_Texcoord:
assert( OMFormat::dimensions(chunk_header_) assert( OMFormat::dimensions(chunk_header_) == size_t(OpenMesh::Vec2f::dim()));
== size_t(OpenMesh::Vec2f::dim()) );
_opt += Options::VertexTexCoord; _opt += Options::VertexTexCoord;
for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx) for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx) {
{ bytes_ += vector_restore(_is, v2f, _swap);
bytes_ += vector_restore( _is, v2f, _swap ); _bi.set_texcoord(VertexHandle(vidx), v2f);
_bi.set_texcoord(VertexHandle(vidx), v2f);
} }
break; break;
case Chunk::Type_Color: case Chunk::Type_Color:
assert( OMFormat::dimensions(chunk_header_) == 3 ); assert( OMFormat::dimensions(chunk_header_) == 3);
_opt += Options::VertexColor; _opt += Options::VertexColor;
for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx) for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx) {
{ bytes_ += vector_restore(_is, v3uc, _swap);
bytes_ += vector_restore( _is, v3uc, _swap ); _bi.set_color(VertexHandle(vidx), v3uc);
_bi.set_color( VertexHandle(vidx), v3uc );
} }
break; break;
case Chunk::Type_Custom: case Chunk::Type_Custom:
bytes_ += bytes_ += restore_binary_custom_data(_is, _bi.kernel()->_get_vprop(property_name_), header_.n_vertices_, _swap);
restore_binary_custom_data( _is,
_bi.kernel()->_get_vprop( property_name_ ),
header_.n_vertices_,
_swap );
vidx = header_.n_vertices_; vidx = header_.n_vertices_;
@@ -370,9 +329,8 @@ _OMReader_::read_binary_vertex_chunk( std::istream &_is,
default: // skip unknown chunks default: // skip unknown chunks
{ {
omerr() << "Unknown chunk type ignored!\n"; omerr() << "Unknown chunk type ignored!\n";
size_t size_of = header_.n_vertices_ size_t size_of = header_.n_vertices_ * OMFormat::vector_size(chunk_header_);
* OMFormat::vector_size(chunk_header_); _is.ignore(size_of);
_is.ignore( size_of );
bytes_ += size_of; bytes_ += size_of;
} }
} }
@@ -384,88 +342,71 @@ _OMReader_::read_binary_vertex_chunk( std::istream &_is,
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool bool _OMReader_::read_binary_face_chunk(std::istream &_is, BaseImporter &_bi, Options &_opt, bool _swap) const
_OMReader_::read_binary_face_chunk( std::istream &_is,
BaseImporter &_bi,
Options &_opt,
bool _swap ) const
{ {
using OMFormat::Chunk; using OMFormat::Chunk;
assert( chunk_header_.entity_ == Chunk::Entity_Face ); assert( chunk_header_.entity_ == Chunk::Entity_Face);
size_t fidx=0; size_t fidx = 0;
OpenMesh::Vec3f v3f; // normal OpenMesh::Vec3f v3f; // normal
OpenMesh::Vec3uc v3uc; // rgb OpenMesh::Vec3uc v3uc; // rgb
switch( chunk_header_.type_ ) switch (chunk_header_.type_) {
{ case Chunk::Type_Topology: {
case Chunk::Type_Topology: BaseImporter::VHandles vhandles;
{ size_t nV = 0;
BaseImporter::VHandles vhandles; size_t vidx = 0;
size_t nV = 0;
size_t vidx = 0;
switch( header_.mesh_ ) switch (header_.mesh_) {
{ case 'T':
case 'T': nV = 3; break; nV = 3;
case 'Q': nV = 4; break; break;
case 'Q':
nV = 4;
break;
} }
for (; fidx < header_.n_faces_; ++fidx) for (; fidx < header_.n_faces_; ++fidx) {
{ if (header_.mesh_ == 'P')
if ( header_.mesh_ == 'P' ) bytes_ += restore(_is, nV, Chunk::Integer_16, _swap);
bytes_ += restore( _is, nV, Chunk::Integer_16, _swap );
vhandles.clear(); vhandles.clear();
for (size_t j=0; j<nV; ++j) for (size_t j = 0; j < nV; ++j) {
{ bytes_ += restore(_is, vidx, Chunk::Integer_Size(chunk_header_.bits_), _swap);
bytes_ += restore( _is, vidx,
Chunk::Integer_Size(chunk_header_.bits_),
_swap );
vhandles.push_back(VertexHandle(vidx)); vhandles.push_back(VertexHandle(vidx));
} }
_bi.add_face(vhandles); _bi.add_face(vhandles);
} }
} }
break;
case Chunk::Type_Normal:
assert( OMFormat::dimensions(chunk_header_)
== size_t(OpenMesh::Vec3f::dim()) );
_opt += Options::FaceNormal;
for (; fidx < header_.n_faces_ && !_is.eof(); ++fidx)
{
bytes_ += vector_restore( _is, v3f, _swap );
_bi.set_normal(FaceHandle(fidx), v3f);
}
break; break;
case Chunk::Type_Normal:
assert( OMFormat::dimensions(chunk_header_) == size_t(OpenMesh::Vec3f::dim()));
_opt += Options::FaceNormal;
for (; fidx < header_.n_faces_ && !_is.eof(); ++fidx) {
bytes_ += vector_restore(_is, v3f, _swap);
_bi.set_normal(FaceHandle(fidx), v3f);
}
break;
case Chunk::Type_Color: case Chunk::Type_Color:
assert( OMFormat::dimensions(chunk_header_) == 3 ); assert( OMFormat::dimensions(chunk_header_) == 3);
_opt += Options::FaceColor; _opt += Options::FaceColor;
for (; fidx < header_.n_faces_ && !_is.eof(); ++fidx) for (; fidx < header_.n_faces_ && !_is.eof(); ++fidx) {
{ bytes_ += vector_restore(_is, v3uc, _swap);
bytes_ += vector_restore( _is, v3uc, _swap ); _bi.set_color(FaceHandle(fidx), v3uc);
_bi.set_color( FaceHandle(fidx), v3uc );
} }
break; break;
case Chunk::Type_Custom: case Chunk::Type_Custom:
bytes_ += bytes_ += restore_binary_custom_data(_is, _bi.kernel()->_get_fprop(property_name_), header_.n_faces_, _swap);
restore_binary_custom_data( _is,
_bi.kernel()->_get_fprop( property_name_ ),
header_.n_faces_,
_swap );
fidx = header_.n_faces_; fidx = header_.n_faces_;
@@ -475,7 +416,7 @@ _OMReader_::read_binary_face_chunk( std::istream &_is,
{ {
omerr() << "Unknown chunk type ignore!\n"; omerr() << "Unknown chunk type ignore!\n";
size_t size_of = OMFormat::chunk_data_size(header_, chunk_header_); size_t size_of = OMFormat::chunk_data_size(header_, chunk_header_);
_is.ignore( size_of ); _is.ignore(size_of);
bytes_ += size_of; bytes_ += size_of;
} }
} }
@@ -485,34 +426,25 @@ _OMReader_::read_binary_face_chunk( std::istream &_is,
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool bool _OMReader_::read_binary_edge_chunk(std::istream &_is, BaseImporter &_bi, Options &/*_opt */, bool _swap) const
_OMReader_::read_binary_edge_chunk( std::istream &_is,
BaseImporter &_bi,
Options &/*_opt */,
bool _swap ) const
{ {
using OMFormat::Chunk; using OMFormat::Chunk;
assert( chunk_header_.entity_ == Chunk::Entity_Edge ); assert( chunk_header_.entity_ == Chunk::Entity_Edge);
size_t b=bytes_; size_t b = bytes_;
switch( chunk_header_.type_ ) switch (chunk_header_.type_) {
{
case Chunk::Type_Custom: case Chunk::Type_Custom:
bytes_ += bytes_ += restore_binary_custom_data(_is, _bi.kernel()->_get_eprop(property_name_), header_.n_edges_, _swap);
restore_binary_custom_data( _is,
_bi.kernel()->_get_eprop( property_name_ ),
header_.n_edges_,
_swap );
break; break;
default: default:
// skip unknown type // skip unknown type
size_t size_of = OMFormat::chunk_data_size(header_, chunk_header_); size_t size_of = OMFormat::chunk_data_size(header_, chunk_header_);
_is.ignore( size_of ); _is.ignore(size_of);
bytes_ += size_of; bytes_ += size_of;
} }
@@ -522,34 +454,25 @@ _OMReader_::read_binary_edge_chunk( std::istream &_is,
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool bool _OMReader_::read_binary_halfedge_chunk(std::istream &_is, BaseImporter &_bi, Options &/* _opt */, bool _swap) const
_OMReader_::read_binary_halfedge_chunk( std::istream &_is,
BaseImporter &_bi,
Options &/* _opt */,
bool _swap ) const
{ {
using OMFormat::Chunk; using OMFormat::Chunk;
assert( chunk_header_.entity_ == Chunk::Entity_Halfedge ); assert( chunk_header_.entity_ == Chunk::Entity_Halfedge);
size_t b = bytes_; size_t b = bytes_;
switch( chunk_header_.type_ ) switch (chunk_header_.type_) {
{
case Chunk::Type_Custom: case Chunk::Type_Custom:
bytes_ += bytes_ += restore_binary_custom_data(_is, _bi.kernel()->_get_hprop(property_name_), 2 * header_.n_edges_, _swap);
restore_binary_custom_data( _is,
_bi.kernel()->_get_hprop( property_name_ ),
2*header_.n_edges_,
_swap );
break; break;
default: default:
// skip unknown chunk // skip unknown chunk
omerr() << "Unknown chunk type ignored!\n"; omerr() << "Unknown chunk type ignored!\n";
size_t size_of = OMFormat::chunk_data_size(header_, chunk_header_); size_t size_of = OMFormat::chunk_data_size(header_, chunk_header_);
_is.ignore( size_of ); _is.ignore(size_of);
bytes_ += size_of; bytes_ += size_of;
} }
@@ -559,34 +482,25 @@ _OMReader_::read_binary_halfedge_chunk( std::istream &_is,
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool bool _OMReader_::read_binary_mesh_chunk(std::istream &_is, BaseImporter &_bi, Options & /* _opt */, bool _swap) const
_OMReader_::read_binary_mesh_chunk( std::istream &_is,
BaseImporter &_bi,
Options & /* _opt */,
bool _swap ) const
{ {
using OMFormat::Chunk; using OMFormat::Chunk;
assert( chunk_header_.entity_ == Chunk::Entity_Mesh ); assert( chunk_header_.entity_ == Chunk::Entity_Mesh);
size_t b = bytes_; size_t b = bytes_;
switch( chunk_header_.type_ ) switch (chunk_header_.type_) {
{
case Chunk::Type_Custom: case Chunk::Type_Custom:
bytes_ += bytes_ += restore_binary_custom_data(_is, _bi.kernel()->_get_mprop(property_name_), 1, _swap);
restore_binary_custom_data( _is,
_bi.kernel()->_get_mprop( property_name_ ),
1,
_swap );
break; break;
default: default:
// skip unknown chunk // skip unknown chunk
size_t size_of = OMFormat::chunk_data_size(header_, chunk_header_); size_t size_of = OMFormat::chunk_data_size(header_, chunk_header_);
_is.ignore( size_of ); _is.ignore(size_of);
bytes_ += size_of; bytes_ += size_of;
} }
@@ -597,53 +511,45 @@ _OMReader_::read_binary_mesh_chunk( std::istream &_is,
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
size_t size_t _OMReader_::restore_binary_custom_data(std::istream& _is, BaseProperty* _bp, size_t _n_elem, bool _swap) const
_OMReader_::restore_binary_custom_data( std::istream& _is, BaseProperty* _bp,
size_t _n_elem, bool _swap) const
{ {
assert( !_bp || (_bp->name() == property_name_) ); assert( !_bp || (_bp->name() == property_name_));
using OMFormat::Chunk; using OMFormat::Chunk;
size_t bytes = 0; size_t bytes = 0;
Chunk::esize_t block_size; Chunk::esize_t block_size;
Chunk::PropertyName custom_prop; Chunk::PropertyName custom_prop;
bytes += binary<Chunk::esize_t>::restore( _is, block_size, _swap ); bytes += binary<Chunk::esize_t>::restore(_is, block_size, _swap);
if (_bp) {
size_t n_bytes = _bp->size_of(_n_elem);
if ( _bp ) if (((n_bytes == BaseProperty::UnknownSize) || (n_bytes == block_size))
{ && (_bp->element_size() == BaseProperty::UnknownSize || (_n_elem * _bp->element_size() == block_size))) {
size_t n_bytes = _bp->size_of( _n_elem );
if ( ((n_bytes == BaseProperty::UnknownSize) || (n_bytes == block_size)) &&
(_bp->element_size() == BaseProperty::UnknownSize ||
(_n_elem * _bp->element_size() == block_size) ) )
{
#if defined(OM_DEBUG) #if defined(OM_DEBUG)
size_t b; size_t b;
bytes += (b=_bp->restore( _is, _swap )); bytes += (b=_bp->restore( _is, _swap ));
#else #else
bytes += _bp->restore( _is, _swap ); bytes += _bp->restore(_is, _swap);
#endif #endif
#if defined(OM_DEBUG) #if defined(OM_DEBUG)
assert( block_size == b ); assert( block_size == b );
#endif #endif
assert( block_size == _bp->size_of() );
assert( block_size == _bp->size_of());
block_size = 0; block_size = 0;
} } else {
else omerr() << "Warning! Property " << _bp->name() << " not loaded: " << "Mismatching data sizes!n";
{
omerr() << "Warning! Property " << _bp->name() << " not loaded: "
<< "Mismatching data sizes!n";
} }
} }
if (block_size) if (block_size) {
{ _is.ignore(block_size);
_is.ignore( block_size ); bytes += block_size;
bytes += block_size;
} }
return bytes; return bytes;