mirror of
https://github.com/NGSolve/netgen.git
synced 2025-01-12 22:20:35 +05:00
persistent archiving of pointers
This commit is contained in:
parent
633376972f
commit
f85b51496f
@ -3,6 +3,9 @@
|
||||
|
||||
// copied from netgen
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
namespace ngstd
|
||||
{
|
||||
|
||||
@ -57,6 +60,66 @@ namespace ngstd
|
||||
// { for (size_t j = 0; j < n; j++) { (*this) & str[j]; }; return *this; };
|
||||
// virtual Archive & operator & (char *& str) = 0;
|
||||
|
||||
|
||||
// archive a pointer ...
|
||||
|
||||
int cnt = 0;
|
||||
std::map<void*,int> ptr2nr;
|
||||
std::vector<void*> nr2ptr;
|
||||
|
||||
template <typename T>
|
||||
Archive & operator& (T *& p)
|
||||
{
|
||||
if (Output())
|
||||
{
|
||||
if (!p)
|
||||
{
|
||||
int m2 = -2;
|
||||
(*this) & m2;
|
||||
return *this;
|
||||
}
|
||||
auto pos = ptr2nr.find( (void*) p);
|
||||
if (pos == ptr2nr.end())
|
||||
{
|
||||
ptr2nr[p] = cnt;
|
||||
int m1 = -1;
|
||||
(*this) & m1;
|
||||
cnt++;
|
||||
(*this) & (*p);
|
||||
}
|
||||
else
|
||||
{
|
||||
(*this) & pos->second;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int nr;
|
||||
(*this) & nr;
|
||||
// cout << "in, got nr " << nr << endl;
|
||||
if (nr == -2)
|
||||
{
|
||||
p = nullptr;
|
||||
}
|
||||
else if (nr == -1)
|
||||
{
|
||||
p = new T;
|
||||
// cout << "create new ptr, p = " << p << endl;
|
||||
(*this) & *p;
|
||||
nr2ptr.push_back(p);
|
||||
}
|
||||
else
|
||||
{
|
||||
p = (T*)nr2ptr[nr];
|
||||
// cout << "reuse ptr " << nr << ": " << p << endl;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template <typename T>
|
||||
Archive & operator << (const T & t)
|
||||
{
|
||||
|
@ -1309,18 +1309,13 @@ namespace netgen
|
||||
archive & points;
|
||||
archive & surfelements;
|
||||
archive & volelements;
|
||||
archive & segments;
|
||||
archive & facedecoding;
|
||||
archive & materials & bcnames & cd2names;
|
||||
|
||||
if (archive.Input())
|
||||
{
|
||||
RebuildSurfaceElementLists();
|
||||
|
||||
for (int faceindex = 1; faceindex <= GetNFD(); faceindex++)
|
||||
{
|
||||
Array<SurfaceElementIndex> seia;
|
||||
GetSurfaceElementsOfFace (faceindex, seia);
|
||||
cout << "seia = " << seia.Size() << endl;
|
||||
}
|
||||
|
||||
CalcSurfacesOfNode ();
|
||||
if (ntasks == 1) // sequential run only
|
||||
|
@ -340,11 +340,7 @@ namespace netgen
|
||||
ngstd::Archive & DoArchive (ngstd::Archive & ar)
|
||||
{
|
||||
ar & x[0] & x[1] & x[2] & layer & singular;
|
||||
unsigned char _type;
|
||||
if (ar.Output())
|
||||
{ _type = type; ar & _type; }
|
||||
else
|
||||
{ ar & _type; type = POINTTYPE(_type); }
|
||||
ar & (unsigned char&)(type);
|
||||
return ar;
|
||||
}
|
||||
};
|
||||
@ -1053,8 +1049,20 @@ namespace netgen
|
||||
#else
|
||||
int GetPartition () const { return 0; }
|
||||
#endif
|
||||
ngstd::Archive & DoArchive (ngstd::Archive & ar)
|
||||
{
|
||||
return ar & pnums[0] & pnums[1] & pnums[2]
|
||||
& edgenr & singedge_left & singedge_right
|
||||
& si & cd2i & domin & domout & tlosurf
|
||||
& surfnr1 & surfnr2
|
||||
& bcname;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
inline ngstd::Archive & operator & (ngstd::Archive & archive, Segment & mp)
|
||||
{ return mp.DoArchive(archive); }
|
||||
|
||||
ostream & operator<<(ostream & s, const Segment & seg);
|
||||
|
||||
|
||||
@ -1146,9 +1154,9 @@ namespace netgen
|
||||
{
|
||||
return ar & surfnr & domin & domout & tlosurf & bcprop
|
||||
& surfcolour.X() & surfcolour.Y() & surfcolour.Z()
|
||||
// & bcname // how to do that ?
|
||||
// & firstelement // don't need it
|
||||
& bcname
|
||||
& domin_singular & domout_singular ;
|
||||
// don't need: firstelement
|
||||
}
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user