Commit 5d99c379 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber

Implementing serialization/deserialization of StaticArray.

parent 11593e3b
......@@ -230,6 +230,25 @@ protected:
template< int Size, typename Value >
std::ostream& operator<<( std::ostream& str, const StaticArray< Size, Value >& a );
/**
* \brief Serialization of arrays into binary files.
*/
template< int Size, typename Value >
File& operator<<( File& file, const StaticArray< Size, Value >& array );
template< int Size, typename Value >
File& operator<<( File&& file, const StaticArray< Size, Value >& array );
/**
* \brief Deserialization of arrays from binary files.
*/
template< int Size, typename Value >
File& operator>>( File& file, StaticArray< Size, Value >& array );
template< int Size, typename Value >
File& operator>>( File&& file, StaticArray< Size, Value >& array );
} // namespace Containers
} // namespace TNL
......
......@@ -343,5 +343,37 @@ std::ostream& operator<<( std::ostream& str, const StaticArray< Size, Value >& a
return str;
}
// Serialization of arrays into binary files.
template< int Size, typename Value >
File& operator<<( File& file, const StaticArray< Size, Value >& array )
{
for( int i = 0; i < Size; i++ )
file.save( &array[ i ] );
return file;
}
template< int Size, typename Value >
File& operator<<( File&& file, const StaticArray< Size, Value >& array )
{
File& f = file;
return f << array;
}
// Deserialization of arrays from binary files.
template< int Size, typename Value >
File& operator>>( File& file, StaticArray< Size, Value >& array )
{
for( int i = 0; i < Size; i++ )
file.load( &array[ i ] );
return file;
}
template< int Size, typename Value >
File& operator>>( File&& file, StaticArray< Size, Value >& array )
{
File& f = file;
return f >> array;
}
} // namespace Containers
} // namespace TNL
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment