Added string serialization and deserialization methods
This commit is contained in:
parent
38ca45f71d
commit
4cfb4c3744
|
@ -217,6 +217,20 @@ namespace vcg
|
||||||
return res;
|
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>
|
//template<typename MESHTYPE>
|
||||||
//static void computeARequestedAttributesSetCompatibleWithMesh(const MESHTYPE& mesh,const PRIMITIVE_MODALITY_MASK,RenderingAtts<ATT_NAMES_DERIVED_CLASS>& rqatt)
|
//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>
|
class InternalRendAtts : public RenderingAtts<INT_ATT_NAMES>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
typedef INT_ATT_NAMES AttName;
|
||||||
|
|
||||||
InternalRendAtts()
|
InternalRendAtts()
|
||||||
:RenderingAtts<INT_ATT_NAMES>()
|
:RenderingAtts<INT_ATT_NAMES>()
|
||||||
{
|
{
|
||||||
|
|
|
@ -118,7 +118,6 @@ namespace vcg
|
||||||
return (*this);
|
return (*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void copyData(const RenderingModalityGLOptions& opts)
|
void copyData(const RenderingModalityGLOptions& opts)
|
||||||
{
|
{
|
||||||
|
@ -156,6 +155,9 @@ namespace vcg
|
||||||
class PerViewData : public GLMeshAttributesInfo
|
class PerViewData : public GLMeshAttributesInfo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
typedef GL_OPTIONS_DERIVED_TYPE GLOptionsType;
|
||||||
|
|
||||||
PerViewData()
|
PerViewData()
|
||||||
:_pmmask(),_intatts(PR_ARITY),_glopts(NULL)
|
:_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:
|
protected:
|
||||||
template<typename MESH_TYPE,typename UNIQUE_VIEW_ID_TYPE, typename XX_GL_OPTIONS_DERIVED_TYPE> friend class NotThreadSafeGLMeshAttributesMultiViewerBOManager;
|
template<typename MESH_TYPE,typename UNIQUE_VIEW_ID_TYPE, typename XX_GL_OPTIONS_DERIVED_TYPE> friend class NotThreadSafeGLMeshAttributesMultiViewerBOManager;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue