NSF Postdoctoral Research
A set of C++ code developed by Andrew E. Slaughter
|
A class for simple file name handling. More...
#include <common/file_parts/file_parts.h>
Public Member Functions | |
FileParts () | |
Default constructor. | |
FileParts (std::string str) | |
Cconstructor, string input version. | |
FileParts (const char *c_str) | |
Constructor, char input version. | |
void | display () |
A function that displays the various parts of the file. | |
void | update () |
A function for updating the full file path. | |
void | assign (std::string str) |
Assign member allows user to initilize class after decleration. | |
void | assign (const char *c_str) |
Assign member using char* as input. | |
std::string | add_tstep (int tstep, int pad=3, const char *prfx="") |
Special function for inserting a time series stamp. | |
Public Attributes | |
std::string | full |
The complete file name and path as input. | |
std::string | path |
The directory of the file name. | |
std::string | name |
The file name without the path or extension. | |
std::string | ext |
The file name extension, including the period. | |
bool | exist |
A boolean flag indicating if the file exists. |
A class for simple file name handling.
On creation it seperates the file into components as well as tests for it existance.
Example usage:
FileParts filename(/my/path/and/file.txt); FILE* fid = fopen(filename.full,'r'); ... gather some data ... fclose(fid);
FileParts::FileParts | ( | std::string | str | ) |
Cconstructor, string input version.
Creates a FileParts object using a std::string input
str | A standard string containing the complete file name and path |
FileParts::FileParts | ( | const char * | c_str | ) |
Constructor, char input version.
Creates a FileParts object with a const char* input
c_str | A char* containing the complete file name and path |
std::string FileParts::add_tstep | ( | int | tstep, |
int | pad = 3 , |
||
const char * | prfx = "" |
||
) |
Special function for inserting a time series stamp.
tstep | An interger value containing the time step |
pad | An interger value containing the zero padding level, the default is 3. |
prfx | A char that is inserted between the filename and the numeric time step. The default is an empty value. |
The following code retuns the following strings with a time stamp inserted, it does not edit the object itself:
path/to/a/file_0222.txt
FileParts filename; filename.assign("path/to/a/file.txt"); std::string str = filename.add_tstep(222, 4, "_"); printf("%s\n", str.c_str());
void FileParts::assign | ( | std::string | str | ) |
Assign member allows user to initilize class after decleration.
In some instances the class must be declared before the complete file path is known. As such, it should be possible to do the following, which this operator enables.
str | A standard string containing the complete file name and path FileParts filename; filname.assign("path/to/a/file.txt"); |
void FileParts::assign | ( | const char * | c_str | ) |
Assign member using char* as input.
c_str | A char* containing the complete file name and path |
void FileParts::update | ( | ) |
A function for updating the full file path.
This allows for the user to alter the components and then create a full file path from these new complnents. For example:
FileParts filename("path/to/a/file.txt"); filename.name.append("2"); filename.update();