Snapshots

This commit is contained in:
Robin Davies
2024-10-03 07:27:13 -04:00
parent 0b7078b592
commit 7821872016
69 changed files with 6070 additions and 1169 deletions
+1 -23
View File
@@ -23,6 +23,7 @@
*/
#include "ConfigSerializer.hpp"
#include "util.hpp"
using namespace config_serializer;
@@ -38,29 +39,6 @@ std::string config_serializer::detail::trim(const std::string &v)
return v.substr(start, end+1 - start);
}
std::vector<std::string> config_serializer::detail::split(const std::string &value, char delimiter)
{
size_t start = 0;
std::vector<std::string> result;
while (start < value.length())
{
size_t pos = value.find_first_of(delimiter, start);
if (pos == std::string::npos)
{
result.push_back(value.substr(start));
break;
}
result.push_back(value.substr(start, pos - start));
start = pos + 1;
if (start == value.length())
{
// ends with delimieter? Then there's an empty-length value at the end.
result.push_back("");
}
}
return result;
}
std::string config_serializer::detail::EncodeString(const std::string &s)
@@ -31,6 +31,9 @@
#include <unordered_map>
#include <fstream>
#include "ofstream_synced.hpp"
#include "util.hpp"
using namespace pipedal;
namespace config_serializer
{
@@ -38,8 +41,6 @@ namespace config_serializer
{
std::string trim(const std::string &v);
std::vector<std::string> split(const std::string &v, char seperator);
/**
* @brief Convert string to config file format.
*
+16 -4
View File
@@ -586,7 +586,11 @@ namespace pipedal
template <typename T>
void write(const std::shared_ptr<T> &obj)
{
write(obj.get());
if (!obj) {
write_raw("null");
} else {
write(obj.get());
}
}
template <typename T>
void write(const std::weak_ptr<T> &obj)
@@ -865,10 +869,18 @@ namespace pipedal
template <typename T>
void read(std::shared_ptr<T> *pUniquePtr)
{
std::shared_ptr<T> p = std::make_shared<T>();
if (peek() == 'n')
{
consumeToken("null", "Expecting '{' or 'null'.");
*pUniquePtr = nullptr;
read(p.get());
(*pUniquePtr) = std::move(p);
} else
{
std::shared_ptr<T> p = std::make_shared<T>();
read(p.get());
(*pUniquePtr) = std::move(p);
}
}
template <typename T>
void read(std::weak_ptr<T> *pUniquePtr)
+29
View File
@@ -23,6 +23,9 @@
#pragma once
#include <string>
#include <filesystem>
#include <vector>
#include <barrier>
#include <atomic>
namespace pipedal {
@@ -38,4 +41,30 @@ namespace pipedal {
std::string GetHostName();
std::vector<std::string> split(const std::string &value, char delimiter);
inline void ReadBarrier() {
std::atomic_thread_fence(std::memory_order::acquire);
}
inline void WriteBarrier() {
std::atomic_thread_fence(std::memory_order::release);
}
class NoCopy {
public:
NoCopy() { }
NoCopy(const NoCopy&) = delete;
NoCopy&operator=(const NoCopy&) = delete;
~NoCopy() {}
};
class NoMove {
public:
NoMove() { }
NoMove(NoMove&&) = delete;
NoMove&operator=(NoMove&&) = delete;
~NoMove() { }
};
}
+24
View File
@@ -112,3 +112,27 @@ std::string pipedal::GetHostName()
buffer[1023] = '\0';
return buffer;
}
std::vector<std::string> pipedal::split(const std::string &value, char delimiter)
{
size_t start = 0;
std::vector<std::string> result;
while (start < value.length())
{
size_t pos = value.find_first_of(delimiter, start);
if (pos == std::string::npos)
{
result.push_back(value.substr(start));
break;
}
result.push_back(value.substr(start, pos - start));
start = pos + 1;
if (start == value.length())
{
// ends with delimieter? Then there's an empty-length value at the end.
result.push_back("");
}
}
return result;
}