From 3b27d05ae13eeca0b7beeb17040d7ff60c3e1bf7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= <klinkjak@fjfi.cvut.cz>
Date: Fri, 12 Apr 2019 23:39:58 +0200
Subject: [PATCH] Removed boundLoad from Array and Object - needed only in
 MeshFunction and VectorField

---
 src/Python/pytnl/tnl/Object.cpp       |  1 -
 src/TNL/Containers/Array.h            | 14 --------------
 src/TNL/Containers/Array.hpp          | 21 ---------------------
 src/TNL/Containers/DistributedArray.h |  3 +--
 src/TNL/Functions/MeshFunction.h      |  4 ++--
 src/TNL/Functions/MeshFunction_impl.h | 14 +++++++++++++-
 src/TNL/Functions/VectorField.h       | 13 +++++++++----
 src/TNL/Matrices/DistributedMatrix.h  |  1 -
 src/TNL/Object.h                      | 18 ------------------
 src/TNL/Object.hpp                    | 12 ------------
 src/UnitTests/Containers/ArrayTest.h  |  8 ++------
 11 files changed, 27 insertions(+), 82 deletions(-)

diff --git a/src/Python/pytnl/tnl/Object.cpp b/src/Python/pytnl/tnl/Object.cpp
index 56b0f54e52..8c7569f2b3 100644
--- a/src/Python/pytnl/tnl/Object.cpp
+++ b/src/Python/pytnl/tnl/Object.cpp
@@ -12,7 +12,6 @@ void export_Object( py::module & m )
         // TODO: make it abstract class in Python
         .def("save", (void (TNL::Object::*)(const TNL::String &) const) &TNL::Object::save)
         .def("load", (void (TNL::Object::*)(const TNL::String &)) &TNL::Object::load)
-        .def("boundLoad", (void (TNL::Object::*)(const TNL::String &)) &TNL::Object::boundLoad)
         // FIXME: why does it not work?
 //        .def("save", py::overload_cast<TNL::File>(&TNL::Object::save, py::const_))
 //        .def("load", py::overload_cast<TNL::File>(&TNL::Object::load))
diff --git a/src/TNL/Containers/Array.h b/src/TNL/Containers/Array.h
index caeb88dd03..0c0e6c0cc8 100644
--- a/src/TNL/Containers/Array.h
+++ b/src/TNL/Containers/Array.h
@@ -537,24 +537,10 @@ class Array : public Object
        */
       void load( File& file );
 
-      /**
-       * \brief This method loads data without reallocation.
-       *
-       * This is useful for loading data into shared arrays.
-       * If the array was not initialize yet, common load is
-       * performed. Otherwise, the array size must fit with
-       * the size of array being loaded.
-       *
-       * This method is deprecated - use ArrayView instead.
-       */
-      void boundLoad( File& file );
-
       using Object::save;
 
       using Object::load;
 
-      using Object::boundLoad;
-
       /** \brief Basic destructor. */
       ~Array();
 
diff --git a/src/TNL/Containers/Array.hpp b/src/TNL/Containers/Array.hpp
index d0cbf39651..cde3b782eb 100644
--- a/src/TNL/Containers/Array.hpp
+++ b/src/TNL/Containers/Array.hpp
@@ -677,27 +677,6 @@ load( File& file )
    Algorithms::ArrayIO< Value, Device, Index >::load( file, this->data, this->size );
 }
 
-template< typename Value,
-          typename Device,
-          typename Index >
-void
-Array< Value, Device, Index >::
-boundLoad( File& file )
-{
-   Object::load( file );
-   Index _size;
-   file.load( &_size );
-   if( _size < 0 )
-      throw Exceptions::FileDeserializationError( file.getFileName(), "invalid array size: " + std::to_string(_size) );
-   if( this->getSize() != 0 )
-   {
-      if( this->getSize() != _size )
-         throw Exceptions::FileDeserializationError( file.getFileName(), "invalid array size: " + std::to_string(_size) + " (expected " + std::to_string( this->getSize() ) + ")." );
-   }
-   else setSize( _size );
-   Algorithms::ArrayIO< Value, Device, Index >::load( file, this->data, this->size );
-}
-
 template< typename Value,
           typename Device,
           typename Index >
