1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-08-05 08:26:28 +00:00

Starts moving towards a Deflectable-based system of runtime options.

This commit is contained in:
Thomas Harte
2020-03-15 23:48:53 -04:00
parent 2031a33edf
commit 8e3bf0dbca
33 changed files with 524 additions and 548 deletions

View File

@@ -8,6 +8,8 @@
#include "Struct.h"
// MARK: - Setters
template <> bool Reflection::set(Struct &target, const std::string &name, int value) {
const auto target_type = target.type_of(name);
if(!target_type) return false;
@@ -52,6 +54,26 @@ template <> bool Reflection::set(Struct &target, const std::string &name, const
return set<const std::string &>(target, name, string);
}
// MARK: - Fuzzy setter
bool Reflection::fuzzy_set(Struct &target, const std::string &name, const std::string &value) {
return false;
}
// MARK: - Getters
template <typename Type> bool Reflection::get(Struct &target, const std::string &name, Type &value) {
return false;
}
template <> bool Reflection::get(Struct &target, const std::string &name, bool &value) {
const auto target_type = target.type_of(name);
if(!target_type) return false;
if(*target_type == typeid(bool)) {
value = *reinterpret_cast<const bool *>(target.get(name));
return true;
}
return false;
}

View File

@@ -71,6 +71,17 @@ template <> bool set(Struct &target, const std::string &name, const char *value)
*/
bool fuzzy_set(Struct &target, const std::string &name, const std::string &value);
/*!
Attempts to get the property @c name to @c value ; will perform limited type conversions.
@returns @c true if the property was successfully read; @c false otherwise.
*/
template <typename Type> bool get(Struct &target, const std::string &name, Type &value);
template <> bool get(Struct &target, const std::string &name, bool &value);
// TODO: move this elsewhere. It's just a sketch anyway.
struct Serialisable {
/// Serialises this object, appending it to @c target.