IceShard 1
A personal game engine project, with development focused on 2D/2.5D games.
Loading...
Searching...
No Matches
config_impl.hxx
Go to the documentation of this file.
1
3
4#pragma once
6#include <ice/array.hxx>
7
9{
10
11 auto find(
12 ice::Config const& config,
13 ice::u32 index,
14 ice::config::detail::ConfigKey const*& out_key,
15 ice::config::detail::ConfigValue const*& out_value
16 ) noexcept -> ice::ErrorCode;
17
18 auto find(
19 ice::Config const& config,
20 ice::String strkey,
21 ice::config::detail::ConfigKey const*& out_key,
22 ice::config::detail::ConfigValue const*& out_value
23 ) noexcept -> ice::ErrorCode;
24
25 auto gettype(
26 ice::config::detail::ConfigKey const* key
27 ) noexcept -> ice::ConfigValueType;
28
29 bool istype(
30 ice::config::detail::ConfigKey const* key,
31 ice::ConfigValueType value_type
32 ) noexcept;
33
34
36 ice::Config const& config,
37 ice::config::detail::ConfigKey const& key
38 ) noexcept -> ice::String;
39
41 ice::config::detail::ConfigKey const*& array_key,
42 ice::config::detail::ConfigValue const*& array_value
43 ) noexcept -> ice::ErrorCode;
44
46 ice::config::detail::ConfigKey const*& array_key,
47 ice::config::detail::ConfigValue const*& array_value
48 ) noexcept -> ice::ErrorCode;
49
50
52 ice::config::detail::ConfigKey const* array_first_key
53 ) noexcept -> ice::u32;
54
56 ice::config::detail::ConfigKey const*& array_key,
57 ice::config::detail::ConfigValue const*& array_value
58 ) noexcept -> ice::ErrorCode;
59
61 ice::config::detail::ConfigKey const*& array_key,
62 ice::config::detail::ConfigValue const*& array_value
63 ) noexcept -> ice::ErrorCode;
64
65
66 template<typename T>
68 auto get(
69 ice::Config const& config,
70 ice::config::detail::ConfigKey const* key,
71 ice::config::detail::ConfigValue const* value,
72 T& out_value,
74 ) noexcept -> ice::ErrorCode;
75
76 template<typename T, typename Key>
78 auto get(
79 ice::Config const& config,
80 Key key,
81 T& out_value,
83 ) noexcept -> ice::ErrorCode
84 {
85 ice::config::detail::ConfigKey const* key_ptr = nullptr;
86 ice::config::detail::ConfigValue const* val_ptr = nullptr;
87 if (ErrorCode const err = ice::config::detail::find(config, key, key_ptr, val_ptr); err != S_Ok)
88 {
89 return err;
90 }
91
92 if (ErrorCode const err = ice::config::detail::get(config, key_ptr, val_ptr, out_value, flags); err != S_Ok)
93 {
94 return err;
95 }
96
97 return S_Ok;
98 }
99
100 template<typename T, typename Key>
103 ice::Config const& config,
104 Key key,
105 ice::Array<T>& out_values,
107 ) noexcept -> ice::ErrorCode
108 {
109 ice::config::detail::ConfigKey const* key_ptr = nullptr;
110 ice::config::detail::ConfigValue const* val_ptr = nullptr;
111 if (ErrorCode const err = ice::config::detail::find(config, key, key_ptr, val_ptr); err != S_Ok)
112 {
113 return err;
114 }
115
117 {
119 }
120
121 ice::config::detail::ConfigKey const* entry_key = key_ptr;
122 ice::config::detail::ConfigValue const* entry_value = val_ptr;
123 if (ErrorCode const err = array_first(entry_key, entry_value); err != S_Ok)
124 {
125 return err;
126 }
127
128 ice::u32 const table_size = array_size(entry_key);
129 if (table_size == 0)
130 {
131 return S_Ok;
132 }
133
134 ice::ErrorCode result = S_Ok;
135 out_values.reserve(table_size);
136 do
137 {
138 T temp_value;
139 if (result = ice::config::detail::get(config, entry_key, entry_value, temp_value, flags); result == S_Ok)
140 {
141 out_values.push_back(temp_value);
142 }
143 else if (result != E_ConfigValueTypeMissmatch)
144 {
145 break;
146 }
147 }
148 while(array_next(entry_key, entry_value));
149
150 return result;
151 }
152
153} // namespace ice
Definition config_types.hxx:34
Definition config_details.hxx:23
Definition config_details.hxx:26
Definition config_details.hxx:31
auto array_next(ice::config::detail::ConfigKey const *&array_key, ice::config::detail::ConfigValue const *&array_value) noexcept -> ice::ErrorCode
auto get(ice::Config const &config, ice::config::detail::ConfigKey const *key, ice::config::detail::ConfigValue const *value, T &out_value, ice::ConfigValueFlags flags) noexcept -> ice::ErrorCode
auto entry_key(ice::Config const &config, ice::config::detail::ConfigKey const &key) noexcept -> ice::String
auto array_size(ice::config::detail::ConfigKey const *array_first_key) noexcept -> ice::u32
auto entry_first(ice::config::detail::ConfigKey const *&array_key, ice::config::detail::ConfigValue const *&array_value) noexcept -> ice::ErrorCode
auto entry_next(ice::config::detail::ConfigKey const *&array_key, ice::config::detail::ConfigValue const *&array_value) noexcept -> ice::ErrorCode
auto gettype(ice::config::detail::ConfigKey const *key) noexcept -> ice::ConfigValueType
bool istype(ice::config::detail::ConfigKey const *key, ice::ConfigValueType value_type) noexcept
auto array_first(ice::config::detail::ConfigKey const *&array_key, ice::config::detail::ConfigValue const *&array_value) noexcept -> ice::ErrorCode
auto get_array(ice::Config const &config, Key key, ice::Array< T > &out_values, ice::ConfigValueFlags flags) noexcept -> ice::ErrorCode
Definition config_impl.hxx:102
auto find(ice::Config const &config, ice::u32 index, ice::config::detail::ConfigKey const *&out_key, ice::config::detail::ConfigValue const *&out_value) noexcept -> ice::ErrorCode
Definition config.hxx:9
ice::BasicString< char > String
Definition string.hxx:82
std::uint32_t u32
Definition types.hxx:26
ConfigValueFlags
Definition config_types.hxx:11
static constexpr ice::ErrorCodeSuccess S_Ok
Definition error_codes.hxx:10
ConfigValueType
Definition config_types.hxx:18
@ Table
Definition config_types.hxx:29
static constexpr ice::ErrorCode E_ConfigValueTypeMissmatch
Definition config_details.hxx:17
static constexpr ice::ErrorCode E_ConfigValueNotAnTable
Definition config_details.hxx:15
A simple container storing items in continuous memory.
Definition array.hxx:24
void push_back(ItemType &&item) noexcept
Definition array.hxx:322
Definition error.hxx:19
constexpr void reserve(this Self &self, ice::ncount min_capacity) noexcept
Definition resizable_container.hxx:25