diff --git a/src/TNL/Meshes/Readers/TNLReader.h b/src/TNL/Meshes/Readers/TNLReader.h index 18fe2e6906b13a3b8310e48fd268afa777e45747..881a5026561c746129a34a951013ca03937fc0d1 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 1c957853f9f8b90143fa3ef3a911550746521fd0..6267da9d34399a5b759691613a95c180f25b99d9 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 49e8c70ca849f67d66f9864590b743b3d213cb70..b6de3817f73eb8f79152e6679acf7018851161a2 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 6e8674eae02cecc4840cb96d8c1157a3a27ead29..1d681a6df133001011cf01c7bc0ba8a4ea671859 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 0f90bc28aa400c22aeda2ec8eabbb3e99e07fbab..d4f7514e2c331c514fb8fddc277ed966c8dfd50b 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 40ada4a8e5fd7169c0c784f0b8e6f8172cba39dd..1bdadb07aef7896e4ff9943f69bcf5ed71d33478 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 d993e1ff7e00d8bdf6ded2b66ae59ee678f41d30..6b8b019e3a3168a3bad7ed56e0d5d0795b211e3d 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 6ce8967e4ae94467a2540f368f2e890459f59362..273bac769d0e307a52906aa9daa4560431042d04 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(...) {