|
|
@ -347,6 +347,8 @@ private: |
|
|
|
// both require a linear iterators as input e.g. most commonly - a static array |
|
|
|
// (either a plain [], or an std::array. template should treat both equally) |
|
|
|
|
|
|
|
struct Result; |
|
|
|
|
|
|
|
// single key variant, exact match of the provided string |
|
|
|
struct alignas(8) Setting { |
|
|
|
using ValueFunc = String(*)(); |
|
|
@ -373,20 +375,6 @@ struct alignas(8) Setting { |
|
|
|
return _key == key; |
|
|
|
} |
|
|
|
|
|
|
|
static const Setting* findFrom(const Setting* begin, const Setting* end, StringView key); |
|
|
|
|
|
|
|
template <typename T> |
|
|
|
static const Setting* findFrom(const T& settings, StringView key) { |
|
|
|
return findFrom(std::begin(settings), std::end(settings), key); |
|
|
|
} |
|
|
|
|
|
|
|
static String findValueFrom(const Setting* begin, const Setting* end, StringView key); |
|
|
|
|
|
|
|
template <typename T> |
|
|
|
static String findValueFrom(const T& settings, StringView key) { |
|
|
|
return findValueFrom(std::begin(settings), std::end(settings), key); |
|
|
|
} |
|
|
|
|
|
|
|
private: |
|
|
|
StringView _key; |
|
|
|
ValueFunc _func; |
|
|
@ -415,30 +403,104 @@ struct alignas(8) IndexedSetting { |
|
|
|
return _prefix; |
|
|
|
} |
|
|
|
|
|
|
|
static bool findSamePrefix(const IndexedSetting* begin, const IndexedSetting* end, StringView key); |
|
|
|
private: |
|
|
|
StringView _prefix; |
|
|
|
ValueFunc _func; |
|
|
|
}; |
|
|
|
|
|
|
|
template <typename T> |
|
|
|
static bool findSamePrefix(const T& settings, StringView key) { |
|
|
|
return findSamePrefix(std::begin(settings), std::end(settings), key); |
|
|
|
} |
|
|
|
// generic way to retrieve specific settings entry or report its absence |
|
|
|
struct Result { |
|
|
|
static constexpr size_t IndexMax = std::numeric_limits<size_t>::max(); |
|
|
|
|
|
|
|
static String findValueFrom(Iota iota, const IndexedSetting* begin, const IndexedSetting* end, StringView key); |
|
|
|
Result(const Result&) = default; |
|
|
|
Result& operator=(const Result&) = default; |
|
|
|
|
|
|
|
template <typename T> |
|
|
|
static String findValueFrom(Iota iota, const T& settings, StringView key) { |
|
|
|
return findValueFrom(iota, std::begin(settings), std::end(settings), key); |
|
|
|
Result(Result&&) = default; |
|
|
|
Result& operator=(Result&&) = default; |
|
|
|
|
|
|
|
Result() = default; |
|
|
|
|
|
|
|
explicit Result(const Setting* setting) : |
|
|
|
_ptr(setting) |
|
|
|
{} |
|
|
|
|
|
|
|
Result(const IndexedSetting* setting, size_t index) : |
|
|
|
_ptr(setting), |
|
|
|
_index(index) |
|
|
|
{} |
|
|
|
|
|
|
|
bool ok() const { |
|
|
|
return _ptr != nullptr; |
|
|
|
} |
|
|
|
|
|
|
|
template <typename T> |
|
|
|
static String findValueFrom(size_t size, const T& settings, StringView key) { |
|
|
|
return findValueFrom(Iota{size}, settings, key); |
|
|
|
explicit operator bool() const { |
|
|
|
return ok(); |
|
|
|
} |
|
|
|
|
|
|
|
String value() const; |
|
|
|
|
|
|
|
const void* pointer() const { |
|
|
|
return _ptr; |
|
|
|
} |
|
|
|
|
|
|
|
private: |
|
|
|
StringView _prefix; |
|
|
|
ValueFunc _func; |
|
|
|
const void* _ptr { nullptr }; |
|
|
|
size_t _index { IndexMax }; |
|
|
|
}; |
|
|
|
|
|
|
|
Result findFrom(const Setting* begin, const Setting* end, StringView key); |
|
|
|
|
|
|
|
template <typename T> |
|
|
|
inline Result findFrom(const T& settings, StringView key) { |
|
|
|
return findFrom(std::begin(settings), std::end(settings), key); |
|
|
|
} |
|
|
|
|
|
|
|
String findValueFrom(const Setting* begin, const Setting* end, StringView key); |
|
|
|
|
|
|
|
template <typename T> |
|
|
|
inline String findValueFrom(const T& settings, StringView key) { |
|
|
|
return findValueFrom(std::begin(settings), std::end(settings), key); |
|
|
|
} |
|
|
|
|
|
|
|
Result findFrom(Iota iota, const IndexedSetting* begin, const IndexedSetting* end, StringView key); |
|
|
|
|
|
|
|
template <typename T> |
|
|
|
inline Result findFrom(Iota iota, const T& settings, StringView key) { |
|
|
|
return findFrom(iota, std::begin(settings), std::end(settings), key); |
|
|
|
} |
|
|
|
|
|
|
|
template <typename T> |
|
|
|
inline Result findFrom(size_t size, const T& settings, StringView key) { |
|
|
|
return findFrom(Iota{size}, settings, key); |
|
|
|
} |
|
|
|
|
|
|
|
String findValueFrom(Iota iota, const IndexedSetting* begin, const IndexedSetting* end, StringView key); |
|
|
|
|
|
|
|
template <typename T> |
|
|
|
inline String findValueFrom(Iota iota, const T& settings, StringView key) { |
|
|
|
return findValueFrom(iota, std::begin(settings), std::end(settings), key); |
|
|
|
} |
|
|
|
|
|
|
|
template <typename T> |
|
|
|
inline String findValueFrom(size_t size, const T& settings, StringView key) { |
|
|
|
return findValueFrom(Iota{size}, settings, key); |
|
|
|
} |
|
|
|
|
|
|
|
const IndexedSetting* findSamePrefix(const IndexedSetting* begin, const IndexedSetting* end, StringView key); |
|
|
|
|
|
|
|
template <typename T> |
|
|
|
inline const IndexedSetting* findSamePrefix(const T& settings, StringView key) { |
|
|
|
return findSamePrefix(std::begin(settings), std::end(settings), key); |
|
|
|
} |
|
|
|
|
|
|
|
inline bool hasSamePrefix(const IndexedSetting* begin, const IndexedSetting* end, StringView key) { |
|
|
|
return nullptr != findSamePrefix(begin, end, key); |
|
|
|
} |
|
|
|
|
|
|
|
template <typename T> |
|
|
|
inline bool hasSamePrefix(const T& settings, StringView key) { |
|
|
|
return hasSamePrefix(std::begin(settings), std::end(settings), key); |
|
|
|
} |
|
|
|
|
|
|
|
} // namespace query |
|
|
|
} // namespace settings |
|
|
|