18#include <fairlogger/Logger.h>
28const char* FileWatcher::mLowGuard =
" 0";
29const char* FileWatcher::mEndGuard =
"~0";
34 this->mDataFolders =
path;
35 this->mCurrentFile = mEndGuard;
37 this->mFiles.push_front(mLowGuard);
38 this->mFiles.push_back(mEndGuard);
43 if (this->mDataFolders.size() == 1 && this->mDataFolders[0] ==
path) {
46 this->mDataFolders.clear();
47 this->mDataFolders.push_back(
path);
48 this->mCurrentFile = mEndGuard;
50 this->mFiles.push_front(mLowGuard);
51 this->mFiles.push_back(mEndGuard);
58 if (this->mDataFolders ==
paths) {
61 this->mDataFolders.clear();
62 this->mDataFolders =
paths;
63 this->mCurrentFile = mEndGuard;
65 this->mFiles.push_front(mLowGuard);
66 this->mFiles.push_back(mEndGuard);
71string FileWatcher::nextItem(
const string& item)
const
73 if (item == mEndGuard) {
76 return *(std::find(this->mFiles.begin(), this->mFiles.end(), item) + 1);
79string FileWatcher::prevItem(
const string& item)
const
81 if (item == mLowGuard) {
84 return *(std::find(mFiles.begin(), mFiles.end(), item) - 1);
89 if (this->mFiles.size() == 2) {
92 if (this->mCurrentFile == mLowGuard) {
93 return *(this->mFiles.begin() + 1);
95 if (this->mCurrentFile == mEndGuard) {
96 return *(this->mFiles.end() - 2);
98 return this->mCurrentFile;
103 if (this->mFiles.size() == 2) {
107 if (this->mCurrentFile == mEndGuard) {
115 this->mCurrentFile = mLowGuard;
120 this->mCurrentFile = mEndGuard;
125 this->mCurrentFile = nextItem(this->mCurrentFile);
130 this->mCurrentFile = prevItem(this->mCurrentFile);
135 return this->mFiles.size();
140 return std::distance(mFiles.begin(), std::find(mFiles.begin(), mFiles.end(), this->mCurrentFile));
146 LOGF(info,
"previous:", previous);
147 LOGF(info,
"currentFile:", this->mCurrentFile);
150 if (this->mCurrentFile != mEndGuard) {
151 if (this->mFiles.empty()) {
152 this->mCurrentFile = mEndGuard;
153 }
else if (this->mCurrentFile < *(this->mFiles.begin())) {
154 this->mCurrentFile = mLowGuard;
156 auto it = std::find(mFiles.begin(), mFiles.end(), this->mCurrentFile);
157 if (it == this->mFiles.end()) {
158 this->mCurrentFile = mEndGuard;
165 this->mFiles.push_front(mLowGuard);
166 this->mFiles.push_back(mEndGuard);
168 LOGF(info,
"this->mFiles.size() = ", this->mFiles.size());
169 LOGF(info,
"this->mCurrentFile = ", this->mCurrentFile);
176 this->mCurrentFile = this->mFiles[no];
177 LOGF(info,
"this->setCurrentItem(", no,
")");
178 LOGF(info,
"this->mCurrentFile = ", this->mCurrentFile);
183 if (this->mDataFolders.size() > 1) {
184 for (std::string dataFolder : mDataFolders) {
192 return this->mDataFolders[0] +
"/" + this->
currentItem();
195bool FileWatcher::currentFileExist()
203 if (!std::filesystem::exists(destinationFolder)) {
206 for (
const auto& folder : this->mDataFolders) {
207 if (folder == destinationFolder) {
211 if (this->currentFileExist()) {
213 std::filesystem::path destination = destinationFolder;
214 destination /=
source.filename();
215 std::filesystem::copy_file(
source, destination);
Loading content of the Folder and returning sorted.
Observing folder for created and removed files - preserving current.
static std::deque< std::string > load(const std::string &path, const std::string &marker, const std::vector< std::string > &ext)
std::string currentFilePath() const
name of the file (with path) but guards replaced with file names
void saveCurrentFileToFolder(const std::string &destinationFolder)
copies
FileWatcher(const std::vector< std::string > &path, const std::vector< std::string > &ext)
stop guard
int getPos() const
include guards -> 0 points to mLowGuard
void setCurrentItem(int no)
sets using index
void rollToNext()
round robin next item
std::string currentItem() const
name of the file (without path) but guards replaced with file names
bool refresh()
reads folder content, updates current if points to not existing file
int getSize() const
include guards (so >=2 )
void changeFolder(const std::string &path)
switch to observe other folder
GLsizei GLsizei GLchar * source
GLsizei const GLuint * paths
GLsizei const GLchar *const * path
Defining DataPointCompositeObject explicitly as copiable.