NSF Postdoctoral Research
A set of C++ code developed by Andrew E. Slaughter
SlaughterCommon::FileParts Class Reference

A class for simple file name handling. More...

#include <common/file_parts/file_parts.h>

List of all members.

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.

Detailed Description

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);
Examples:
fem/examples/example1.cpp, fem/examples/example2.cpp, and test_file_parts.cpp.

Constructor & Destructor Documentation

FileParts::FileParts ( std::string  str)

Cconstructor, string input version.

Creates a FileParts object using a std::string input

Parameters:
strA 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

Parameters:
c_strA char* containing the complete file name and path

Member Function Documentation

std::string FileParts::add_tstep ( int  tstep,
int  pad = 3,
const char *  prfx = "" 
)

Special function for inserting a time series stamp.

Parameters:
tstepAn interger value containing the time step
padAn interger value containing the zero padding level, the default is 3.
prfxA 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());
Examples:
test_file_parts.cpp.
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.

Parameters:
strA standard string containing the complete file name and path
 FileParts filename;
 filname.assign("path/to/a/file.txt");
Examples:
test_file_parts.cpp.
void FileParts::assign ( const char *  c_str)

Assign member using char* as input.

Parameters:
c_strA char* containing the complete file name and path

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();

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs