Field3D
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 StringVecfilenames () 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.

76 { }

◆ 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.

65{
66 // Example sequences: myfile.1-2@.f3d, myfile1-21#.f3d
67 // The number '1' in each of these is the 'sequence start'
68 // The numbers '2' and '21' are the 'sequence end'
69
70 const std::string k_numbers = "0123456789";
71 const std::string k_seqMarks = "#@";
72 const std::string k_framePlaceholder = "####";
73 const size_t npos = std::string::npos;
74
75 // Check for file by that name. If it exists, we are just that one file
76 if (fileExists(sequence)) {
77 m_filenames.push_back(sequence);
78 return;
79 }
80
81 // Find the sequence mark
82 const size_t seqMarkIdx = sequence.find_first_of(k_seqMarks);
83
84 // If no sequence mark was found, there is no sequence.
85 if (seqMarkIdx == npos) {
86 return;
87 }
88
89 // Make sure there is not more than one sequence mark
90 if (sequence.find_first_of(k_seqMarks, seqMarkIdx + 1) != npos) {
91 std::stringstream warning;
92 warning << "Multiple sequence marks in filename: " << sequence;
94 return;
95 }
96
97 // Get the end range index
98 size_t seqEndIdx = sequence.find_last_not_of(k_numbers, seqMarkIdx - 1);
99 if (seqEndIdx == npos) {
100 std::stringstream warning;
101 warning << "Sequence mark but no sequence range in filename: "
102 << sequence;
104 return;
105 } else {
106 seqEndIdx += 1;
107 }
108 if (seqEndIdx == 0) {
109 std::stringstream warning;
110 warning << "Sequence mark preceded by single number: "
111 << sequence;
113 return;
114 }
115
116 // Make sure the preceding character is '-'
117 if (sequence[seqEndIdx - 1] != '-') {
118 std::stringstream warning;
119 warning << "Sequence mark preceded by single number but no '-': "
120 << sequence;
122 return;
123 }
124
125 // Get the start range index
126 size_t seqStartIdx = sequence.find_last_not_of(k_numbers, seqEndIdx - 2);
127 if (seqStartIdx == npos) {
128 std::stringstream warning;
129 warning << "No sequence start in filename: "
130 << sequence;
132 return;
133 } else {
134 seqStartIdx += 1;
135 }
136
137 // String versions of frame numbers
138 const std::string startStr = sequence.substr(seqStartIdx, seqEndIdx - 1);
139 const std::string endStr = sequence.substr(seqEndIdx, seqMarkIdx);
140
141 // Get the integers
142 const int start = atoi(startStr.c_str());
143 const int end = atoi(endStr.c_str());
144
145 // Create the file basename for replacement
146 const std::string baseStart = sequence.substr(0, seqStartIdx);
147 const std::string baseEnd = sequence.substr(seqMarkIdx + 1);
148
149 // Create the filenames
150 for (int i = start; i <= end; ++i) {
151 std::stringstream filename;
152 filename << baseStart << i << baseEnd;
153 m_filenames.push_back(filename.str());
154 }
155}
bool fileExists(const std::string &filename)
checks to see if a file/directory exists or not
#define FIELD3D_MTX_T
Definition StdMathLib.h:99
const std::string & filename(const size_t idx) const
Returns a single filename.
std::vector< std::string > m_filenames
Stores the resulting filenames.
@ SevWarning
Definition Log.h:68
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 FIELD3D_MTX_T, 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.

86 { 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.

90 { return m_filenames[idx]; }

References FIELD3D_MTX_T, and 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.

94 { 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: