WARPXM v1.10.0
Loading...
Searching...
No Matches
wmiointerface.h
Go to the documentation of this file.
1#ifndef WMIOINTERFACE_H
2#define WMIOINTERFACE_H
3
4// STL includes
5#include <string>
6#include <fstream>
7#include <cmath>
8
9namespace WmIOInterface
10{
11
12inline bool fileExists(const std::string& filename)
13{
14 std::ifstream file(filename.c_str());
15 const bool exists = bool(file);
16 file.close();
17 return exists;
18}
19
20inline int scanForFileIndexWithPrefixSuffix(const std::string& prefix,
21 const std::string& suffix,
22 const int startIndex,
23 const int endIndex)
24{
25 // start scanning from the back
26 for (int i = endIndex; i >= startIndex; --i)
27 {
28 std::stringstream ss;
29 ss << prefix << i << suffix;
30 if (fileExists(ss.str()))
31 {
32 return i;
33 }
34 }
35 return std::min(startIndex, endIndex) - 1;
36}
37
38inline std::string scanForFileWithPrefixSuffix(const std::string& prefix,
39 const std::string& suffix,
40 const int startIndex,
41 const int endIndex)
42{
43 const int possibleIndex =
44 scanForFileIndexWithPrefixSuffix(prefix, suffix, startIndex, endIndex);
45 if (possibleIndex == std::min(startIndex, endIndex) - 1)
46 {
47 return std::string();
48 }
49 std::stringstream ss;
50 ss << prefix << possibleIndex << suffix;
51 return ss.str();
52}
53} // namespace WmIOInterface
54
55#endif // WMIOINTERFACE_H
Definition: wmiointerface.h:10
std::string scanForFileWithPrefixSuffix(const std::string &prefix, const std::string &suffix, const int startIndex, const int endIndex)
Definition: wmiointerface.h:38
bool fileExists(const std::string &filename)
Definition: wmiointerface.h:12
int scanForFileIndexWithPrefixSuffix(const std::string &prefix, const std::string &suffix, const int startIndex, const int endIndex)
Definition: wmiointerface.h:20