6 #include <SimoxUtility/algorithm/string.h>
21 std::string
ret = segmentName;
25 ret = simox::alg::replace_all(
ret,
s, r);
33 std::string
ret = escapedName;
38 ret = simox::alg::replace_all(
ret, r,
s);
46 size_t pos = path.rfind(
'/');
48 if (pos != std::string::npos)
50 return path.substr(pos + 1);
73 for (
char const& ch :
s)
75 if (std::isdigit(ch) == 0)
87 if (
split.size() != 3)
101 std::filesystem::path p = base;
102 if (
id.hasMemoryName())
106 if (
id.hasCoreSegmentName())
110 if (
id.hasProviderSegmentName())
114 if (
id.hasEntityName())
118 if (
id.hasTimestamp())
122 p /=
id.timestampStr();
124 if (
id.hasInstanceIndex())
126 p /=
id.instanceIndexStr();
135 return std::filesystem::exists(p) and std::filesystem::is_directory(p);
141 return std::filesystem::exists(p) && std::filesystem::is_regular_file(p);
149 if (createIfNotExistent)
151 std::filesystem::create_directories(p);
155 throw armarx::LocalException(
"Directory existence cannot be ensured: " +
167 if (createIfNotExistent)
169 std::string content =
"";
175 throw armarx::LocalException(
"Could not find file: " + p.string());
183 std::ofstream dataofs;
187 throw armarx::LocalException(
"Could not write data to filesystem file '" + p.string() +
188 "'. Skipping this file.");
190 dataofs.write(
reinterpret_cast<const char*
>(
data.data()),
data.size());
194 std::vector<unsigned char>
197 std::ifstream dataifs(p);
198 std::vector<unsigned char> datafilecontent((std::istreambuf_iterator<char>(dataifs)),
199 (std::istreambuf_iterator<char>()));
201 return datafilecontent;
204 std::vector<std::filesystem::path>
207 std::vector<std::filesystem::path>
ret;
208 for (
const auto& subdir : std::filesystem::directory_iterator(p))
210 std::filesystem::path subdirPath = subdir.path();
211 if (std::filesystem::is_directory(subdirPath))
213 ret.push_back(subdirPath);
216 std::sort(
ret.begin(),
218 [](
const std::filesystem::path&
a,
const std::filesystem::path& b) ->
bool
219 { return a.string() < b.string(); });
223 std::vector<std::filesystem::path>
226 std::vector<std::filesystem::path>
ret;
227 for (
const auto& subdir : std::filesystem::directory_iterator(p))
229 std::filesystem::path subdirPath = subdir.path();
230 if (std::filesystem::is_regular_file(subdirPath))
232 ret.push_back(subdirPath);
235 std::sort(
ret.begin(),
237 [](
const std::filesystem::path&
a,
const std::filesystem::path& b) ->
bool
238 { return a.string() > b.string(); });