diff --git a/src/TNL/Containers/DistributedArray.h b/src/TNL/Containers/DistributedArray.h
index edae7ccd03..db160a1efb 100644
--- a/src/TNL/Containers/DistributedArray.h
+++ b/src/TNL/Containers/DistributedArray.h
@@ -138,7 +138,7 @@ public:
    // Returns true iff non-zero size is set
    operator bool() const;
 
-   // TODO: serialization (save, load, boundLoad)
+   // TODO: serialization (save, load)
 
 protected:
    LocalRangeType localRange;
@@ -150,7 +150,6 @@ private:
    // TODO: disabled until they are implemented
    using Object::save;
    using Object::load;
-   using Object::boundLoad;
 };
 
 } // namespace Containers
diff --git a/src/TNL/Functions/MeshFunction.h b/src/TNL/Functions/MeshFunction.h
index 9e6f6f5719..c9eb66ac53 100644
--- a/src/TNL/Functions/MeshFunction.h
+++ b/src/TNL/Functions/MeshFunction.h
@@ -152,6 +152,8 @@ class MeshFunction :
 
       void boundLoad( File& file );
 
+      void boundLoad( const String& fileName );
+
       bool write( const String& fileName,
                   const String& format = "vtk",
                   const double& scale = 1.0 ) const;
@@ -160,8 +162,6 @@ class MeshFunction :
 
       using Object::load;
 
-      using Object::boundLoad;
-
       DistributedMeshSynchronizerType& getSynchronizer()
       {
          return this->synchronizer;
diff --git a/src/TNL/Functions/MeshFunction_impl.h b/src/TNL/Functions/MeshFunction_impl.h
index 40844062bc..d0efb9f387 100644
--- a/src/TNL/Functions/MeshFunction_impl.h
+++ b/src/TNL/Functions/MeshFunction_impl.h
@@ -497,7 +497,19 @@ MeshFunction< Mesh, MeshEntityDimension, Real >::
 boundLoad( File& file )
 {
    Object::load( file );
-   this->data.boundLoad( file );
+   this->data.getView().load( file );
+}
+
+template< typename Mesh,
+          int MeshEntityDimension,
+          typename Real >
+void
+MeshFunction< Mesh, MeshEntityDimension, Real >::
+boundLoad( const String& fileName )
+{
+   File file;
+   file.open( fileName, std::ios_base::in );
+   this->boundLoad( file );
 }
 
 template< typename Mesh,
diff --git a/src/TNL/Functions/VectorField.h b/src/TNL/Functions/VectorField.h
index 87d86d62b6..4db601c9f4 100644
--- a/src/TNL/Functions/VectorField.h
+++ b/src/TNL/Functions/VectorField.h
@@ -282,14 +282,21 @@ class VectorField< Size, MeshFunction< Mesh, MeshEntityDimension, Real > >
          for( int i = 0; i < Size; i++ )
             vectorField[ i ]->load( file );
       }
- 
+
       void boundLoad( File& file )
       {
          Object::load( file );
          for( int i = 0; i < Size; i++ )
             vectorField[ i ]->boundLoad( file );
       }
-      
+
+      void boundLoad( const String& fileName )
+      {
+         File file;
+         file.open( fileName, std::ios_base::in );
+         this->boundLoad( file );
+      }
+
       bool write( const String& fileName,
                   const String& format = "vtk",
                   const double& scale = 1.0 ) const
@@ -316,8 +323,6 @@ class VectorField< Size, MeshFunction< Mesh, MeshEntityDimension, Real > >
  
       using Object::load;
  
-      using Object::boundLoad;      
-
    protected:
       
       Containers::StaticArray< Size, FunctionPointer > vectorField;
