little tuning of mesh pickling

This commit is contained in:
Joachim Schoeberl 2021-06-24 07:37:53 +02:00
parent e0f3ce9cf0
commit 971d6bb465
2 changed files with 19 additions and 1 deletions

View File

@ -153,6 +153,7 @@ namespace ngcore
virtual void NeedsVersion(const std::string& /*unused*/, const std::string& /*unused*/) {} virtual void NeedsVersion(const std::string& /*unused*/, const std::string& /*unused*/) {}
// Pure virtual functions that have to be implemented by In-/OutArchive // Pure virtual functions that have to be implemented by In-/OutArchive
virtual Archive & operator & (std::byte & d) = 0;
virtual Archive & operator & (float & d) = 0; virtual Archive & operator & (float & d) = 0;
virtual Archive & operator & (double & d) = 0; virtual Archive & operator & (double & d) = 0;
virtual Archive & operator & (int & i) = 0; virtual Archive & operator & (int & i) = 0;
@ -275,6 +276,9 @@ namespace ngcore
Archive & Do (T * data, size_t n) Archive & Do (T * data, size_t n)
{ for (size_t j = 0; j < n; j++) { (*this) & data[j]; }; return *this; }; // NOLINT { for (size_t j = 0; j < n; j++) { (*this) & data[j]; }; return *this; }; // NOLINT
virtual Archive & Do (std::byte * d, size_t n)
{ for (size_t j = 0; j < n; j++) { (*this) & d[j]; }; return *this; }; // NOLINT
virtual Archive & Do (double * d, size_t n) virtual Archive & Do (double * d, size_t n)
{ for (size_t j = 0; j < n; j++) { (*this) & d[j]; }; return *this; }; // NOLINT { for (size_t j = 0; j < n; j++) { (*this) & d[j]; }; return *this; }; // NOLINT
@ -679,6 +683,8 @@ namespace ngcore
BinaryOutArchive& operator=(BinaryOutArchive&&) = delete; BinaryOutArchive& operator=(BinaryOutArchive&&) = delete;
using Archive::operator&; using Archive::operator&;
Archive & operator & (std::byte & d) override
{ return Write(d); }
Archive & operator & (float & f) override Archive & operator & (float & f) override
{ return Write(f); } { return Write(f); }
Archive & operator & (double & d) override Archive & operator & (double & d) override
@ -755,6 +761,8 @@ namespace ngcore
: BinaryInArchive(std::make_shared<std::ifstream>(filename)) { ; } : BinaryInArchive(std::make_shared<std::ifstream>(filename)) { ; }
using Archive::operator&; using Archive::operator&;
Archive & operator & (std::byte & d) override
{ Read(d); return *this; }
Archive & operator & (float & f) override Archive & operator & (float & f) override
{ Read(f); return *this; } { Read(f); return *this; }
Archive & operator & (double & d) override Archive & operator & (double & d) override
@ -826,6 +834,8 @@ namespace ngcore
TextOutArchive(std::make_shared<std::ofstream>(filename)) { } TextOutArchive(std::make_shared<std::ofstream>(filename)) { }
using Archive::operator&; using Archive::operator&;
Archive & operator & (std::byte & d) override
{ *stream << std::hex << int(d) << ' '; return *this; }
Archive & operator & (float & f) override Archive & operator & (float & f) override
{ *stream << f << '\n'; return *this; } { *stream << f << '\n'; return *this; }
Archive & operator & (double & d) override Archive & operator & (double & d) override
@ -879,6 +889,8 @@ namespace ngcore
: TextInArchive(std::make_shared<std::ifstream>(filename)) {} : TextInArchive(std::make_shared<std::ifstream>(filename)) {}
using Archive::operator&; using Archive::operator&;
Archive & operator & (std::byte & d) override
{ int tmp; *stream >> std::hex >> tmp; d = std::byte(tmp); return *this; }
Archive & operator & (float & f) override Archive & operator & (float & f) override
{ *stream >> f; return *this; } { *stream >> f; return *this; }
Archive & operator & (double & d) override Archive & operator & (double & d) override

View File

@ -377,7 +377,9 @@ namespace netgen
void DoArchive (Archive & ar) void DoArchive (Archive & ar)
{ {
ar & x[0] & x[1] & x[2] & layer & singular; // ar & x[0] & x[1] & x[2] & layer & singular;
ar.Do(&x[0], 3);
ar & layer & singular;
ar & (unsigned char&)(type); ar & (unsigned char&)(type);
} }
}; };
@ -845,8 +847,12 @@ namespace netgen
ar & _np & _typ & index & _curved; ar & _np & _typ & index & _curved;
if (ar.Input()) if (ar.Input())
{ np = _np; typ = ELEMENT_TYPE(_typ); is_curved = _curved; } { np = _np; typ = ELEMENT_TYPE(_typ); is_curved = _curved; }
/*
for (size_t i = 0; i < np; i++) for (size_t i = 0; i < np; i++)
ar & pnum[i]; ar & pnum[i];
*/
static_assert(sizeof(int) == sizeof (PointIndex));
ar.Do( (int*)&pnum[0], np);
} }
#ifdef PARALLEL #ifdef PARALLEL