From 4cfb4c374436d0dfb1319d34fbca7d47f8c3b5b1 Mon Sep 17 00:00:00 2001 From: gianpaolopalma Date: Mon, 27 Nov 2017 13:26:15 +0100 Subject: [PATCH] Added string serialization and deserialization methods --- wrap/gl/gl_mesh_attributes_info.h | 16 ++++++ ..._mesh_attributes_multi_viewer_bo_manager.h | 51 ++++++++++++++++++- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/wrap/gl/gl_mesh_attributes_info.h b/wrap/gl/gl_mesh_attributes_info.h index 60d96fb1..21957db8 100644 --- a/wrap/gl/gl_mesh_attributes_info.h +++ b/wrap/gl/gl_mesh_attributes_info.h @@ -217,6 +217,20 @@ namespace vcg return res; } + size_t serialize(std::string& str) + { + for (unsigned int ii = 0; ii < ATT_NAMES_DERIVED_CLASS::enumArity(); ++ii) + str.append(((_atts[ii]) ? "1" : "0")); + return ATT_NAMES_DERIVED_CLASS::enumArity(); + } + + void deserialize(const std::string& str) + { + std::bitset bset(str); + for (unsigned int ii = 0; ii < ATT_NAMES_DERIVED_CLASS::enumArity(); ++ii) + _atts[ATT_NAMES_DERIVED_CLASS::enumArity() - ii - 1] = bset[ii]; + } + //template //static void computeARequestedAttributesSetCompatibleWithMesh(const MESHTYPE& mesh,const PRIMITIVE_MODALITY_MASK,RenderingAtts& rqatt) //{ @@ -330,6 +344,8 @@ namespace vcg class InternalRendAtts : public RenderingAtts { public: + typedef INT_ATT_NAMES AttName; + InternalRendAtts() :RenderingAtts() { diff --git a/wrap/gl/gl_mesh_attributes_multi_viewer_bo_manager.h b/wrap/gl/gl_mesh_attributes_multi_viewer_bo_manager.h index 3ead992c..e56470b2 100644 --- a/wrap/gl/gl_mesh_attributes_multi_viewer_bo_manager.h +++ b/wrap/gl/gl_mesh_attributes_multi_viewer_bo_manager.h @@ -118,7 +118,6 @@ namespace vcg return (*this); } - private: void copyData(const RenderingModalityGLOptions& opts) { @@ -156,6 +155,9 @@ namespace vcg class PerViewData : public GLMeshAttributesInfo { public: + + typedef GL_OPTIONS_DERIVED_TYPE GLOptionsType; + PerViewData() :_pmmask(),_intatts(PR_ARITY),_glopts(NULL) { @@ -260,6 +262,53 @@ namespace vcg } } + + void serialize(std::string& str) + { + str.append(_pmmask.to_string()); + for (typename PerRendModData::iterator it = _intatts.begin(); it != _intatts.end(); ++it) + { + std::string s; + it->serialize(s); + str.append(s); + } + std::string s; + _glopts->serialize(s); + str.append(s); + } + + bool deserialize(const std::string& str) + { + std::string::size_type pos = 0; + std::string token[6]; + token[0] = str.substr(pos, _pmmask.size()); + if (token[0].length() < _pmmask.size()) + return false; + int i = 1; + pos = _pmmask.size(); + for (typename PerRendModData::iterator it = _intatts.begin(); it != _intatts.end(); ++it, i++) + { + token[i] = str.substr(pos, InternalRendAtts::AttName::enumArity()); + if (token[i].length() < InternalRendAtts::AttName::enumArity()) + return false; + pos = pos + InternalRendAtts::AttName::enumArity(); + } + if (_glopts != NULL) + { + int size = _glopts->serialize(std::string()); + token[i] = str.substr(pos, size); + if (token[i].length() < size) + return false; + } + _pmmask = PRIMITIVE_MODALITY_MASK(token[0]); + i = 1; + for (typename PerRendModData::iterator it = _intatts.begin(); it != _intatts.end(); ++it, i++) + it->deserialize(token[i]); + if (_glopts != NULL) + _glopts->deserialize(token[i]); + return true; + } + protected: template friend class NotThreadSafeGLMeshAttributesMultiViewerBOManager;