diff --git a/src/TNL/Matrices/DistributedMatrix.h b/src/TNL/Matrices/DistributedMatrix.h
index dd76804cf7..c200663dc3 100644
--- a/src/TNL/Matrices/DistributedMatrix.h
+++ b/src/TNL/Matrices/DistributedMatrix.h
@@ -177,7 +177,6 @@ private:
    // TODO: disabled until they are implemented
    using Object::save;
    using Object::load;
-   using Object::boundLoad;
 };
 
 } // namespace Matrices
diff --git a/src/TNL/Object.h b/src/TNL/Object.h
index 4dd6d658e3..8e7e567a9c 100644
--- a/src/TNL/Object.h
+++ b/src/TNL/Object.h
@@ -104,15 +104,6 @@ class Object
        */
       virtual void load( File& file );
 
-      /**
-       * \brief Method for restoring the object from a file.
-       *
-       * Throws \ref Exceptions::FileDeserializationError if the object cannot be loaded.
-       *
-       * \param file Name of file object.
-       */
-      virtual void boundLoad( File& file );
-
       /**
        * \brief Method for saving the object to a file as a binary data.
        *
@@ -131,15 +122,6 @@ class Object
        */
       void load( const String& fileName );
 
-       /**
-       * \brief Method for restoring the object from a file.
-       *
-       * Throws \ref Exceptions::FileDeserializationError if the object cannot be loaded.
-       *
-       * \param fileName String defining the name of a file.
-       */
-      void boundLoad( const String& fileName );
-
       /**
        * \brief Destructor.
        *
diff --git a/src/TNL/Object.hpp b/src/TNL/Object.hpp
index f2bad7cf3a..697e738fdb 100644
--- a/src/TNL/Object.hpp
+++ b/src/TNL/Object.hpp
@@ -53,11 +53,6 @@ inline void Object::load( File& file )
       throw Exceptions::FileDeserializationError( file.getFileName(), "object type does not match (expected " + this->getSerializationTypeVirtual() + ", found " + objectType + ")." );
 }
 
-inline void Object::boundLoad( File& file )
-{
-   this->load( file );
-}
-
 inline void Object::save( const String& fileName ) const
 {
    File file;
@@ -72,13 +67,6 @@ inline void Object::load( const String& fileName )
    this->load( file );
 }
 
-inline void Object::boundLoad( const String& fileName )
-{
-   File file;
-   file.open( fileName, std::ios_base::in );
-   this->boundLoad( file );
-}
-
 inline String getObjectType( File& file )
 {
    char mn[ 10 ];
diff --git a/src/UnitTests/Containers/ArrayTest.h b/src/UnitTests/Containers/ArrayTest.h
index 2d4283221d..527f6e9e13 100644
--- a/src/UnitTests/Containers/ArrayTest.h
+++ b/src/UnitTests/Containers/ArrayTest.h
@@ -489,7 +489,7 @@ TYPED_TEST( ArrayTest, SaveAndLoad )
    EXPECT_EQ( std::remove( "test-file.tnl" ), 0 );
 }
 
-TYPED_TEST( ArrayTest, boundLoad )
+TYPED_TEST( ArrayTest, LoadViaView )
 {
    using ArrayType = typename TestFixture::ArrayType;
 
@@ -511,11 +511,7 @@ TYPED_TEST( ArrayTest, boundLoad )
 
    ArrayType z( 50 );
    ASSERT_NO_THROW( file.open( "test-file.tnl", std::ios_base::in ) );
-   EXPECT_ANY_THROW( z.boundLoad( file ) );
-
-   v.reset();
-   ASSERT_NO_THROW( file.open( "test-file.tnl", std::ios_base::in ) );
-   EXPECT_NO_THROW( v.boundLoad( file ) );
+   EXPECT_ANY_THROW( z.getView().load( file ) );
 
    EXPECT_EQ( std::remove( "test-file.tnl" ), 0 );
 }
-- 
GitLab