|
template<typename T > |
EnableIf_t< IsNumeric_v< T >, Archive< Stream > & > | operator<< (const T &value) |
| Serializes the given built-in data value and writes it to the archive. More...
|
|
template<typename T > |
DisableIf_t< IsNumeric_v< T >, Archive< Stream > & > | operator<< (const T &value) |
| Serializes the user-defined object and writes it to the archive. More...
|
|
template<typename T > |
EnableIf_t< IsNumeric_v< T >, Archive< Stream > & > | operator>> (T &value) |
| Deserializes a value of built-in data type and reads it from the archive. More...
|
|
template<typename T > |
DisableIf_t< IsNumeric_v< T >, Archive< Stream > & > | operator>> (T &value) |
| Deserializes an object of user-defined data type and reads it from the archive. More...
|
|
template<typename Type > |
EnableIf_t< IsNumeric_v< Type >, Archive< Stream > & > | write (const Type *array, size_t count) |
| Writing an array of values to the stream. More...
|
|
template<typename Type > |
EnableIf_t< IsNumeric_v< Type >, Archive< Stream > & > | read (Type *array, size_t count) |
| Reading an array of values from the stream. More...
|
|
|
template<typename... Args> |
| Archive (Args &&... args) |
| Creating an archive with an internal stream resource. More...
|
|
| Archive (Stream &stream) |
| Creating an archive with an external stream resource. More...
|
|
| Archive (const Archive &)=delete |
|
| Archive (Archive &&)=default |
|
|
| ~Archive ()=default |
|
|
Archive & | operator= (const Archive &)=delete |
|
Archive & | operator= (Archive &&)=default |
|
|
| operator bool () const |
| Returns the current state of the archive. More...
|
|
bool | operator! () const |
| Returns the negated state of the archive. More...
|
|
|
template<typename T > |
EnableIf_t< IsNumeric_v< T >, Archive & > | operator<< (const T &value) |
|
template<typename T > |
DisableIf_t< IsNumeric_v< T >, Archive & > | operator<< (const T &value) |
|
template<typename T > |
EnableIf_t< IsNumeric_v< T >, Archive & > | operator>> (T &value) |
|
template<typename T > |
DisableIf_t< IsNumeric_v< T >, Archive & > | operator>> (T &value) |
|
template<typename Type > |
EnableIf_t< IsNumeric_v< Type >, Archive & > | write (const Type *array, size_t count) |
|
template<typename Type > |
EnableIf_t< IsNumeric_v< Type >, Archive & > | read (Type *array, size_t count) |
|
|
Stream::int_type | peek () const |
| Reads the next character from the input stream without extracting it. More...
|
|
bool | good () const |
| Checks if no error has occurred, i.e. I/O operations are available. More...
|
|
bool | eof () const |
| Checks if end-of-file (EOF) has been reached. More...
|
|
bool | fail () const |
| Checks if a recoverable error has occurred. More...
|
|
bool | bad () const |
| Checks if a non-recoverable error has occurred. More...
|
|
std::ios_base::iostate | rdstate () const |
| Returns the current state flags settings. More...
|
|
void | setstate (std::ios_base::iostate state) |
| Sets the state flags to a specific value. More...
|
|
void | clear (std::ios_base::iostate state=std::ios_base::goodbit) |
| Clears error and eof flags. More...
|
|
template<typename Stream>
class blaze::Archive< Stream >
Binary archive for the portable serialization of data.
The Archive class implements the functionality to create platform independent, portable, representations of arbitrary C++ data structures. The resulting binary data structures can be used to reconstitute the data structures in a different context, on another platform, etc.
The following example demonstrates the Archive class by means of a C-style POD data structure:
struct POD {
int i;
unsigned int u;
float f;
double d;
};
The archive already supports the (de-)serialization of built-in data types. In order to be able to serialize the POD data structure, i.e. to convert it into a binary representation that can stored or transfered to other machines, the according serialize
and deserialize
function have to be implemented:
template< typename Archive >
{
archive << pod.i << pod.u << pod.f << pod.d;
}
template< typename Archive >
{
archive >> pod.i >> pod.u >> pod.f >> pod.d;
}
void serialize(Archive &archive, const Matrix< MT, SO > &mat)
Serializes the given matrix and writes it to the archive.
Definition: MatrixSerializer.h:1256
void deserialize(Archive &archive, Matrix< MT, SO > &mat)
Deserializes a matrix from the given archive.
Definition: MatrixSerializer.h:1278
Archive(Args &&... args)
Creating an archive with an internal stream resource.
Definition: Archive.h:250
The serialize
function implements the conversion from the POD to a binary representation, the deserialize
function implements the reverse conversion from a binary representation to a POD. Note that it is important to write the values to the archive in exactly the same order as the values are read from the archive!
With these two functions it is already possible to serialize a POD object:
int main()
{
{
POD pod;
archive << pod;
}
{
POD pod;
Archive<std::ifstream> archive( "filename" );
archive >> pod;
}
}
decltype(auto) trunc(const DenseMatrix< MT, SO > &dm)
Applies the trunc() function to each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1408
Each archive has to be bound to either an output or input stream. In the example, the archive is bound to a file output stream that is created by passing the file name and the according flags to the archive. Subsequently, the archive can be used like an output stream to write the POD data structure to the file called 'filename'.
The reverse conversion from the binary representation contained in the file to the POD data structure can be achieved by binding an archive to a file input stream. Subsequently, the archive can be used as an input stream to read the POD from file.
Note that the Archive class can be bound to any kind of input or output stream (or also iostream) that supports the standard write or read functions, respectively. Therefore the serialization of a C++ data structure is not restricted to binary files, but allows for any possible destination.