Template Numerical Library version\ main:f17d0c8
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
TNL::FileName Class Reference

Helper class for the construction of file names based on name, index and extension. More...

#include <TNL/FileName.h>

Collaboration diagram for TNL::FileName:
Collaboration graph
[legend]

Public Member Functions

 FileName ()=default
 Basic constructor.
 
 FileName (String fileNameBase)
 Constructor with file name base parameter.
 
 FileName (String fileNameBase, String extension)
 Constructor with file name base and file name extension.
 
String getFileName ()
 Returns complete file name.
 
void resetDistributedSystemNodeId ()
 Resets the distributed system node ID.
 
void setDigitsCount (size_t digitsCount)
 Sets number of digits for index of the file name.
 
template<typename Coordinates >
void setDistributedSystemNodeCoordinates (const Coordinates &nodeId)
 Sets the distributed system node ID in a form of Cartesian coordinates.
 
void setDistributedSystemNodeId (size_t nodeId)
 Sets the distributed system node ID as integer, for example MPI process ID.
 
void setExtension (const String &extension)
 Sets the file name extension.
 
void setFileNameBase (const String &fileNameBase)
 Sets the file name base.
 
void setIndex (size_t index)
 Sets index of the file name.
 

Protected Attributes

std::size_t digitsCount = 5
 
String distributedSystemNodeId
 
String extension
 
String fileNameBase
 
std::size_t index = 0
 

Detailed Description

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.

The following example demonstrates the use of FileName.

Example
#include <iostream>
#include <TNL/FileName.h>
using namespace TNL;
int
main()
{
/***
* Create file name with filename base 'velocity' and extension 'vtk'.
*/
FileName fileName( "velocity-", "vtk" );
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;
}
}
Helper class for the construction of file names based on name, index and extension.
Definition FileName.h:23
T endl(T... args)
The main TNL namespace.
Definition AtomicOperations.h:9
Output
velocity-00.vtk
velocity-01.vtk
velocity-02.vtk
velocity-03.vtk
velocity-04.vtk
velocity-05.vtk
velocity-06.vtk
velocity-07.vtk
velocity-08.vtk
velocity-09.vtk
velocity-10.vtk
velocity-000.vtk
velocity-001.vtk
velocity-002.vtk
velocity-003.vtk
velocity-004.vtk
velocity-005.vtk
velocity-006.vtk
velocity-007.vtk
velocity-008.vtk
velocity-009.vtk
velocity-010.vtk

Constructor & Destructor Documentation

◆ FileName() [1/3]

TNL::FileName::FileName ( )
default

Basic constructor.

Sets no file name base, index to zero and index digits count to five;

◆ FileName() [2/3]

TNL::FileName::FileName ( String fileNameBase)
inline

Constructor with file name base parameter.

The index is set to zero and index digits count to five.

Parameters
fileNameBaseFile name base.

◆ FileName() [3/3]

TNL::FileName::FileName ( String fileNameBase,
String extension )
inline

Constructor with file name base and file name extension.

The index is set to zero and index digits count to five.

Parameters
fileNameBaseFile name base.
extensionFile name extension.

Member Function Documentation

◆ getFileName()

String TNL::FileName::getFileName ( )
inline

Returns complete file name.

Returns
String with the complete file name.

◆ setDigitsCount()

void TNL::FileName::setDigitsCount ( size_t digitsCount)
inline

Sets number of digits for index of the file name.

Parameters
digitsCountNumber of digits. It is 5 by default.

◆ setDistributedSystemNodeCoordinates()

template<typename Coordinates >
void TNL::FileName::setDistributedSystemNodeCoordinates ( const Coordinates & nodeId)

Sets the distributed system node ID in a form of Cartesian coordinates.

Template Parameters
CoordinatesType of Cartesian coordinates. It is Containers::StaticVector usually.
Parameters
nodeIdNode ID in a form of Cartesian coordinates.

See the following example:

Example
#include <iostream>
#include <TNL/FileName.h>
#include <TNL/Containers/StaticVector.h>
using namespace TNL;
int
main()
{
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 );
fileName.setDigitsCount( 2 );
for( int i = 0; i <= 10; i++ ) {
fileName.setIndex( i );
std::cout << fileName.getFileName() << std::endl;
}
}
Vector with constant size.
Definition StaticVector.h:19
Output
velocity-00-@0-0-0.vtk
velocity-01-@0-0-0.vtk
velocity-02-@0-0-0.vtk
velocity-03-@0-0-0.vtk
velocity-04-@0-0-0.vtk
velocity-05-@0-0-0.vtk
velocity-06-@0-0-0.vtk
velocity-07-@0-0-0.vtk
velocity-08-@0-0-0.vtk
velocity-09-@0-0-0.vtk
velocity-10-@0-0-0.vtk

◆ setDistributedSystemNodeId()

void TNL::FileName::setDistributedSystemNodeId ( size_t nodeId)
inline

Sets the distributed system node ID as integer, for example MPI process ID.

Parameters
nodeIdNode ID.

See the following example:

Example
#include <iostream>
#include <TNL/FileName.h>
using namespace TNL;
int
main()
{
FileName fileName( "velocity-", "vtk" );
fileName.setDistributedSystemNodeId( 0 );
fileName.setDigitsCount( 2 );
for( int i = 0; i <= 10; i++ ) {
fileName.setIndex( i );
std::cout << fileName.getFileName() << std::endl;
}
}
Output
velocity-00-@0.vtk
velocity-01-@0.vtk
velocity-02-@0.vtk
velocity-03-@0.vtk
velocity-04-@0.vtk
velocity-05-@0.vtk
velocity-06-@0.vtk
velocity-07-@0.vtk
velocity-08-@0.vtk
velocity-09-@0.vtk
velocity-10-@0.vtk

◆ setExtension()

void TNL::FileName::setExtension ( const String & extension)
inline

Sets the file name extension.

Parameters
extensionA String that specifies the new extension of file without dot.

◆ setFileNameBase()

void TNL::FileName::setFileNameBase ( const String & fileNameBase)
inline

Sets the file name base.

Parameters
fileNameBaseString that specifies the new file name base.

◆ setIndex()

void TNL::FileName::setIndex ( size_t index)
inline

Sets index of the file name.

Parameters
indexIndex of the file name.

The documentation for this class was generated from the following files: