OpenLB 1.7
Loading...
Searching...
No Matches
Public Member Functions | List of all members
olb::Serializer Class Reference

Class for writing, reading, sending and receiving Serializable objects. More...

#include <serializer.h>

+ Collaboration diagram for olb::Serializer:

Public Member Functions

 Serializer (Serializable &serializable, std::string fileName="")
 Constructor.
 
void resetCounter ()
 Resets the _iBlock counter.
 
std::size_t getSize () const
 Returns the total memory size in bits.
 
bool * getNextBlock (std::size_t &sizeBlock, const bool loadingMode)
 Returns pointer to the memory of the current block and increments iBlock
 
template<bool includeLogOutputDir = true>
bool load (std::string fileName="", const bool enforceUint=false)
 Loads a file and pushes the data into the serialized class. Always in parallel, i.e. one file per rank.
 
template<bool includeLogOutputDir = true>
bool save (std::string fileName="", const bool enforceUint=false)
 Save _serializable into file filename. Always in parallel, i.e. one file per rank.
 
bool load (const std::uint8_t *buffer)
 Loads serialized class from buffer.
 
bool save (std::uint8_t *buffer)
 Saves serialized class to buffer.
 
void computeSize (const bool enforceRecompute=false)
 computes _size based on the individual definition of getBlock()
 

Detailed Description

Class for writing, reading, sending and receiving Serializable objects.

For detailed information on the serialization concept, see the Serializable documentation.

Definition at line 41 of file serializer.h.

Constructor & Destructor Documentation

◆ Serializer()

olb::Serializer::Serializer ( Serializable & serializable,
std::string fileName = "" )

Constructor.

If serializable is omitted, it has to be provided in the save method.

Definition at line 44 of file serializer.hh.

45 : _serializable(serializable), _iBlock(0), _size(0), _fileName(fileName)
46{ }

Member Function Documentation

◆ computeSize()

void olb::Serializer::computeSize ( const bool enforceRecompute = false)

computes _size based on the individual definition of getBlock()

Definition at line 112 of file serializer.hh.

113{
114 // compute size (only if it wasn't computed yet or is enforced)
115 if (enforceRecompute || _size == 0) {
116 _size = _serializable.getSerializableSize();
117 }
118}
virtual std::size_t getSerializableSize() const =0
Returns the binary size of the data to be saved.

References olb::Serializable::getSerializableSize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getNextBlock()

bool * olb::Serializer::getNextBlock ( std::size_t & sizeBlock,
const bool loadingMode )

Returns pointer to the memory of the current block and increments iBlock

Definition at line 59 of file serializer.hh.

60{
61 return _serializable.getBlock(_iBlock++, sizeBlock, loadingMode);
62}
virtual bool * getBlock(const std::size_t iBlock, std::size_t &sizeBlock, const bool loadingMode=false)=0
Returns the address of the i-th block and its size.

References olb::Serializable::getBlock().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSize()

std::size_t olb::Serializer::getSize ( ) const

Returns the total memory size in bits.

Definition at line 54 of file serializer.hh.

55{
56 return _size;
57}
+ Here is the caller graph for this function:

◆ load() [1/2]

bool olb::Serializer::load ( const std::uint8_t * buffer)

Loads serialized class from buffer.

Definition at line 99 of file serializer.hh.

100{
101 buffer2serializer(*this, buffer);
102 _serializable.postLoad();
103 return true;
104}
virtual void postLoad()
Definition serializer.h:191
void buffer2serializer(Serializer &serializer, const std::uint8_t *buffer)
processes a buffer to a serializer

References olb::buffer2serializer(), and olb::Serializable::postLoad().

+ Here is the call graph for this function:

◆ load() [2/2]

template<bool includeLogOutputDir>
bool olb::Serializer::load ( std::string fileName = "",
const bool enforceUint = false )

Loads a file and pushes the data into the serialized class. Always in parallel, i.e. one file per rank.

Definition at line 65 of file serializer.hh.

66{
67 validateFileName(fileName);
68 std::ifstream istr(getFullFileName<includeLogOutputDir>(fileName).c_str());
69 if (istr) {
70 istr2serializer(*this, istr, enforceUint);
71 istr.close();
72 _serializable.postLoad();
73 return true;
74 }
75 else {
76 return false;
77 }
78}
void istr2serializer(Serializer &serializer, std::istream &istr, bool enforceUint=false)
processes an istr to a serializer, always in parallel

References olb::istr2serializer(), and olb::Serializable::postLoad().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resetCounter()

void olb::Serializer::resetCounter ( )

Resets the _iBlock counter.

Definition at line 49 of file serializer.hh.

50{
51 _iBlock = 0;
52}
+ Here is the caller graph for this function:

◆ save() [1/2]

template<bool includeLogOutputDir>
bool olb::Serializer::save ( std::string fileName = "",
const bool enforceUint = false )

Save _serializable into file filename. Always in parallel, i.e. one file per rank.

Definition at line 81 of file serializer.hh.

82{
83 validateFileName(fileName);
84
85 // Determine binary size through `getSerializableSize()` method
87
88 std::ofstream ostr (getFullFileName<includeLogOutputDir>(fileName).c_str());
89 if (ostr) {
90 serializer2ostr(*this, ostr, enforceUint);
91 ostr.close();
92 return true;
93 }
94 else {
95 return false;
96 }
97}
void computeSize(const bool enforceRecompute=false)
computes _size based on the individual definition of getBlock()
void serializer2ostr(Serializer &serializer, std::ostream &ostr, bool enforceUint=false)
processes data from a serializer to a given ostr, always in parallel

References computeSize(), and olb::serializer2ostr().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ save() [2/2]

bool olb::Serializer::save ( std::uint8_t * buffer)

Saves serialized class to buffer.

Definition at line 106 of file serializer.hh.

107{
108 serializer2buffer(*this, buffer);
109 return true;
110}
void serializer2buffer(Serializer &serializer, std::uint8_t *buffer)
processes data from a serializer to a given buffer

References olb::serializer2buffer().

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: