Added string serialization and deserialization methods

This commit is contained in:
Gianpaolo Palma 2017-11-27 13:26:15 +01:00
parent 38ca45f71d
commit 4cfb4c3744
2 changed files with 66 additions and 1 deletions

View File

@ -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<ATT_NAMES_DERIVED_CLASS::ATT_ARITY> 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<typename MESHTYPE>
//static void computeARequestedAttributesSetCompatibleWithMesh(const MESHTYPE& mesh,const PRIMITIVE_MODALITY_MASK,RenderingAtts<ATT_NAMES_DERIVED_CLASS>& rqatt)
//{
@ -330,6 +344,8 @@ namespace vcg
class InternalRendAtts : public RenderingAtts<INT_ATT_NAMES>
{
public:
typedef INT_ATT_NAMES AttName;
InternalRendAtts()
:RenderingAtts<INT_ATT_NAMES>()
{

View File

@ -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<typename MESH_TYPE,typename UNIQUE_VIEW_ID_TYPE, typename XX_GL_OPTIONS_DERIVED_TYPE> friend class NotThreadSafeGLMeshAttributesMultiViewerBOManager;