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) {
49 return path.substr(pos + 1);
70 for (
char const& ch :
s)
72 if (std::isdigit(ch) == 0)
84 if (
split.size() != 3)
98 std::filesystem::path p = base;
99 if (
id.hasMemoryName())
103 if (
id.hasCoreSegmentName())
107 if (
id.hasProviderSegmentName())
111 if (
id.hasEntityName())
115 if (
id.hasTimestamp())
119 p /=
id.timestampStr();
121 if (
id.hasInstanceIndex())
123 p /=
id.instanceIndexStr();
132 return std::filesystem::exists(p) and std::filesystem::is_directory(p);
138 return std::filesystem::exists(p) && std::filesystem::is_regular_file(p);
146 if (createIfNotExistent)
148 std::filesystem::create_directories(p);
152 throw armarx::LocalException(
"Directory existence cannot be ensured: " +
164 if (createIfNotExistent)
166 std::string content =
"";
172 throw armarx::LocalException(
"Could not find file: " + p.string());
180 std::ofstream dataofs;
184 throw armarx::LocalException(
"Could not write data to filesystem file '" + p.string() +
185 "'. Skipping this file.");
187 dataofs.write(
reinterpret_cast<const char*
>(
data.data()),
data.size());
191 std::vector<unsigned char>
194 std::ifstream dataifs(p);
195 std::vector<unsigned char> datafilecontent((std::istreambuf_iterator<char>(dataifs)),
196 (std::istreambuf_iterator<char>()));
198 return datafilecontent;
201 std::vector<std::filesystem::path>
204 std::vector<std::filesystem::path>
ret;
205 for (
const auto& subdir : std::filesystem::directory_iterator(p))
207 std::filesystem::path subdirPath = subdir.path();
208 if (std::filesystem::is_directory(subdirPath))
210 ret.push_back(subdirPath);
213 std::sort(
ret.begin(),
215 [](
const std::filesystem::path&
a,
const std::filesystem::path& b) ->
bool
216 { return a.string() < b.string(); });
220 std::vector<std::filesystem::path>
223 std::vector<std::filesystem::path>
ret;
224 for (
const auto& subdir : std::filesystem::directory_iterator(p))
226 std::filesystem::path subdirPath = subdir.path();
227 if (std::filesystem::is_regular_file(subdirPath))
229 ret.push_back(subdirPath);
232 std::sort(
ret.begin(),
234 [](
const std::filesystem::path&
a,
const std::filesystem::path& b) ->
bool
235 { return a.string() > b.string(); });