Commit f7a62b21 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Moved getSerializationType method from Array/ArrayView to ArrayIO

parent a0e9a56d
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -31,7 +31,13 @@ template< typename Value,
          typename Index >
struct ArrayIO< Value, Device, Index, true >
{
   public:
   static String getSerializationType()
   {
      return String( "Containers::Array< " ) +
             TNL::getType< Value >() + ", " +
             Devices::Host::getDeviceType() + ", " +
             TNL::getType< Index >() + " >";
   }

   static void save( File& file,
                     const Value* data,
@@ -71,6 +77,14 @@ template< typename Value,
          typename Index >
struct ArrayIO< Value, Device, Index, false >
{
   static String getSerializationType()
   {
      return String( "Containers::Array< " ) +
             TNL::getType< Value >() + ", " +
             Devices::Host::getDeviceType() + ", " +
             TNL::getType< Index >() + " >";
   }

   static void save( File& file,
                     const Value* data,
                     const Index elements )
+6 −4
Original line number Diff line number Diff line
@@ -178,7 +178,7 @@ String
Array< Value, Device, Index >::
getSerializationType()
{
   return HostType::getType();
   return Algorithms::ArrayIO< Value, Device, Index >::getSerializationType();
}

template< typename Value,
@@ -716,7 +716,8 @@ std::ostream& operator<<( std::ostream& str, const Array< Value, Device, Index >
template< typename Value, typename Device, typename Index >
File& operator<<( File& file, const Array< Value, Device, Index >& array )
{
   saveObjectType( file, array.getSerializationType() );
   using IO = Algorithms::ArrayIO< Value, Device, Index >;
   saveObjectType( file, IO::getSerializationType() );
   const Index size = array.getSize();
   file.save( &size );
   Algorithms::ArrayIO< Value, Device, Index >::save( file, array.getData(), array.getSize() );
@@ -734,9 +735,10 @@ File& operator<<( File&& file, const Array< Value, Device, Index >& array )
template< typename Value, typename Device, typename Index >
File& operator>>( File& file, Array< Value, Device, Index >& array )
{
   using IO = Algorithms::ArrayIO< Value, Device, Index >;
   const String type = getObjectType( file );
   if( type != array.getSerializationType() )
      throw Exceptions::FileDeserializationError( file.getFileName(), "object type does not match (expected " + array.getSerializationType() + ", found " + type + ")." );
   if( type != IO::getSerializationType() )
      throw Exceptions::FileDeserializationError( file.getFileName(), "object type does not match (expected " + IO::getSerializationType() + ", found " + type + ")." );
   Index _size;
   file.load( &_size );
   if( _size < 0 )
+0 −9
Original line number Diff line number Diff line
@@ -21,9 +21,6 @@
namespace TNL {
namespace Containers {

template< typename Value, typename Device, typename Index >
class Array;

/**
 * \brief \e ArrayView is a simple data structure which provides a non-owning
 * encapsulation of array data. That is, \e ArrayView is like \ref Array without
@@ -64,7 +61,6 @@ template< typename Value,
          typename Index = int >
class ArrayView
{
   using SerializationType = Array< Value, Devices::Host, Index >;
public:
   using ValueType = Value;
   using DeviceType = Device;
@@ -79,11 +75,6 @@ public:
    */
   static String getType();

   /**
    * \brief Returns a \ref String representation of the serialization type.
    */
   static String getSerializationType();

   /**
    * \brief Constructs an empty array view.
    *
+7 −15
Original line number Diff line number Diff line
@@ -37,16 +37,6 @@ getType()
                  TNL::getType< Index >() + " >";
}

template< typename Value,
          typename Device,
          typename Index >
String
ArrayView< Value, Device, Index >::
getSerializationType()
{
   return SerializationType::getSerializationType();
}

// explicit initialization by raw data pointer and size
template< typename Value,
          typename Device,
@@ -405,10 +395,11 @@ load( const String& fileName )
template< typename Value, typename Device, typename Index >
File& operator<<( File& file, const ArrayView< Value, Device, Index > view )
{
   saveObjectType( file, view.getSerializationType() );
   using IO = Algorithms::ArrayIO< Value, Device, Index >;
   saveObjectType( file, IO::getSerializationType() );
   const Index size = view.getSize();
   file.save( &size );
   Algorithms::ArrayIO< Value, Device, Index >::save( file, view.getData(), view.getSize() );
   IO::save( file, view.getData(), view.getSize() );
   return file;
}

@@ -423,14 +414,15 @@ File& operator<<( File&& file, const ArrayView< Value, Device, Index > view )
template< typename Value, typename Device, typename Index >
File& operator>>( File& file, ArrayView< Value, Device, Index > view )
{
   using IO = Algorithms::ArrayIO< Value, Device, Index >;
   const String type = getObjectType( file );
   if( type != view.getSerializationType() )
      throw Exceptions::FileDeserializationError( file.getFileName(), "object type does not match (expected " + view.getSerializationType() + ", found " + type + ")." );
   if( type != IO::getSerializationType() )
      throw Exceptions::FileDeserializationError( file.getFileName(), "object type does not match (expected " + IO::getSerializationType() + ", found " + type + ")." );
   Index _size;
   file.load( &_size );
   if( _size != view.getSize() )
      throw Exceptions::FileDeserializationError( file.getFileName(), "invalid array size: " + std::to_string(_size) + " (expected " + std::to_string( view.getSize() ) + ")." );
   Algorithms::ArrayIO< Value, Device, Index >::load( file, view.getData(), view.getSize() );
   IO::load( file, view.getData(), view.getSize() );
   return file;
}