...
This commit is contained in:
@@ -108,7 +108,7 @@ public:
|
||||
_inlineComment[_hashes[I]] = rec.inline_comment;
|
||||
};
|
||||
|
||||
[&, this]<size_t... Is>(std::index_sequence<Is...>) {
|
||||
[&]<size_t... Is>(std::index_sequence<Is...>) {
|
||||
(get_comm.template operator()<Is>(), ...);
|
||||
}(std::make_index_sequence<Asibfm700MountConfiguration::NUMBER_OF_RECORDS>{});
|
||||
}
|
||||
@@ -133,48 +133,51 @@ public:
|
||||
fst.close();
|
||||
|
||||
// remove possible header (see "save" method)
|
||||
size_t nskip = 5;
|
||||
auto lines = std::views::split(buffer, DEFAULT_RECORD_DELIMITER);
|
||||
if (std::ranges::distance(lines.begin(), lines.end()) >= 5) {
|
||||
bool head_exists = true;
|
||||
std::vector<std::string_view> tl;
|
||||
for (auto const& l : lines) { // lines must start with COMMENT_SEQ
|
||||
tl.emplace_back(mcc::utils::trimSpaces(l));
|
||||
if (tl.back().size() >= COMMENT_SEQ.size()) {
|
||||
auto found = std::ranges::search(tl.back(), COMMENT_SEQ);
|
||||
if (tl.back().begin() != found.begin()) {
|
||||
head_exists = false;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
head_exists = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (head_exists) {
|
||||
// the first and last lines must contain only a comment sequence and possible spaces
|
||||
if (tl[0].size() != COMMENT_SEQ.size() || tl[3].size() != COMMENT_SEQ.size()) {
|
||||
head_exists = false;
|
||||
} else {
|
||||
if (tl[1] != "# ASTROSIB FM-700 MOUNT CONFIGURATION") {
|
||||
head_exists = false;
|
||||
} else {
|
||||
std::regex rx{
|
||||
"# \\(created at "
|
||||
"20[0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\\.[0-9] "
|
||||
"UTC\\)"};
|
||||
|
||||
if (!std::regex_match(std::string{tl[2]}, rx)) {
|
||||
head_exists = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!head_exists) { // delete the first N lines
|
||||
size_t nskip = headerLines;
|
||||
if (!std::regex_match(buffer, headerRx)) {
|
||||
nskip = 0;
|
||||
}
|
||||
}
|
||||
// auto lines = std::views::split(buffer, DEFAULT_RECORD_DELIMITER);
|
||||
// if (std::ranges::distance(lines.begin(), lines.end()) >= 5) {
|
||||
// bool head_exists = true;
|
||||
// std::vector<std::string_view> tl;
|
||||
// for (auto const& l : lines) { // lines must start with COMMENT_SEQ
|
||||
// tl.emplace_back(mcc::utils::trimSpaces(l));
|
||||
// if (tl.back().size() >= COMMENT_SEQ.size()) {
|
||||
// auto found = std::ranges::search(tl.back(), COMMENT_SEQ);
|
||||
// if (tl.back().begin() != found.begin()) {
|
||||
// head_exists = false;
|
||||
// break;
|
||||
// }
|
||||
// } else {
|
||||
// head_exists = false;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if (head_exists) {
|
||||
// // the first and last lines must contain only a comment sequence and possible spaces
|
||||
// if (tl[0].size() != COMMENT_SEQ.size() || tl[3].size() != COMMENT_SEQ.size()) {
|
||||
// head_exists = false;
|
||||
// } else {
|
||||
// if (tl[1] != "# ASTROSIB FM-700 MOUNT CONFIGURATION") {
|
||||
// head_exists = false;
|
||||
// } else {
|
||||
// std::regex rx{
|
||||
// "# \\(created at "
|
||||
// "20[0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\\.[0-9] "
|
||||
// "UTC\\)"};
|
||||
|
||||
// if (!std::regex_match(std::string{tl[2]}, rx)) {
|
||||
// head_exists = false;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (!head_exists) { // delete the first N lines
|
||||
// nskip = 0;
|
||||
// }
|
||||
// }
|
||||
|
||||
ec = base_t::fromCharRange(buffer, nskip);
|
||||
if (!ec) {
|
||||
@@ -275,6 +278,8 @@ public:
|
||||
private:
|
||||
std::filesystem::path _lastConfigPath{};
|
||||
|
||||
static constexpr size_t headerLines = 5; // number of lines in the header
|
||||
|
||||
static std::string generateHeader()
|
||||
{
|
||||
std::string s{
|
||||
@@ -286,6 +291,12 @@ private:
|
||||
std::back_inserter(s), "# (created at {:%FT%T} UTC)\n#\n",
|
||||
std::chrono::round<std::chrono::duration<int64_t, std::ratio<1, 10>>>(std::chrono::system_clock::now()));
|
||||
|
||||
// auto time_stamp =
|
||||
// std::chrono::round<std::chrono::duration<int64_t, std::ratio<1, 10>>>(std::chrono::system_clock::now());
|
||||
// std::string s = std::format(
|
||||
// "{0:}{1:}{0:} ASTROSIB FM-700 MOUNT CONFIGURATION{1:}{0:}{1:}{0:} (created at {2:%FT%T}
|
||||
// UTC){1:}{0:}{1:}", COMMENT_SEQ, rec_delim, time_stamp);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user