FileSequence Class Reference

`#include <FileSequence.h>`

## Public Types

typedef std::vector< std::string > | StringVec

## Public Member Functions

const std::string & | filename (const size_t idx) const
| Returns a single filename.
const StringVec & | filenames () const
| Returns the full list of all filenames.
| FileSequence ()
| Default constructor. Creates an empty sequence.
| FileSequence (const std::string &sequence)
| Construct from a sequence string. If the sequence string is an actual filename, we become a 1-length sequence. If the sequence can't be resolved, we become a 0-length sequence.
size_t | size () const
| Number of files in sequence.

## Private Attributes

std::vector< std::string > | m_filenames
| Stores the resulting filenames.

## Detailed Description

Definition at line 63 of file FileSequence.h.

## Member Typedef Documentation

## StringVec

typedef std::vector<std::string> FileSequence::StringVec

Definition at line 70 of file FileSequence.h.

## Constructor & Destructor Documentation

## FileSequence() [1/2]

FileSequence::FileSequence | ( |  | ) |

inline

Default constructor. Creates an empty sequence.

Definition at line 75 of file FileSequence.h.

{ }

## FileSequence() [2/2]

FIELD3D_NAMESPACE_OPEN FileSequence::FileSequence | ( | const std::string & | sequence | ) |

Construct from a sequence string. If the sequence string is an actual filename, we become a 1-length sequence. If the sequence can't be resolved, we become a 0-length sequence.

Note
  Apart from checking if the sequence is itself a filename, no checks are made to see that the actual resulting files exist.

Definition at line 64 of file FileSequence.cpp.

{
// Example sequences: myfile.1-2@.f3d, myfile1-21#.f3d
// The number '1' in each of these is the 'sequence start'
// The numbers '2' and '21' are the 'sequence end'
const std::string k_numbers = "0123456789";
const std::string k_seqMarks = "#@";
const std::string k_framePlaceholder = "####";
const size_t npos = std::string::npos;
// Check for file by that name. If it exists, we are just that one file
if (fileExists(sequence)) {
m_filenames.push_back(sequence);
return;
}
// Find the sequence mark
const size_t seqMarkIdx = sequence.find_first_of(k_seqMarks);
// If no sequence mark was found, there is no sequence.
if (seqMarkIdx == npos) {
return;
}
// Make sure there is not more than one sequence mark
if (sequence.find_first_of(k_seqMarks, seqMarkIdx + 1) != npos) {
std::stringstream warning;
warning << "Multiple sequence marks in filename: " << sequence;
Msg::print(Msg::SevWarning, warning.str());
return;
}
// Get the end range index
size_t seqEndIdx = sequence.find_last_not_of(k_numbers, seqMarkIdx - 1);
if (seqEndIdx == npos) {
std::stringstream warning;
warning << "Sequence mark but no sequence range in filename: "
<< sequence;
Msg::print(Msg::SevWarning, warning.str());
return;
} else {
seqEndIdx += 1;
}
if (seqEndIdx == 0) {
std::stringstream warning;
warning << "Sequence mark preceded by single number: "
<< sequence;
Msg::print(Msg::SevWarning, warning.str());
return;
}
// Make sure the preceding character is '-'
if (sequence[seqEndIdx - 1] != '-') {
std::stringstream warning;
warning << "Sequence mark preceded by single number but no '-': "
<< sequence;
Msg::print(Msg::SevWarning, warning.str());
return;
}
// Get the start range index
size_t seqStartIdx = sequence.find_last_not_of(k_numbers, seqEndIdx - 2);
if (seqStartIdx == npos) {
std::stringstream warning;
warning << "No sequence start in filename: "
<< sequence;
Msg::print(Msg::SevWarning, warning.str());
return;
} else {
seqStartIdx += 1;
}
// String versions of frame numbers
const std::string startStr = sequence.substr(seqStartIdx, seqEndIdx - 1);
const std::string endStr = sequence.substr(seqEndIdx, seqMarkIdx);
// Get the integers
const int start = atoi(startStr.c_str());
const int end = atoi(endStr.c_str());
// Create the file basename for replacement
const std::string baseStart = sequence.substr(0, seqStartIdx);
const std::string baseEnd = sequence.substr(seqMarkIdx + 1);
// Create the filenames
for (int i = start; i <= end; ++i) {
std::stringstream filename;
filename << baseStart << i << baseEnd;
m_filenames.push_back(filename.str());
}
}
fileExists
bool fileExists(const std::string &filename)
checks to see if a file/directory exists or not
Definition Field3DFile.cpp:1341
FileSequence::filename
const std::string & filename(const size_t idx) const
Returns a single filename.
Definition FileSequence.h:89
FileSequence::m_filenames
std::vector< std::string > m_filenames
Stores the resulting filenames.
Definition FileSequence.h:101
Msg::SevWarning
@ SevWarning
Definition Log.h:68
Msg::print
FIELD3D_API void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity.
Definition Log.cpp:70

References fileExists(), filename(), m_filenames, Msg::print(), and Msg::SevWarning.

## Member Function Documentation

## size()

size_t FileSequence::size | ( |  | ) | const

inline

Number of files in sequence.

Definition at line 85 of file FileSequence.h.

{ return m_filenames.size(); }

References m_filenames.

## filename()

const std::string & FileSequence::filename | ( | const size_t | idx | ) | const

inline

Returns a single filename.

Definition at line 89 of file FileSequence.h.

{ return m_filenames[idx]; }

References m_filenames.

Referenced by FileSequence().

## filenames()

const StringVec & FileSequence::filenames | ( |  | ) | const

inline

Returns the full list of all filenames.

Definition at line 93 of file FileSequence.h.

{ return m_filenames; }

References m_filenames.

## Member Data Documentation

## m_filenames

std::vector<std::string> FileSequence::m_filenames

private

Stores the resulting filenames.

Definition at line 101 of file FileSequence.h.

Referenced by filename(), filenames(), FileSequence(), and size().

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

- export/FileSequence.h
- src/FileSequence.cpp