Skip to content
Snippets Groups Projects
Commit 5d99c379 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Implementing serialization/deserialization of StaticArray.

parent 11593e3b
No related branches found
No related tags found
1 merge request!41Tutorials
...@@ -230,6 +230,25 @@ protected: ...@@ -230,6 +230,25 @@ protected:
template< int Size, typename Value > template< int Size, typename Value >
std::ostream& operator<<( std::ostream& str, const StaticArray< Size, Value >& a ); 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 Containers
} // namespace TNL } // namespace TNL
......
...@@ -343,5 +343,37 @@ std::ostream& operator<<( std::ostream& str, const StaticArray< Size, Value >& a ...@@ -343,5 +343,37 @@ std::ostream& operator<<( std::ostream& str, const StaticArray< Size, Value >& a
return str; 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 Containers
} // namespace TNL } // namespace TNL
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment