Adds further ext deps as-is binaries copies from customers env.
Qt6 Migration CI / migrate (push) Canceled after 0s
Qt6 Migration CI / migrate (push) Canceled after 0s
This commit is contained in:
3700 files changed
+2132394
No files matched your search
+77
@@ -0,0 +1,77 @@
|
||||
#pragma once
|
||||
|
||||
#include "ddkit/base/IConfig.hpp"
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
namespace ddkit {
|
||||
namespace base {
|
||||
|
||||
class Config : public IConfig {
|
||||
|
||||
public:
|
||||
// as both ctor-params are strings, make constructor-calls disambiguous:
|
||||
struct Text {
|
||||
explicit Text(const std::string& text)
|
||||
: m_text(text) {}
|
||||
std::string m_text;
|
||||
};
|
||||
struct Filename {
|
||||
explicit Filename(const std::string& filename)
|
||||
: m_filename(filename) {}
|
||||
std::string m_filename;
|
||||
};
|
||||
|
||||
class FileNotFound : public std::runtime_error {
|
||||
public:
|
||||
FileNotFound(const std::string& filename) : std::runtime_error("could not open file \"" + filename + "\""){}
|
||||
};
|
||||
|
||||
Config();
|
||||
Config(const nlohmann::json&);
|
||||
Config(const Text& text); // call: Config config((Config::Text("{ abc = 17 }")));
|
||||
Config(const Filename& filename);
|
||||
Config(const Config&);
|
||||
void operator=(Config const&);
|
||||
|
||||
// IConfig
|
||||
bool hasKey(const std::string& key) const override;
|
||||
std::string getStringValue(const std::string& key) const override;
|
||||
int getIntValue(const std::string& key) const override;
|
||||
int64_t getInt64Value(const std::string& key) const override;
|
||||
bool getBoolValue(const std::string& key) const override;
|
||||
|
||||
// todo array into IConfig?
|
||||
int getArraySize(const std::string& key) const;
|
||||
|
||||
// no template-getter any more (error-prone in conjunction with type-casts)
|
||||
// no default-getter any more (error-prone in conjunction with typos)
|
||||
// no optional-getter any more (too much tmsif-API-logic, might be useful in other place)
|
||||
|
||||
bool isInt64Value(const std::string& key) const; // int or int64
|
||||
bool isBoolValue(const std::string& key) const;
|
||||
bool isStringValue(const std::string& key) const;
|
||||
bool isArrayValue(const std::string& key) const;
|
||||
bool isListValue(const std::string& key) const; // has subKeys
|
||||
|
||||
std::vector<std::string> getSubKeys(const std::string& key) const;
|
||||
|
||||
Config getSubConfig(const std::string& key) const;
|
||||
|
||||
operator std::string() const;
|
||||
|
||||
private:
|
||||
|
||||
static nlohmann::json::json_pointer keyToJsonPointer(const std::string& key);
|
||||
nlohmann::json getValue(const std::string& key) const;
|
||||
bool hasKey(const nlohmann::json&, const std::string& key) const;
|
||||
bool hasKey(const nlohmann::json& jsonObj, const nlohmann::json::json_pointer& jsonPtr) const;
|
||||
|
||||
nlohmann::json m_json;
|
||||
};
|
||||
|
||||
} // namespace base
|
||||
} // namespace ddkit
|
||||
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include "ddkit/base/Config.hpp"
|
||||
|
||||
namespace ddkit {
|
||||
namespace access {
|
||||
class ConfigLoaderDds;
|
||||
}
|
||||
|
||||
namespace base {
|
||||
|
||||
/// @brief class "ConfigLoader"
|
||||
/// - it holds the config-File of the application and sets up the logger
|
||||
/// Hold by ConfigLoaderDds
|
||||
class ConfigLoader final {
|
||||
|
||||
public:
|
||||
|
||||
ConfigLoader(const std::string& configFile);
|
||||
~ConfigLoader();
|
||||
|
||||
Config& config() { return m_config; }
|
||||
|
||||
private:
|
||||
|
||||
std::string m_programName;
|
||||
Config m_config;
|
||||
|
||||
// no copying
|
||||
ConfigLoader(ConfigLoader const&) = delete;
|
||||
ConfigLoader(ConfigLoader&&) = delete;
|
||||
void operator=(ConfigLoader const&) = delete;
|
||||
void operator=(ConfigLoader&&) = delete;
|
||||
};
|
||||
|
||||
} // namespace base
|
||||
} // namespace ddkit
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
#pragma once
|
||||
|
||||
#include "ddkit/base/Config.hpp"
|
||||
#include "ddkit/base/IConfigWrite.hpp"
|
||||
|
||||
#include <set>
|
||||
#include <map>
|
||||
|
||||
namespace ddkit {
|
||||
namespace base {
|
||||
|
||||
/// @brief ConfigRw (ReadWrite) is constructed with a normal Config (read, from a file) and enables overwrite of keys as well.
|
||||
/// additionally it may be checked, which keys are allowed
|
||||
class ConfigRw : public IConfig,
|
||||
public IConfigWrite {
|
||||
|
||||
public:
|
||||
ConfigRw();
|
||||
ConfigRw(Config& config);
|
||||
ConfigRw(const ConfigRw&);
|
||||
void operator=(const ConfigRw&);
|
||||
|
||||
// IConfig
|
||||
bool hasKey(const std::string& key) const override;
|
||||
std::string getStringValue(const std::string& key) const override;
|
||||
int getIntValue(const std::string& key) const override;
|
||||
int64_t getInt64Value(const std::string& key) const override;
|
||||
bool getBoolValue(const std::string& key) const override;
|
||||
|
||||
// IConfigWrite
|
||||
void setStringValue(const std::string& key, const std::string& value) override;
|
||||
void setIntValue(const std::string& key, int value) override;
|
||||
void setInt64Value(const std::string& key, int64_t value) override;
|
||||
void setBoolValue(const std::string& key, bool value) override;
|
||||
|
||||
// activate checks. i.e. foo.bar -> section foo and key bar
|
||||
void registerKnownConfigKey(
|
||||
const std::string& section,
|
||||
const std::string& key);
|
||||
|
||||
void checkConfig() const; // check in file (only for corresponding top-level)
|
||||
|
||||
private:
|
||||
// the 'real' BaseConfig (ConfigFile from ConfigLoader)
|
||||
Config m_config;
|
||||
|
||||
// the overwritten key-values
|
||||
std::vector<std::string> m_keys;
|
||||
std::map<std::string, std::string> m_key2stringValue;
|
||||
std::map<std::string, int> m_key2intValue;
|
||||
std::map<std::string, int64_t> m_key2int64Value;
|
||||
std::map<std::string, bool> m_key2boolValue;
|
||||
|
||||
// keys allowed
|
||||
std::map<std::string, std::vector<std::string>> m_knownKeysMap;
|
||||
void checkKey(const std::string& key) const;
|
||||
void checkConfig(const std::string& prefix) const; // check in file
|
||||
};
|
||||
|
||||
} // namespace base
|
||||
} // namespace ddkit
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace ddkit {
|
||||
namespace base {
|
||||
|
||||
class IConfig {
|
||||
public:
|
||||
virtual ~IConfig() = default;
|
||||
|
||||
virtual bool hasKey(const std::string& key) const = 0;
|
||||
|
||||
// getters which throw if the key does not exist
|
||||
virtual std::string getStringValue(const std::string& key) const = 0;
|
||||
virtual int getIntValue(const std::string& key) const = 0;
|
||||
virtual int64_t getInt64Value(const std::string& key) const = 0;
|
||||
virtual bool getBoolValue(const std::string& key) const = 0;
|
||||
|
||||
// getters which return a default if the key does not exist
|
||||
std::string getStringValue(const std::string& key, const std::string& defaultValue) const {
|
||||
if (hasKey(key)) return getStringValue(key);
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
int getIntValue(const std::string& key, int defaultValue) const {
|
||||
if (hasKey(key)) return getIntValue(key);
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
int64_t getInt64Value(const std::string& key, int64_t defaultValue) const {
|
||||
if (hasKey(key)) return getInt64Value(key);
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
bool getBoolValue(const std::string& key, bool defaultValue) const {
|
||||
if (hasKey(key)) return getBoolValue(key);
|
||||
return defaultValue;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace base
|
||||
} // namespace ddkit
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace ddkit {
|
||||
namespace base {
|
||||
|
||||
class IConfigWrite {
|
||||
public:
|
||||
virtual void setStringValue(const std::string& key, const std::string& value) = 0;
|
||||
virtual void setIntValue(const std::string& key, int value) = 0;
|
||||
virtual void setInt64Value(const std::string& key, int64_t value) = 0;
|
||||
virtual void setBoolValue(const std::string& key, bool value) = 0;
|
||||
virtual ~IConfigWrite() = default;
|
||||
};
|
||||
|
||||
} // namespace base
|
||||
} // namespace ddkit
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
#pragma once
|
||||
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <exception>
|
||||
|
||||
namespace ddkit {
|
||||
namespace base {
|
||||
|
||||
/// @brief exception class for serialization errors
|
||||
/// emitted for any errors encouted during parsing
|
||||
/// for details refere to what() message
|
||||
class SerializationError : public std::exception {
|
||||
public:
|
||||
SerializationError(const std::string& message) : m_message(message) {
|
||||
}
|
||||
|
||||
virtual const char* what() const noexcept override {
|
||||
return m_message.c_str();
|
||||
}
|
||||
|
||||
private:
|
||||
const std::string m_message;
|
||||
};
|
||||
|
||||
/// @brief simple serialization like stringstream
|
||||
/// - serialized format is a string, readable
|
||||
/// - may be deserialized with same operator-calling-pattern of types on another instance
|
||||
/// mixed calls to serializing and deserializing on same object -> undefined behaviour
|
||||
class Serialization {
|
||||
std::ostringstream m_os;
|
||||
std::istringstream m_is;
|
||||
// bool m_isSerializing; // todo nth check?
|
||||
// bool m_isDeserializing;
|
||||
public:
|
||||
// serializing
|
||||
Serialization();
|
||||
std::string str();
|
||||
|
||||
// deserializing
|
||||
explicit Serialization(const std::string& text);
|
||||
bool isEnd();
|
||||
|
||||
|
||||
// bool
|
||||
Serialization& operator<<(bool rhs);
|
||||
Serialization& operator>>(bool& rhs);
|
||||
|
||||
// int char
|
||||
Serialization& operator<<(uint8_t rhs);
|
||||
Serialization& operator>>(uint8_t& rhs);
|
||||
|
||||
Serialization& operator<<(uint16_t rhs);
|
||||
Serialization& operator>>(uint16_t& rhs);
|
||||
|
||||
Serialization& operator<<(uint32_t rhs);
|
||||
Serialization& operator>>(uint32_t& rhs);
|
||||
|
||||
Serialization& operator<<(uint64_t rhs);
|
||||
Serialization& operator>>(uint64_t& rhs);
|
||||
|
||||
Serialization& operator<<(int8_t rhs);
|
||||
Serialization& operator>>(int8_t& rhs);
|
||||
|
||||
Serialization& operator<<(int16_t rhs);
|
||||
Serialization& operator>>(int16_t& rhs);
|
||||
|
||||
Serialization& operator<<(int32_t rhs);
|
||||
Serialization& operator>>(int32_t& rhs);
|
||||
|
||||
Serialization& operator<<(int64_t rhs);
|
||||
Serialization& operator>>(int64_t& rhs);
|
||||
|
||||
Serialization& operator<<(char rhs);
|
||||
Serialization& operator>>(char& rhs);
|
||||
|
||||
// float double
|
||||
Serialization& operator<<(double rhs);
|
||||
Serialization& operator>>(double& rhs);
|
||||
|
||||
Serialization& operator<<(float rhs);
|
||||
Serialization& operator>>(float& rhs);
|
||||
|
||||
// string
|
||||
Serialization& operator<<(const std::string& rhs);
|
||||
Serialization& operator>>(std::string& rhs);
|
||||
|
||||
// vector
|
||||
template <typename T>
|
||||
Serialization& operator<<(std::vector<T> const& rhs) {
|
||||
*this << rhs.size();
|
||||
for (T const& t : rhs) {
|
||||
*this << t;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
template <typename T>
|
||||
Serialization& operator>>(std::vector<T>& rhs) {
|
||||
rhs.clear();
|
||||
|
||||
int size = getSize();
|
||||
for (int i = 0; i < size; ++i) {
|
||||
T t;
|
||||
*this >> t;
|
||||
rhs.push_back(t);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string readBytes(int size);
|
||||
void expectAndSkipComma();
|
||||
int getSize();
|
||||
};
|
||||
|
||||
} // namespace base
|
||||
} // namespace ddkit
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
#include <condition_variable>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
namespace ddkit {
|
||||
namespace base {
|
||||
|
||||
/// @brief wrapper for std::thread, including
|
||||
/// - clean synchronized start/stop/stopCommanded-mechanism
|
||||
/// - tracing with threadname, exception-logging on outermost level
|
||||
class Thread {
|
||||
|
||||
public:
|
||||
/// @param name 6-char-thread-name
|
||||
Thread(const std::string& name);
|
||||
virtual ~Thread();
|
||||
|
||||
void start();
|
||||
// void stop(); // call stopAndJoin instead
|
||||
void stopAndJoin();
|
||||
|
||||
bool isActive() const;
|
||||
void waitForStopCommanded();
|
||||
bool stopCommanded() const;
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
std::unique_ptr<std::thread> m_thread;
|
||||
bool m_threadExecutionActive;
|
||||
|
||||
std::mutex m_mutexStart;
|
||||
std::condition_variable m_threadStarted;
|
||||
bool m_hasStarted;
|
||||
|
||||
std::mutex m_mutexStop;
|
||||
std::condition_variable m_threadStopped;
|
||||
bool m_stopCommanded;
|
||||
|
||||
virtual void run();
|
||||
virtual void onStop();
|
||||
|
||||
void startUp();
|
||||
|
||||
void waitForStarted();
|
||||
virtual void waitForReadyIf();
|
||||
|
||||
// no copying
|
||||
Thread(Thread const&) = delete;
|
||||
Thread(Thread&&) = delete;
|
||||
void operator=(Thread const&) = delete;
|
||||
};
|
||||
|
||||
} // namespace base
|
||||
} // namespace ddkit
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "ddkit/base/Thread.hpp"
|
||||
#include <functional>
|
||||
|
||||
namespace ddkit {
|
||||
namespace base {
|
||||
|
||||
class ThreadInline final : public Thread {
|
||||
public:
|
||||
ThreadInline(const std::string& name, const std::function<void()>& function);
|
||||
~ThreadInline() override;
|
||||
|
||||
private:
|
||||
std::function<void()> m_function;
|
||||
|
||||
void run() override;
|
||||
|
||||
ThreadInline(ThreadInline const&) = delete;
|
||||
void operator=(ThreadInline const&) = delete;
|
||||
};
|
||||
|
||||
} // namespace base
|
||||
} // namespace ddkit
|
||||
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include "ddkit/base/Thread.hpp"
|
||||
|
||||
namespace ddkit {
|
||||
namespace base {
|
||||
|
||||
/// @brief ThreadSync may be used instead of Thread, if 'start()' shall be 'synchronous', that is
|
||||
/// - the os-thread, which is calling 'start()' on this obj, is blocked until
|
||||
/// - the new os-thread is created and the intern-thread-function was started
|
||||
/// - the overridden 'run()'-method (Derivee from ThreadSync) is started
|
||||
/// - the implementation of that 'run'-method decided to call 'ready()'
|
||||
/// - (as first command, or after some initialization-steps, which went for some reason not in ctor, but run)
|
||||
class ThreadSync : public Thread {
|
||||
|
||||
public:
|
||||
ThreadSync(const std::string& name);
|
||||
virtual ~ThreadSync() override;
|
||||
|
||||
protected:
|
||||
void ready();
|
||||
|
||||
private:
|
||||
std::recursive_mutex m_mutex;
|
||||
std::condition_variable_any m_condition;
|
||||
|
||||
bool m_isReady; // did the thread call "ready()" for signaling "fully" starting up?
|
||||
|
||||
void waitForReadyIf() override; // called by Thread
|
||||
|
||||
ThreadSync(ThreadSync const&) = delete;
|
||||
void operator=(ThreadSync const&) = delete;
|
||||
};
|
||||
|
||||
|
||||
} // namespace base
|
||||
} // namespace ddkit
|
||||
Reference in new issue
Block a user