|
@@ -51,12 +51,19 @@ namespace igl
|
|
|
|
|
|
template <typename T>
|
|
|
IGL_INLINE bool serialize(const T& obj,const std::string& objectName,std::vector<char>& buffer)
|
|
|
+ {
|
|
|
+ std::map<std::uintptr_t,IndexedPointerBase*> handler;
|
|
|
+ return serialize(obj,objectName,buffer,0,handler);
|
|
|
+ }
|
|
|
+
|
|
|
+ template <typename T>
|
|
|
+ IGL_INLINE bool serialize(const T& obj,const std::string& objectName,std::vector<char>& buffer,size_t offset,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap)
|
|
|
{
|
|
|
// serialize object data
|
|
|
size_t size = serialization::getByteSize(obj);
|
|
|
std::vector<char> tmp(size);
|
|
|
auto it = tmp.begin();
|
|
|
- serialization::serialize(obj,tmp,it);
|
|
|
+ serialization::serialize(obj,tmp,it,memoryMap);
|
|
|
|
|
|
std::string objectType(typeid(obj).name());
|
|
|
size_t newObjectSize = tmp.size();
|
|
@@ -69,9 +76,9 @@ namespace igl
|
|
|
std::vector<char>::iterator iter = buffer.begin()+curSize;
|
|
|
|
|
|
// serialize object header (name/type/size)
|
|
|
- serialization::serialize(objectName,buffer,iter);
|
|
|
- serialization::serialize(objectType,buffer,iter);
|
|
|
- serialization::serialize(newObjectSize,buffer,iter);
|
|
|
+ serialization::serialize(objectName,buffer,iter,memoryMap);
|
|
|
+ serialization::serialize(objectType,buffer,iter,memoryMap);
|
|
|
+ serialization::serialize(newObjectSize,buffer,iter,memoryMap);
|
|
|
|
|
|
// copy serialized data to buffer
|
|
|
iter = std::copy(tmp.begin(),tmp.end(),iter);
|
|
@@ -281,7 +288,7 @@ namespace igl
|
|
|
}
|
|
|
|
|
|
template <typename T>
|
|
|
- IGL_INLINE typename std::enable_if<!is_serializable<T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
|
|
|
+ IGL_INLINE typename std::enable_if<!is_serializable<T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap)
|
|
|
{
|
|
|
// data
|
|
|
std::vector<char> tmp;
|
|
@@ -289,7 +296,7 @@ namespace igl
|
|
|
|
|
|
// size
|
|
|
size_t size = buffer.size();
|
|
|
- serialization::serialize(tmp.size(),buffer,iter);
|
|
|
+ serialization::serialize(tmp.size(),buffer,iter,memoryMap);
|
|
|
size_t cur = iter - buffer.begin();
|
|
|
|
|
|
buffer.resize(size+tmp.size());
|
|
@@ -320,9 +327,9 @@ namespace igl
|
|
|
}
|
|
|
|
|
|
template <typename T>
|
|
|
- IGL_INLINE typename std::enable_if<std::is_fundamental<T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
|
|
|
+ IGL_INLINE typename std::enable_if<std::is_fundamental<T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap)
|
|
|
{
|
|
|
- //serialization::updateMemoryMap(obj,sizeof(T));
|
|
|
+ //serialization::updateMemoryMap(obj,sizeof(T),memoryMap);
|
|
|
const uint8_t* ptr = reinterpret_cast<const uint8_t*>(&obj);
|
|
|
iter = std::copy(ptr,ptr+sizeof(T),iter);
|
|
|
}
|
|
@@ -342,12 +349,12 @@ namespace igl
|
|
|
return getByteSize(obj.length())+obj.length()*sizeof(uint8_t);
|
|
|
}
|
|
|
|
|
|
- IGL_INLINE void serialize(const std::string& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
|
|
|
+ IGL_INLINE void serialize(const std::string& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap)
|
|
|
{
|
|
|
- serialization::serialize(obj.length(),buffer,iter);
|
|
|
+ serialization::serialize(obj.length(),buffer,iter,memoryMap);
|
|
|
for(const auto& cur : obj)
|
|
|
{
|
|
|
- serialization::serialize(cur,buffer,iter);
|
|
|
+ serialization::serialize(cur,buffer,iter,memoryMap);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -374,7 +381,7 @@ namespace igl
|
|
|
}
|
|
|
|
|
|
template <typename T>
|
|
|
- IGL_INLINE typename std::enable_if<std::is_base_of<SerializableBase,T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
|
|
|
+ IGL_INLINE typename std::enable_if<std::is_base_of<SerializableBase,T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap)
|
|
|
{
|
|
|
// data
|
|
|
std::vector<char> tmp;
|
|
@@ -382,7 +389,7 @@ namespace igl
|
|
|
|
|
|
// size
|
|
|
size_t size = buffer.size();
|
|
|
- serialization::serialize(tmp.size(),buffer,iter);
|
|
|
+ serialization::serialize(tmp.size(),buffer,iter,memoryMap);
|
|
|
size_t cur = iter - buffer.begin();
|
|
|
|
|
|
buffer.resize(size+tmp.size());
|
|
@@ -415,10 +422,10 @@ namespace igl
|
|
|
}
|
|
|
|
|
|
template <typename T1,typename T2>
|
|
|
- IGL_INLINE void serialize(const std::pair<T1,T2>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
|
|
|
+ IGL_INLINE void serialize(const std::pair<T1,T2>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap)
|
|
|
{
|
|
|
- serialization::serialize(obj.first,buffer,iter);
|
|
|
- serialization::serialize(obj.second,buffer,iter);
|
|
|
+ serialization::serialize(obj.first,buffer,iter,memoryMap);
|
|
|
+ serialization::serialize(obj.second,buffer,iter,memoryMap);
|
|
|
}
|
|
|
|
|
|
template <typename T1,typename T2>
|
|
@@ -437,13 +444,13 @@ namespace igl
|
|
|
}
|
|
|
|
|
|
template <typename T1,typename T2>
|
|
|
- IGL_INLINE void serialize(const std::vector<T1,T2>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
|
|
|
+ IGL_INLINE void serialize(const std::vector<T1,T2>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap)
|
|
|
{
|
|
|
size_t size = obj.size();
|
|
|
- serialization::serialize(size,buffer,iter);
|
|
|
+ serialization::serialize(size,buffer,iter,memoryMap);
|
|
|
for(const T1& cur : obj)
|
|
|
{
|
|
|
- serialization::serialize(cur,buffer,iter);
|
|
|
+ serialization::serialize(cur,buffer,iter,memoryMap);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -484,12 +491,12 @@ namespace igl
|
|
|
}
|
|
|
|
|
|
template <typename T>
|
|
|
- IGL_INLINE void serialize(const std::set<T>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
|
|
|
+ IGL_INLINE void serialize(const std::set<T>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap)
|
|
|
{
|
|
|
- serialization::serialize(obj.size(),buffer,iter);
|
|
|
+ serialization::serialize(obj.size(),buffer,iter,memoryMap);
|
|
|
for(const T& cur : obj)
|
|
|
{
|
|
|
- serialization::serialize(cur,buffer,iter);
|
|
|
+ serialization::serialize(cur,buffer,iter,memoryMap);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -517,12 +524,12 @@ namespace igl
|
|
|
}
|
|
|
|
|
|
template <typename T1,typename T2>
|
|
|
- IGL_INLINE void serialize(const std::map<T1,T2>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
|
|
|
+ IGL_INLINE void serialize(const std::map<T1,T2>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap)
|
|
|
{
|
|
|
- serialization::serialize(obj.size(),buffer,iter);
|
|
|
+ serialization::serialize(obj.size(),buffer,iter,memoryMap);
|
|
|
for(const auto& cur : obj)
|
|
|
{
|
|
|
- serialization::serialize(cur,buffer,iter);
|
|
|
+ serialization::serialize(cur,buffer,iter,memoryMap);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -550,10 +557,10 @@ namespace igl
|
|
|
}
|
|
|
|
|
|
template<typename T,int R,int C,int P,int MR,int MC>
|
|
|
- IGL_INLINE void serialize(const Eigen::Matrix<T,R,C,P,MR,MC>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
|
|
|
+ IGL_INLINE void serialize(const Eigen::Matrix<T,R,C,P,MR,MC>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap)
|
|
|
{
|
|
|
- serialization::serialize(obj.rows(),buffer,iter);
|
|
|
- serialization::serialize(obj.cols(),buffer,iter);
|
|
|
+ serialization::serialize(obj.rows(),buffer,iter,memoryMap);
|
|
|
+ serialization::serialize(obj.cols(),buffer,iter,memoryMap);
|
|
|
size_t size = sizeof(T)*obj.rows()*obj.cols();
|
|
|
auto ptr = reinterpret_cast<const uint8_t*>(obj.data());
|
|
|
iter = std::copy(ptr,ptr+size,iter);
|
|
@@ -581,19 +588,19 @@ namespace igl
|
|
|
}
|
|
|
|
|
|
template<typename T,int P,typename I>
|
|
|
- IGL_INLINE void serialize(const Eigen::SparseMatrix<T,P,I>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
|
|
|
+ IGL_INLINE void serialize(const Eigen::SparseMatrix<T,P,I>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap)
|
|
|
{
|
|
|
- serialization::serialize(obj.rows(),buffer,iter);
|
|
|
- serialization::serialize(obj.cols(),buffer,iter);
|
|
|
- serialization::serialize(obj.nonZeros(),buffer,iter);
|
|
|
+ serialization::serialize(obj.rows(),buffer,iter,memoryMap);
|
|
|
+ serialization::serialize(obj.cols(),buffer,iter,memoryMap);
|
|
|
+ serialization::serialize(obj.nonZeros(),buffer,iter,memoryMap);
|
|
|
|
|
|
for(int k=0;k<obj.outerSize();++k)
|
|
|
{
|
|
|
for(typename Eigen::SparseMatrix<T,P,I>::InnerIterator it(obj,k);it;++it)
|
|
|
{
|
|
|
- serialization::serialize(it.row(),buffer,iter);
|
|
|
- serialization::serialize(it.col(),buffer,iter);
|
|
|
- serialization::serialize(it.value(),buffer,iter);
|
|
|
+ serialization::serialize(it.row(),buffer,iter,memoryMap);
|
|
|
+ serialization::serialize(it.col(),buffer,iter,memoryMap);
|
|
|
+ serialization::serialize(it.value(),buffer,iter,memoryMap);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -636,12 +643,12 @@ namespace igl
|
|
|
}
|
|
|
|
|
|
template <typename T>
|
|
|
- IGL_INLINE typename std::enable_if<std::is_pointer<T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
|
|
|
+ IGL_INLINE typename std::enable_if<std::is_pointer<T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap)
|
|
|
{
|
|
|
- serialization::serialize(obj == nullptr,buffer,iter);
|
|
|
+ serialization::serialize(obj == nullptr,buffer,iter,memoryMap);
|
|
|
|
|
|
if(obj)
|
|
|
- serialization::serialize(*obj,buffer,iter);
|
|
|
+ serialization::serialize(*obj,buffer,iter,memoryMap);
|
|
|
}
|
|
|
|
|
|
template <typename T>
|
|
@@ -681,9 +688,9 @@ namespace igl
|
|
|
}
|
|
|
|
|
|
template <typename T>
|
|
|
- IGL_INLINE typename std::enable_if<serialization::is_smart_ptr<T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
|
|
|
+ IGL_INLINE typename std::enable_if<serialization::is_smart_ptr<T>::value>::type serialize(const T& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap)
|
|
|
{
|
|
|
- serialize(obj.get(),buffer,iter);
|
|
|
+ serialize(obj.get(),buffer,iter,memoryMap);
|
|
|
}
|
|
|
|
|
|
template <template<typename> class T0,typename T1>
|
|
@@ -712,7 +719,7 @@ namespace igl
|
|
|
}
|
|
|
|
|
|
template <typename T>
|
|
|
- IGL_INLINE void serialize(const std::weak_ptr<T>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter)
|
|
|
+ IGL_INLINE void serialize(const std::weak_ptr<T>& obj,std::vector<char>& buffer,std::vector<char>::iterator& iter,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap)
|
|
|
{
|
|
|
|
|
|
}
|
|
@@ -739,7 +746,7 @@ namespace igl
|
|
|
// helper functions
|
|
|
|
|
|
template <typename T>
|
|
|
- IGL_INLINE void updateMemoryMap(T& obj,size_t size)
|
|
|
+ IGL_INLINE void updateMemoryMap(T& obj,size_t size,std::map<std::uintptr_t,IndexedPointerBase*>& memoryMap)
|
|
|
{
|
|
|
// check if object is already serialized
|
|
|
auto startPtr = new IndexedPointer<T>();
|