44#include < userver/formats/common/items.hpp>
55#include < userver/formats/parse/try_parse.hpp>
66#include < format>
7+ #include < unordered_map>
78#include < userver/utils/regex.hpp>
89
910USERVER_NAMESPACE_BEGIN
@@ -123,8 +124,8 @@ struct Pattern : public impl::EmptyCheck, public impl::Param<const utils::regex*
123124 }
124125};
125126
126- struct Additional : public impl ::EmptyCheck, public impl::Param<bool > {
127- constexpr inline Additional (const bool & value) :
127+ struct AdditionalProperties : public impl ::EmptyCheck, public impl::Param<bool > {
128+ constexpr inline AdditionalProperties (const bool & value) :
128129 impl::Param<bool>(value) {}
129130};
130131
@@ -147,13 +148,13 @@ struct FieldConfig<std::optional<T>> {
147148 };
148149 return std::nullopt ;
149150 }
150- constexpr auto Write (const std::optional<T>& value, std::string_view fieldName , const auto & names, auto & builder) const {
151+ constexpr auto Write (const std::optional<T>& value, std::string_view field_name , const auto & names, auto & builder) const {
151152 if (value) {
152- this ->Main .Write (*value, fieldName , names, builder);
153+ this ->Main .Write (*value, field_name , names, builder);
153154 return ;
154155 }
155156 if (this ->Default ) {
156- this ->Main .Write (this ->Default ->value (), fieldName , names, builder);
157+ this ->Main .Write (this ->Default ->value (), field_name , names, builder);
157158 return ;
158159 }
159160 }
@@ -202,22 +203,22 @@ struct FieldConfig<std::optional<T>> {
202203 }
203204};
204205
205- template <>
206- struct FieldConfig <int > {
207- std::optional<Max<int >> Maximum = std::nullopt ;
208- std::optional<Min<int >> Minimum = std::nullopt ;
206+ template <typename T >
207+ struct FieldConfig <T, std:: enable_if_t <meta:: kIsInteger <T> || std::is_floating_point_v<T>> > {
208+ std::optional<Max<T >> Maximum = std::nullopt ;
209+ std::optional<Min<T >> Minimum = std::nullopt ;
209210 template <typename MainClass, auto I, typename Value>
210211 constexpr int Read (Value&& value) const {
211212 constexpr auto name = boost::pfr::get_name<I, MainClass>();
212- return value[name].template As <int >();
213+ return value[name].template As <T >();
213214 }
214215 template <typename MainClass, auto I, typename Value>
215- constexpr std::optional<int > TryRead (Value&& value) const {
216+ constexpr std::optional<T > TryRead (Value&& value) const {
216217 constexpr auto name = boost::pfr::get_name<I, MainClass>();
217- return parse::TryParse (value[name], parse::To<int >{});
218+ return parse::TryParse (value[name], parse::To<T >{});
218219 }
219- constexpr auto Write (const int & value, std::string_view fieldName , const auto &, auto & builder) const {
220- builder[static_cast <std::string>(fieldName )] = value;
220+ constexpr auto Write (const int & value, std::string_view field_name , const auto &, auto & builder) const {
221+ builder[static_cast <std::string>(field_name )] = value;
221222 }
222223 inline constexpr std::optional<std::string> Check (const int &) const {
223224 return std::nullopt ;
@@ -236,8 +237,8 @@ struct FieldConfig<std::string> {
236237 constexpr auto name = boost::pfr::get_name<I, MainClass>();
237238 return parse::TryParse (value[name], parse::To<std::string>{});
238239 }
239- constexpr auto Write (std::string_view value, std::string_view fieldName , const auto &, auto & builder) const {
240- builder[static_cast <std::string>(fieldName )] = value;
240+ constexpr auto Write (std::string_view value, std::string_view field_name , const auto &, auto & builder) const {
241+ builder[static_cast <std::string>(field_name )] = value;
241242 }
242243 inline constexpr std::optional<std::string> Check (std::string_view) const {
243244 return std::nullopt ;
@@ -247,13 +248,13 @@ struct FieldConfig<std::string> {
247248
248249template <typename Value>
249250struct FieldConfig <std::unordered_map<std::string, Value>> {
250- std::optional<Additional> Additional = std::nullopt ;
251+ std::optional<AdditionalProperties> AdditionalProperties = std::nullopt ;
251252 FieldConfig<Value> Items = {};
252253 using Type = std::unordered_map<std::string, Value>;
253254 template <typename MainClass, auto I, typename Value2>
254255 inline constexpr Type Read (Value2&& value) const {
255256 Type response;
256- if (this ->Additional ) {
257+ if (this ->AdditionalProperties ) {
257258 constexpr auto fields = boost::pfr::names_as_array<MainClass>();
258259 for (const auto & [name, value] : userver::formats::common::Items (std::forward<Value2>(value))) {
259260 auto it = std::find (fields.begin (), fields.end (), name);
@@ -272,7 +273,7 @@ struct FieldConfig<std::unordered_map<std::string, Value>> {
272273 template <typename MainClass, auto I, typename Value2>
273274 inline constexpr std::optional<Type> TryRead (Value2&& value) const {
274275 Type response;
275- if (this ->Additional ) {
276+ if (this ->AdditionalProperties ) {
276277 constexpr auto fields = boost::pfr::names_as_array<MainClass>();
277278 for (const auto & [name, value] : userver::formats::common::Items (std::forward<Value2>(value))) {
278279 if (std::find (fields.begin (), fields.end (), name) == fields.end ()) {
@@ -285,8 +286,8 @@ struct FieldConfig<std::unordered_map<std::string, Value>> {
285286 }
286287 return response;
287288 }
288- constexpr auto fieldName = boost::pfr::get_name<I, MainClass>();
289- for (const auto & [name, value] : userver::formats::common::Items (value[fieldName ])) {
289+ constexpr auto field_name = boost::pfr::get_name<I, MainClass>();
290+ for (const auto & [name, value] : userver::formats::common::Items (value[field_name ])) {
290291 auto New = parse::TryParse (value, parse::To<Value>{});
291292 if (!New) {
292293 return std::nullopt ;
@@ -310,8 +311,8 @@ struct FieldConfig<std::unordered_map<std::string, Value>> {
310311 return error;
311312 }
312313 template <typename Builder>
313- constexpr auto Write (const Type& value, std::string_view fieldName , const auto &, Builder& builder) const {
314- if (this ->Additional ) {
314+ constexpr auto Write (const Type& value, std::string_view field_name , const auto &, Builder& builder) const {
315+ if (this ->AdditionalProperties ) {
315316 for (const auto & [name, value2] : value) {
316317 builder[name] = value2;
317318 }
@@ -321,7 +322,7 @@ struct FieldConfig<std::unordered_map<std::string, Value>> {
321322 for (const auto & [name, value2] : value) {
322323 newBuilder[name] = value2;
323324 }
324- builder[static_cast <std::string>(fieldName )] = newBuilder.ExtractValue ();
325+ builder[static_cast <std::string>(field_name )] = newBuilder.ExtractValue ();
325326 }
326327};
327328template <typename Element>
0 commit comments