Commit 26562c2c authored by Tomáš Oberhuber's avatar Tomáš Oberhuber Committed by Tomáš Oberhuber
Browse files

Renaming File_impl.h to File.hpp.

Reformatting the File documentation.
parent 04d0568a
Loading
Loading
Loading
Loading
+141 −113
Original line number Diff line number Diff line
@@ -28,7 +28,8 @@ enum class IOMode
   write = 2
};

/* When we need to transfer data between the GPU and the CPU we use
/**
 * When we need to transfer data between the GPU and the CPU we use
 * 5 MB buffer. This size should ensure good performance -- see.
 * http://wiki.accelereyes.com/wiki/index.php/GPU_Memory_Transfer
 * Similar constant is defined in tnlLonegVectorCUDA
@@ -36,76 +37,94 @@ enum class IOMode
static constexpr std::streamsize FileGPUvsCPUTransferBufferSize = 5 * 2<<20;


///\brief Class file is aimed mainly for saving and loading binary data.
///
/// \par Example
/// \include FileExample.cpp
// \par Output
// \include FileExample.out
/**
 * \brief Class file is aimed mainly for saving and loading binary data.
 *
 * \par Example
 * \include FileExample.cpp
 * \par Output
 * \include FileExample.out
 */
class File
{
   std::fstream file;
   String fileName;

   public:
   /// \brief Basic constructor.
      
      enum class Mode
      {
         In = 1,
         Out = 2,
         Append = 4
      };
      
      /**
       * \brief Basic constructor.
       */
      File() = default;

   /////
   /// \brief Attempts to open given file and returns \e true after the file is
   /// successfully opened. Otherwise returns \e false.
   ///
   /// Opens file with given \e fileName and returns true/false based on the success in opening the file.
   /// \param fileName String which indicates name of the file user wants to open.
   /// \param mode Indicates what user needs to do with opened file.
      /**
       * \brief Attempts to open given file and returns \e true after the file is
       * successfully opened. Otherwise returns \e false.
       *
       * Opens file with given \e fileName and returns true/false based on the success in opening the file.
       * \param fileName String which indicates name of the file user wants to open.
       * \param mode Indicates what user needs to do with opened file.
       */
      bool open( const String& fileName,
                 const IOMode mode );

   /// \brief Attempts to close given file and returns \e true when the file is
   /// successfully closed. Otherwise returns \e false.
      /**
       * \brief Attempts to close given file and returns \e true when the file is
       * successfully closed. Otherwise returns \e false.
       */
      bool close();

   /// \brief Returns name of given file.
      /**
       * \brief Returns name of given file.
       */
      const String& getFileName() const
      {
         return this->fileName;
      }

   /// \brief Method that can write particular data type from given file into GPU. (Function that gets particular elements from given file.)
   ///
   /// Returns \e true when the elements are successfully read from given file. Otherwise returns \e false.
   ///
   /// Throws \ref std::ios_base::failure on failure.
   ///
   /// \tparam Type Type of data.
   /// \tparam Device Place where data are stored after reading from file. For example \ref Devices::Host or \ref Devices::Cuda.
   /// \tparam Index Type of index by which the elements are indexed.
   /// \param buffer Pointer in memory where the elements are loaded and stored after reading.
   /// \param elements Number of elements the user wants to get (read) from given file.
      /**
       * \brief Method that can write particular data type from given file into GPU. (Function that gets particular elements from given file.)
       *
       * Returns \e true when the elements are successfully read from given file. Otherwise returns \e false.
       *
       * Throws \ref std::ios_base::failure on failure.
       *
       * \tparam Type Type of data.
       * \tparam Device Place where data are stored after reading from file. For example \ref Devices::Host or \ref Devices::Cuda.
       * \tparam Index Type of index by which the elements are indexed.
       * \param buffer Pointer in memory where the elements are loaded and stored after reading.
       * \param elements Number of elements the user wants to get (read) from given file.
       */
      template< typename Type, typename Device = Devices::Host >
   bool read( Type* buffer, std::streamsize elements );
      bool read( Type* buffer, std::streamsize elements = 1 );

      // Toto je treba??
      //template< typename Type, typename Device = Devices::Host >
      //bool read( Type* buffer );

      /**
       * \brief Method that can write particular data type from CPU into given file. (Function that writes particular elements into given file.)
       *
       * Returns \e true when the elements are successfully written into given file. Otherwise returns \e false.
       *
       * Throws \ref std::ios_base::failure on failure.
       *
       * \tparam Type Type of data.
       * \tparam Device Place from where the data are loaded before writing into file. For example \ref Devices::Host or \ref Devices::Cuda.
       * \tparam Index Type of index by which the elements are indexed.
       * \param buffer Pointer in memory where the elements are loaded from before writing into file.
       * \param elements Number of elements the user wants to write into the given file.
       */
      template< typename Type, typename Device = Devices::Host >
   bool read( Type* buffer );

   /// \brief Method that can write particular data type from CPU into given file. (Function that writes particular elements into given file.)
   ///
   /// Returns \e true when the elements are successfully written into given file. Otherwise returns \e false.
   ///
   /// Throws \ref std::ios_base::failure on failure.
   ///
   /// \tparam Type Type of data.
   /// \tparam Device Place from where the data are loaded before writing into file. For example \ref Devices::Host or \ref Devices::Cuda.
   /// \tparam Index Type of index by which the elements are indexed.
   /// \param buffer Pointer in memory where the elements are loaded from before writing into file.
   /// \param elements Number of elements the user wants to write into the given file.
   template< typename Type, typename Device = Devices::Host >
   bool write( const Type* buffer, std::streamsize elements );
      bool write( const Type* buffer, std::streamsize elements = 1 );

      // Toto je treba?
   template< typename Type, typename Device = Devices::Host >
   bool write( const Type* buffer );
      //template< typename Type, typename Device = Devices::Host >
      //bool write( const Type* buffer );

   protected:
      template< typename Type,
@@ -143,20 +162,29 @@ protected:
                typename = void,
                typename = void >
      bool write_impl( const Type* buffer, std::streamsize elements );

      std::fstream file;
      String fileName;
};

/// Returns true if the file exists and false otherwise.
///
/// Finds out if the file \e fileName exists.
/// \param fileName Name of the file that user wants to find in the PC.
/**
 * \brief Returns true if the file exists and false otherwise.
 *
 * Finds out if the file \e fileName exists.
 * \param fileName Name of the file to check.
 */
bool fileExists( const String& fileName );

// serialization of strings
/**
 * \brief Serialization of strings
 */
File& operator<<( File& file, const std::string& str );

// deserialization of strings
/**
 * \brief Deserialization of strings.
 */
File& operator>>( File& file, std::string& str );

} // namespace TNL

#include <TNL/File_impl.h>
#include <TNL/File.hpp>
+4 −4
Original line number Diff line number Diff line
@@ -56,17 +56,17 @@ inline bool File::close()
   return true;
}

template< typename Type, typename Device >
/*template< typename Type, typename Device >
bool File::read( Type* buffer )
{
   return read< Type, Device >( buffer, 1 );
}
}*/

template< typename Type, typename Device >
/*template< typename Type, typename Device >
bool File::write( const Type* buffer )
{
   return write< Type, Device >( buffer, 1 );
}
}*/

template< typename Type, typename Device >
bool File::read( Type* buffer, std::streamsize elements )