From e55f31a958b3438bd1fb4edce17f666c8ee3f10d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Oberhuber?= <oberhuber.tomas@gmail.com> Date: Mon, 4 Mar 2019 21:15:29 +0100 Subject: [PATCH] getObjectType returns String with the object type. --- src/TNL/Meshes/Readers/TNLReader.h | 2 +- src/TNL/Object.h | 22 +++++++++++++++++----- src/TNL/Object.hpp | 11 ++++++----- src/Tools/tnl-diff.cpp | 2 +- src/Tools/tnl-diff.h | 2 +- src/Tools/tnl-init.cpp | 2 +- src/Tools/tnl-lattice-init.h | 6 +++--- src/Tools/tnl-view.h | 2 +- 8 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/TNL/Meshes/Readers/TNLReader.h b/src/TNL/Meshes/Readers/TNLReader.h index 18fe2e6906..881a502656 100644 --- a/src/TNL/Meshes/Readers/TNLReader.h +++ b/src/TNL/Meshes/Readers/TNLReader.h @@ -31,7 +31,7 @@ public: String objectType; try { - getObjectType( fileName, objectType ); + objectType = getObjectType( fileName ); } catch( ... ) { diff --git a/src/TNL/Object.h b/src/TNL/Object.h index 1c957853f9..6267da9d34 100644 --- a/src/TNL/Object.h +++ b/src/TNL/Object.h @@ -135,14 +135,26 @@ class Object /** * \brief Extracts object type from a binary file. * - * @param file - * @param type - * @return + * @param file is file where the object is stored + * @return string with the object type */ -void getObjectType( File& file, String& type ); +String getObjectType( File& file ); -void getObjectType( const String& file_name, String& type ); +/** + * \brief Does the same as \ref getObjectType but with \e fileName parameter instead of file. + * + * @param fileName name of file where the object is stored + * @param type string with the object type + */ +String getObjectType( const String& fileName ); +/** + * \brief Parses the object type + * + * @param objectType is a string with the object type + * @return list of strings where the first one is the object type and the next + * strings are the template parameters + */ std::vector< String > parseObjectType( const String& objectType ); diff --git a/src/TNL/Object.hpp b/src/TNL/Object.hpp index 49e8c70ca8..b6de3817f7 100644 --- a/src/TNL/Object.hpp +++ b/src/TNL/Object.hpp @@ -51,8 +51,7 @@ inline bool Object::save( File& file ) const inline bool Object::load( File& file ) { - String objectType; - getObjectType( file, objectType ); + String objectType = getObjectType( file ); if( objectType != this->getSerializationTypeVirtual() ) { std::cerr << "Given file contains instance of " << objectType << " but " << getSerializationTypeVirtual() << " is expected." << std::endl; @@ -99,20 +98,22 @@ inline bool Object::boundLoad( const String& fileName ) return this->boundLoad( file ); } -inline void getObjectType( File& file, String& type ) +inline String getObjectType( File& file ) { char mn[ 10 ]; + String type; file.read( mn, strlen( magic_number ) ); if( strncmp( mn, magic_number, 5 ) != 0 ) throw Exceptions::NotTNLFile(); file >> type; + return type; } -inline void getObjectType( const String& fileName, String& type ) +inline String getObjectType( const String& fileName ) { File binaryFile; binaryFile.open( fileName, IOMode::read ); - getObjectType( binaryFile, type ); + return getObjectType( binaryFile ); } inline std::vector< String > diff --git a/src/Tools/tnl-diff.cpp b/src/Tools/tnl-diff.cpp index 6e8674eae0..1d681a6df1 100644 --- a/src/Tools/tnl-diff.cpp +++ b/src/Tools/tnl-diff.cpp @@ -53,7 +53,7 @@ int main( int argc, char* argv[] ) String meshType; try { - getObjectType( meshFile, meshType ); + meshType = getObjectType( meshFile ); } catch(...) { diff --git a/src/Tools/tnl-diff.h b/src/Tools/tnl-diff.h index 0f90bc28aa..d4f7514e2c 100644 --- a/src/Tools/tnl-diff.h +++ b/src/Tools/tnl-diff.h @@ -625,7 +625,7 @@ bool processFiles( const Config::ParameterContainer& parameters ) String objectType; try { - getObjectType( inputFiles[ 0 ], objectType ); + objectType = getObjectType( inputFiles[ 0 ] ); } catch( std::ios_base::failure exception ) { diff --git a/src/Tools/tnl-init.cpp b/src/Tools/tnl-init.cpp index 40ada4a8e5..1bdadb07ae 100644 --- a/src/Tools/tnl-init.cpp +++ b/src/Tools/tnl-init.cpp @@ -66,7 +66,7 @@ int main( int argc, char* argv[] ) String meshType; try { - getObjectType( meshFile, meshType ); + meshType = getObjectType( meshFile ); } catch(...) { diff --git a/src/Tools/tnl-lattice-init.h b/src/Tools/tnl-lattice-init.h index d993e1ff7e..6b8b019e3a 100644 --- a/src/Tools/tnl-lattice-init.h +++ b/src/Tools/tnl-lattice-init.h @@ -224,7 +224,7 @@ bool resolveProfileReal( const Config::ParameterContainer& parameters ) String meshFunctionType; try { - getObjectType( profileFile, meshFunctionType ); + meshFunctionType = getObjectType( profileFile ); } catch(...) { @@ -283,7 +283,7 @@ bool resolveMesh( const Config::ParameterContainer& parameters ) String meshType; try { - getObjectType( meshFile, meshType ); + meshType = getObjectType( meshFile ); } catch(...) { @@ -381,7 +381,7 @@ bool resolveProfileMeshType( const Config::ParameterContainer& parameters ) String meshType; try { - getObjectType( meshFile, meshType ); + meshType = getObjectType( meshFile ); } catch(...) { diff --git a/src/Tools/tnl-view.h b/src/Tools/tnl-view.h index 6ce8967e4a..273bac769d 100644 --- a/src/Tools/tnl-view.h +++ b/src/Tools/tnl-view.h @@ -475,7 +475,7 @@ struct FilesProcessor String objectType; try { - getObjectType( inputFiles[ i ], objectType ); + objectType = getObjectType( inputFiles[ i ] ); } catch(...) { -- GitLab