Loading src/Examples/CMakeLists.txt +12 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,15 @@ ENDIF() ADD_EXECUTABLE( FileExampleSaveAndLoad FileExampleSaveAndLoad.cpp ) ADD_CUSTOM_COMMAND( COMMAND FileExampleSaveAndLoad > FileExampleSaveAndLoad.out OUTPUT FileExampleSaveAndLoad.out ) ADD_EXECUTABLE( FileNameExample FileNameExample.cpp ) ADD_CUSTOM_COMMAND( COMMAND FileNameExample > FileNameExample.out OUTPUT FileNameExample.out ) ADD_EXECUTABLE( FileNameExampleDistributedSystemNodeCoordinates FileNameExampleDistributedSystemNodeCoordinates.cpp ) ADD_CUSTOM_COMMAND( COMMAND FileNameExampleDistributedSystemNodeCoordinates > FileNameExampleDistributedSystemNodeCoordinates.out OUTPUT FileNameExampleDistributedSystemNodeCoordinates.out ) ADD_EXECUTABLE( FileNameExampleDistributedSystemNodeId FileNameExampleDistributedSystemNodeId.cpp ) ADD_CUSTOM_COMMAND( COMMAND FileNameExampleDistributedSystemNodeId > FileNameExampleDistributedSystemNodeId.out OUTPUT FileNameExampleDistributedSystemNodeId.out ) ADD_EXECUTABLE( ListExample ListExample.cpp ) ADD_EXECUTABLE( LoggerExample LoggerExample.cpp ) Loading Loading @@ -75,6 +84,9 @@ ADD_EXECUTABLE( VectorExample VectorExample.cpp ) ADD_CUSTOM_TARGET( run ALL DEPENDS FileExample.out FileExampleSaveAndLoad.out FileNameExample.out FileNameExampleDistributedSystemNodeCoordinates.out FileNameExampleDistributedSystemNodeId.out ObjectExample_getType.out ParseObjectTypeExample.out StringExample.out Loading src/Examples/FileNameExample.cpp 0 → 100644 +37 −0 Original line number Diff line number Diff line #include <iostream> #include <TNL/FileName.h> using namespace TNL; using namespace std; int main() { /*** * Create file name with filename base 'velocity' and extension 'vtk'. */ FileName fileName( "velocity-", "vtk" ); /** * Set the number of digits for the index to 2 and print file names for * indexes 0 to 10. */ fileName.setDigitsCount( 2 ); for( int i = 0; i <= 10; i ++ ) { fileName.setIndex( i ); std::cout << fileName.getFileName() << std::endl; } /*** * Now set the number if index digits to 3 and do the same. */ fileName.setDigitsCount( 3 ); for( int i = 0; i <= 10; i ++ ) { fileName.setIndex( i ); std::cout << fileName.getFileName() << std::endl; } } src/Examples/FileNameExampleDistributedSystemNodeCoordinates.cpp 0 → 100644 +34 −0 Original line number Diff line number Diff line #include <iostream> #include <TNL/FileName.h> #include <TNL/Containers/StaticVector.h> using namespace TNL; using namespace std; int main() { /** * Create file name with filename base 'velocity' and extension 'vtk'. */ FileName fileName( "velocity-", "vtk" ); /*** * Set the distributed system node ID to 0-0-0. */ using CoordinatesType = Containers::StaticVector< 3, int >; CoordinatesType coordinates( 0, 0, 0 ); fileName.setDistributedSystemNodeCoordinates( coordinates ); /** * Now set the file name index digits count to 2 and print file names * for indexes 0 to 10. */ fileName.setDigitsCount( 2 ); for( int i = 0; i <= 10; i ++ ) { fileName.setIndex( i ); std::cout << fileName.getFileName() << std::endl; } } src/Examples/FileNameExampleDistributedSystemNodeId.cpp 0 → 100644 +31 −0 Original line number Diff line number Diff line #include <iostream> #include <TNL/FileName.h> using namespace TNL; using namespace std; int main() { /** * Create file name with filename base 'velocity' and extension 'vtk'. */ FileName fileName( "velocity-", "vtk" ); /** * Set the distributed system node ID to 0; */ fileName.setDistributedSystemNodeId( 0 ); /** * Set the number of digits for the index to 2 and print file names for * indexes 0 to 10. */ fileName.setDigitsCount( 2 ); for( int i = 0; i <= 10; i ++ ) { fileName.setIndex( i ); std::cout << fileName.getFileName() << std::endl; } } src/TNL/FileName.h +98 −38 Original line number Diff line number Diff line Loading @@ -14,74 +14,117 @@ namespace TNL { String getFileExtension( const String fileName ); void removeFileExtension( String& file_name ); /*** * \brief Class for the construction of file names from multiple parts. /** * \brief Helper class for the construction of file names based on name, index and extension. * * Optionally, the file name can also handle node ID for distributed systems. * * Merges base name, index number and extension to create the full name of a file. * The following example demonstrates the use of FileName. * * \par Example * \include FileNameExample.cpp * \par Output * \include FileNameExample.out */ class FileName { public: /*** /** * \brief Basic constructor. * * Constructs an empty filename object. * Sets no file name base, index to zero and index digits count to five; */ FileName(); /** * \brief Constructor with file name base parameter. * * The index is set to zero and index digits count to five. * * @param fileNameBase File name base. */ FileName( const String& fileNameBase ); /** * \brief Constructor with file name base and file name extension. * * The index is set to zero and index digits count to five. * * @param fileNameBase File name base. * @param extension File name extension. */ FileName( const String& fileNameBase, const String& extension ); /*** * \brief Sets the base name of given file. /** * \brief Sets the file name base. * * Sets \e fileNameBase as the base name of given file. * @param fileNameBase String that specifies new name of file. * @param fileNameBase String that specifies the new file name base. */ void setFileNameBase( const String& fileNameBase ); /*** * \brief Sets the extension of given file. /** * \brief Sets the file name extension. * * Sets \e extension as suffix of a file name. * @param extension A String that specifies extension of file (without dot). * Suffix of a file name. E.g. doc, xls, tnl. * @param extension A String that specifies the new extension of file without dot. */ void setExtension( const String& extension ); /*** * \brief Sets index for given file. /** * \brief Sets index of the file name. * * Sets \e index after the base name of given file. * @param index Integer - number of maximum 5(default) digits. * (Number of digits can be changed with \ref setDigitsCount). * @param index Index of the file name. */ void setIndex( const int index ); void setIndex( const size_t index ); /*** * \brief Sets number of digits for index of given file. /** * \brief Sets number of digits for index of the file name. * * @param digitsCount Integer - number of digits. * @param digitsCount Number of digits. It is 5 by default. */ void setDigitsCount( const int digitsCount ); void setDigitsCount( const size_t digitsCount ); void setDistributedSystemNodeId( int nodeId ); /** * \brief Sets the distributed system node ID as integer, for example MPI process ID. * * @param nodeId Node ID. * * See the following example: * * \par Example * \include FileNameExampleDistributedSystemNodeId.cpp * \par Output * \include FileNameExampleDistributedSystemNodeId.out */ void setDistributedSystemNodeId( size_t nodeId ); /** * \brief Sets the distributed system node ID in a form of Cartesian coordinates. * * @tparam Coordinates Type of Cartesian coordinates. It is Containers::StaticVector usually. * @param nodeId Node ID in a form of Cartesian coordinates. * * See the following example: * * \par Example * \include FileNameExampleDistributedSystemNodeCoordinates.cpp * \par Output * \include FileNameExampleDistributedSystemNodeCoordinates.out * */ template< typename Coordinates > void setDistributedSystemNodeId( const Coordinates& nodeId ); void setDistributedSystemNodeCoordinates( const Coordinates& nodeId ); /** * \brief Resets the distributed system node ID. */ void resetDistributedSystemNodeId(); /*** * \brief Creates appropriate name for given file. /** * \brief Returns complete file name. * * Creates particular file name using \e fileNameBase, \e digitsCount, * \e index and \e extension. * @return String with the complete file name. */ String getFileName(); Loading @@ -89,9 +132,26 @@ class FileName String fileNameBase, extension, distributedSystemNodeId; int index, digitsCount; size_t index, digitsCount; }; /** * \brief Returns extension of given file name, i.e. part after the last dot. * * @param fileName Input file name. * * @return Extension of the given file name. */ String getFileExtension( const String fileName ); /** * \brief Cuts off the file extension. * * @param file_name Input file name. * @return String with the file name without extension. */ String removeFileNameExtension( String fileName ); } // namespace TNL #include <TNL/FileName.hpp> Loading
src/Examples/CMakeLists.txt +12 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,15 @@ ENDIF() ADD_EXECUTABLE( FileExampleSaveAndLoad FileExampleSaveAndLoad.cpp ) ADD_CUSTOM_COMMAND( COMMAND FileExampleSaveAndLoad > FileExampleSaveAndLoad.out OUTPUT FileExampleSaveAndLoad.out ) ADD_EXECUTABLE( FileNameExample FileNameExample.cpp ) ADD_CUSTOM_COMMAND( COMMAND FileNameExample > FileNameExample.out OUTPUT FileNameExample.out ) ADD_EXECUTABLE( FileNameExampleDistributedSystemNodeCoordinates FileNameExampleDistributedSystemNodeCoordinates.cpp ) ADD_CUSTOM_COMMAND( COMMAND FileNameExampleDistributedSystemNodeCoordinates > FileNameExampleDistributedSystemNodeCoordinates.out OUTPUT FileNameExampleDistributedSystemNodeCoordinates.out ) ADD_EXECUTABLE( FileNameExampleDistributedSystemNodeId FileNameExampleDistributedSystemNodeId.cpp ) ADD_CUSTOM_COMMAND( COMMAND FileNameExampleDistributedSystemNodeId > FileNameExampleDistributedSystemNodeId.out OUTPUT FileNameExampleDistributedSystemNodeId.out ) ADD_EXECUTABLE( ListExample ListExample.cpp ) ADD_EXECUTABLE( LoggerExample LoggerExample.cpp ) Loading Loading @@ -75,6 +84,9 @@ ADD_EXECUTABLE( VectorExample VectorExample.cpp ) ADD_CUSTOM_TARGET( run ALL DEPENDS FileExample.out FileExampleSaveAndLoad.out FileNameExample.out FileNameExampleDistributedSystemNodeCoordinates.out FileNameExampleDistributedSystemNodeId.out ObjectExample_getType.out ParseObjectTypeExample.out StringExample.out Loading
src/Examples/FileNameExample.cpp 0 → 100644 +37 −0 Original line number Diff line number Diff line #include <iostream> #include <TNL/FileName.h> using namespace TNL; using namespace std; int main() { /*** * Create file name with filename base 'velocity' and extension 'vtk'. */ FileName fileName( "velocity-", "vtk" ); /** * Set the number of digits for the index to 2 and print file names for * indexes 0 to 10. */ fileName.setDigitsCount( 2 ); for( int i = 0; i <= 10; i ++ ) { fileName.setIndex( i ); std::cout << fileName.getFileName() << std::endl; } /*** * Now set the number if index digits to 3 and do the same. */ fileName.setDigitsCount( 3 ); for( int i = 0; i <= 10; i ++ ) { fileName.setIndex( i ); std::cout << fileName.getFileName() << std::endl; } }
src/Examples/FileNameExampleDistributedSystemNodeCoordinates.cpp 0 → 100644 +34 −0 Original line number Diff line number Diff line #include <iostream> #include <TNL/FileName.h> #include <TNL/Containers/StaticVector.h> using namespace TNL; using namespace std; int main() { /** * Create file name with filename base 'velocity' and extension 'vtk'. */ FileName fileName( "velocity-", "vtk" ); /*** * Set the distributed system node ID to 0-0-0. */ using CoordinatesType = Containers::StaticVector< 3, int >; CoordinatesType coordinates( 0, 0, 0 ); fileName.setDistributedSystemNodeCoordinates( coordinates ); /** * Now set the file name index digits count to 2 and print file names * for indexes 0 to 10. */ fileName.setDigitsCount( 2 ); for( int i = 0; i <= 10; i ++ ) { fileName.setIndex( i ); std::cout << fileName.getFileName() << std::endl; } }
src/Examples/FileNameExampleDistributedSystemNodeId.cpp 0 → 100644 +31 −0 Original line number Diff line number Diff line #include <iostream> #include <TNL/FileName.h> using namespace TNL; using namespace std; int main() { /** * Create file name with filename base 'velocity' and extension 'vtk'. */ FileName fileName( "velocity-", "vtk" ); /** * Set the distributed system node ID to 0; */ fileName.setDistributedSystemNodeId( 0 ); /** * Set the number of digits for the index to 2 and print file names for * indexes 0 to 10. */ fileName.setDigitsCount( 2 ); for( int i = 0; i <= 10; i ++ ) { fileName.setIndex( i ); std::cout << fileName.getFileName() << std::endl; } }
src/TNL/FileName.h +98 −38 Original line number Diff line number Diff line Loading @@ -14,74 +14,117 @@ namespace TNL { String getFileExtension( const String fileName ); void removeFileExtension( String& file_name ); /*** * \brief Class for the construction of file names from multiple parts. /** * \brief Helper class for the construction of file names based on name, index and extension. * * Optionally, the file name can also handle node ID for distributed systems. * * Merges base name, index number and extension to create the full name of a file. * The following example demonstrates the use of FileName. * * \par Example * \include FileNameExample.cpp * \par Output * \include FileNameExample.out */ class FileName { public: /*** /** * \brief Basic constructor. * * Constructs an empty filename object. * Sets no file name base, index to zero and index digits count to five; */ FileName(); /** * \brief Constructor with file name base parameter. * * The index is set to zero and index digits count to five. * * @param fileNameBase File name base. */ FileName( const String& fileNameBase ); /** * \brief Constructor with file name base and file name extension. * * The index is set to zero and index digits count to five. * * @param fileNameBase File name base. * @param extension File name extension. */ FileName( const String& fileNameBase, const String& extension ); /*** * \brief Sets the base name of given file. /** * \brief Sets the file name base. * * Sets \e fileNameBase as the base name of given file. * @param fileNameBase String that specifies new name of file. * @param fileNameBase String that specifies the new file name base. */ void setFileNameBase( const String& fileNameBase ); /*** * \brief Sets the extension of given file. /** * \brief Sets the file name extension. * * Sets \e extension as suffix of a file name. * @param extension A String that specifies extension of file (without dot). * Suffix of a file name. E.g. doc, xls, tnl. * @param extension A String that specifies the new extension of file without dot. */ void setExtension( const String& extension ); /*** * \brief Sets index for given file. /** * \brief Sets index of the file name. * * Sets \e index after the base name of given file. * @param index Integer - number of maximum 5(default) digits. * (Number of digits can be changed with \ref setDigitsCount). * @param index Index of the file name. */ void setIndex( const int index ); void setIndex( const size_t index ); /*** * \brief Sets number of digits for index of given file. /** * \brief Sets number of digits for index of the file name. * * @param digitsCount Integer - number of digits. * @param digitsCount Number of digits. It is 5 by default. */ void setDigitsCount( const int digitsCount ); void setDigitsCount( const size_t digitsCount ); void setDistributedSystemNodeId( int nodeId ); /** * \brief Sets the distributed system node ID as integer, for example MPI process ID. * * @param nodeId Node ID. * * See the following example: * * \par Example * \include FileNameExampleDistributedSystemNodeId.cpp * \par Output * \include FileNameExampleDistributedSystemNodeId.out */ void setDistributedSystemNodeId( size_t nodeId ); /** * \brief Sets the distributed system node ID in a form of Cartesian coordinates. * * @tparam Coordinates Type of Cartesian coordinates. It is Containers::StaticVector usually. * @param nodeId Node ID in a form of Cartesian coordinates. * * See the following example: * * \par Example * \include FileNameExampleDistributedSystemNodeCoordinates.cpp * \par Output * \include FileNameExampleDistributedSystemNodeCoordinates.out * */ template< typename Coordinates > void setDistributedSystemNodeId( const Coordinates& nodeId ); void setDistributedSystemNodeCoordinates( const Coordinates& nodeId ); /** * \brief Resets the distributed system node ID. */ void resetDistributedSystemNodeId(); /*** * \brief Creates appropriate name for given file. /** * \brief Returns complete file name. * * Creates particular file name using \e fileNameBase, \e digitsCount, * \e index and \e extension. * @return String with the complete file name. */ String getFileName(); Loading @@ -89,9 +132,26 @@ class FileName String fileNameBase, extension, distributedSystemNodeId; int index, digitsCount; size_t index, digitsCount; }; /** * \brief Returns extension of given file name, i.e. part after the last dot. * * @param fileName Input file name. * * @return Extension of the given file name. */ String getFileExtension( const String fileName ); /** * \brief Cuts off the file extension. * * @param file_name Input file name. * @return String with the file name without extension. */ String removeFileNameExtension( String fileName ); } // namespace TNL #include <TNL/FileName.hpp>