Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cppcoreguidelines-narrowing-conversions warning reported by clang-tidy #1159

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
245e299
Empty
MaximSmolskiy Dec 4, 2022
0084655
Fix src/stats/log_collector.cc
MaximSmolskiy Dec 4, 2022
01539d3
Fix clang-diagnostic-error
MaximSmolskiy Dec 4, 2022
9daa79f
Fix clang-diagnostic-error
MaximSmolskiy Dec 4, 2022
a2fe597
Fix src/common/io_util.cc
MaximSmolskiy Dec 4, 2022
60cc348
Fix src/common/string_util.cc
MaximSmolskiy Dec 4, 2022
0e3275e
Fix src/common/io_util.cc
MaximSmolskiy Dec 4, 2022
1f46891
Fix
MaximSmolskiy Dec 4, 2022
10461c6
Fix format
MaximSmolskiy Dec 4, 2022
187d5a1
Fix errors
MaximSmolskiy Dec 5, 2022
fec58b1
Fix
MaximSmolskiy Dec 5, 2022
1e4d846
Fix
MaximSmolskiy Dec 5, 2022
af2f01a
Fix
MaximSmolskiy Dec 5, 2022
6f63f41
Fix
MaximSmolskiy Dec 5, 2022
d7410bf
Fix src/storage/lock_manager.cc
MaximSmolskiy Dec 5, 2022
501be08
Fix src/main.cc
MaximSmolskiy Dec 5, 2022
a05a728
Fix src/config/config.cc
MaximSmolskiy Dec 5, 2022
54b7842
Fix src/server/redis_connection.cc
MaximSmolskiy Dec 5, 2022
82cb120
Fix src/server/redis_request.cc
MaximSmolskiy Dec 5, 2022
291e577
Fix src/server/worker.cc
MaximSmolskiy Dec 5, 2022
32aea24
Fix src/storage/storage.cc
MaximSmolskiy Dec 5, 2022
27ef7a2
Fix src/storage/storage.cc
MaximSmolskiy Dec 5, 2022
9818f10
Fix src/commands/redis_cmd.cc
MaximSmolskiy Dec 5, 2022
dbbc259
Fix src/server/server.cc
MaximSmolskiy Dec 5, 2022
d752b38
Fix src/storage/scripting.cc
MaximSmolskiy Dec 5, 2022
91f3286
Fix src/types/geohash.cc
MaximSmolskiy Dec 5, 2022
3127679
Fix src/types/redis_bitmap_string.cc
MaximSmolskiy Dec 5, 2022
3e7333c
Fix src/storage/scripting.cc
MaximSmolskiy Dec 5, 2022
e364ee4
Fix src/types/redis_geo.cc
MaximSmolskiy Dec 5, 2022
86f1a27
Fix errors
MaximSmolskiy Dec 5, 2022
931e179
Fix src/types/redis_bitmap_string.cc
MaximSmolskiy Dec 5, 2022
8fe94d5
Fix src/types/redis_bitmap.cc
MaximSmolskiy Dec 5, 2022
4b3293d
Fix src/types/redis_hash.cc
MaximSmolskiy Dec 5, 2022
2858cb1
Fix src/types/redis_list.cc
MaximSmolskiy Dec 5, 2022
38f7529
Fix src/types/redis_set.cc
MaximSmolskiy Dec 5, 2022
1c89644
Fix src/types/redis_sortedint.cc
MaximSmolskiy Dec 5, 2022
c034178
Fix src/types/redis_string.cc
MaximSmolskiy Dec 5, 2022
3370ba3
Fix src/types/redis_zset.cc
MaximSmolskiy Dec 5, 2022
dedf6c1
Add cppcoreguidelines-narrowing-conversions to WarningsAsErrors in .c…
MaximSmolskiy Dec 5, 2022
dcabf0d
Merge branch 'unstable' into fix-cppcoreguidelines-narrowing-conversi…
MaximSmolskiy Dec 6, 2022
a45b195
Merge branch 'unstable' into fix-cppcoreguidelines-narrowing-conversi…
MaximSmolskiy Dec 6, 2022
f01cf83
Merge branch 'unstable' into fix-cppcoreguidelines-narrowing-conversi…
MaximSmolskiy Dec 10, 2022
810ef4c
Change the camel case to the snake case
MaximSmolskiy Dec 10, 2022
8cdb044
Change port and tls_port types from int to uint32_t
MaximSmolskiy Dec 10, 2022
77758b6
Add templated IntegerField
MaximSmolskiy Dec 10, 2022
a5ec5f2
Specify types
MaximSmolskiy Dec 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 51 additions & 49 deletions src/config/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ Config::Config() {
FieldWrapper fields[] = {
{"daemonize", true, new YesNoField(&daemonize, false)},
{"bind", true, new StringField(&binds_, "")},
{"port", true, new Uint32Field(&port, kDefaultPort, 1, PORT_LIMIT)},
{"port", true, new IntegerField(&port, kDefaultPort, (uint32_t)1, PORT_LIMIT)},
#ifdef ENABLE_OPENSSL
{"tls-port", true, new Uint32Field(&tls_port, 0, 0, PORT_LIMIT)},
{"tls-port", true, new IntegerField(&tls_port, (uint32_t)0, (uint32_t)0, PORT_LIMIT)},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{"tls-port", true, new IntegerField(&tls_port, (uint32_t)0, (uint32_t)0, PORT_LIMIT)},
{"tls-port", true, new IntegerField<uint32_t>(&tls_port, 0, 0, PORT_LIMIT)},

I prefer we specify template types explicitly instead of deduced from arguments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In all places (and with int type) or only in few places with types uint32_t and uint64_t?

Copy link
Member

@PragmaTwice PragmaTwice Dec 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can define some aliases, e.g. using IntField = IntergerField<int>, using UInt32Field = IntergerField<uint32_t>.

Then you can use these alias in the config map, so most config kv will remain the original form (IntField).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

{"tls-cert-file", false, new StringField(&tls_cert_file, "")},
{"tls-key-file", false, new StringField(&tls_key_file, "")},
{"tls-key-file-pass", false, new StringField(&tls_key_file_pass, "")},
Expand All @@ -111,15 +111,15 @@ Config::Config() {
{"tls-ciphersuites", false, new StringField(&tls_ciphersuites, "")},
{"tls-prefer-server-ciphers", false, new YesNoField(&tls_prefer_server_ciphers, false)},
{"tls-session-caching", false, new YesNoField(&tls_session_caching, true)},
{"tls-session-cache-size", false, new IntField(&tls_session_cache_size, 1024 * 20, 0, INT_MAX)},
{"tls-session-cache-timeout", false, new IntField(&tls_session_cache_timeout, 300, 0, INT_MAX)},
{"tls-session-cache-size", false, new IntegerField(&tls_session_cache_size, 1024 * 20, 0, INT_MAX)},
{"tls-session-cache-timeout", false, new IntegerField(&tls_session_cache_timeout, 300, 0, INT_MAX)},
#endif
{"workers", true, new IntField(&workers, 8, 1, 256)},
{"timeout", false, new IntField(&timeout, 0, 0, INT_MAX)},
{"tcp-backlog", true, new IntField(&backlog, 511, 0, INT_MAX)},
{"maxclients", false, new IntField(&maxclients, 10240, 0, INT_MAX)},
{"max-backup-to-keep", false, new IntField(&max_backup_to_keep, 1, 0, 1)},
{"max-backup-keep-hours", false, new IntField(&max_backup_keep_hours, 0, 0, INT_MAX)},
{"workers", true, new IntegerField(&workers, 8, 1, 256)},
{"timeout", false, new IntegerField(&timeout, 0, 0, INT_MAX)},
{"tcp-backlog", true, new IntegerField(&backlog, 511, 0, INT_MAX)},
{"maxclients", false, new IntegerField(&maxclients, 10240, 0, INT_MAX)},
{"max-backup-to-keep", false, new IntegerField(&max_backup_to_keep, 1, 0, 1)},
{"max-backup-keep-hours", false, new IntegerField(&max_backup_keep_hours, 0, 0, INT_MAX)},
{"master-use-repl-port", false, new YesNoField(&master_use_repl_port, false)},
{"requirepass", false, new StringField(&requirepass, "")},
{"masterauth", false, new StringField(&masterauth, "")},
Expand All @@ -132,74 +132,76 @@ Config::Config() {
{"backup-dir", false, new StringField(&backup_dir, "")},
{"log-dir", true, new StringField(&log_dir, "")},
{"pidfile", true, new StringField(&pidfile, "")},
{"max-io-mb", false, new IntField(&max_io_mb, 500, 0, INT_MAX)},
{"max-bitmap-to-string-mb", false, new IntField(&max_bitmap_to_string_mb, 16, 0, INT_MAX)},
{"max-db-size", false, new IntField(&max_db_size, 0, 0, INT_MAX)},
{"max-replication-mb", false, new IntField(&max_replication_mb, 0, 0, INT_MAX)},
{"max-io-mb", false, new IntegerField(&max_io_mb, 500, 0, INT_MAX)},
{"max-bitmap-to-string-mb", false, new IntegerField(&max_bitmap_to_string_mb, 16, 0, INT_MAX)},
{"max-db-size", false, new IntegerField(&max_db_size, 0, 0, INT_MAX)},
{"max-replication-mb", false, new IntegerField(&max_replication_mb, 0, 0, INT_MAX)},
{"supervised", true, new EnumField(&supervised_mode, supervised_mode_enum, kSupervisedNone)},
{"slave-serve-stale-data", false, new YesNoField(&slave_serve_stale_data, true)},
{"slave-empty-db-before-fullsync", false, new YesNoField(&slave_empty_db_before_fullsync, false)},
{"slave-priority", false, new IntField(&slave_priority, 100, 0, INT_MAX)},
{"slave-priority", false, new IntegerField(&slave_priority, 100, 0, INT_MAX)},
{"slave-read-only", false, new YesNoField(&slave_readonly, true)},
{"use-rsid-psync", true, new YesNoField(&use_rsid_psync, false)},
{"profiling-sample-ratio", false, new IntField(&profiling_sample_ratio, 0, 0, 100)},
{"profiling-sample-record-max-len", false, new IntField(&profiling_sample_record_max_len, 256, 0, INT_MAX)},
{"profiling-sample-ratio", false, new IntegerField(&profiling_sample_ratio, 0, 0, 100)},
{"profiling-sample-record-max-len", false, new IntegerField(&profiling_sample_record_max_len, 256, 0, INT_MAX)},
{"profiling-sample-record-threshold-ms", false,
new IntField(&profiling_sample_record_threshold_ms, 100, 0, INT_MAX)},
{"slowlog-log-slower-than", false, new IntField(&slowlog_log_slower_than, 200000, -1, INT_MAX)},
new IntegerField(&profiling_sample_record_threshold_ms, 100, 0, INT_MAX)},
{"slowlog-log-slower-than", false, new IntegerField(&slowlog_log_slower_than, 200000, -1, INT_MAX)},
{"profiling-sample-commands", false, new StringField(&profiling_sample_commands_, "")},
{"slowlog-max-len", false, new IntField(&slowlog_max_len, 128, 0, INT_MAX)},
{"slowlog-max-len", false, new IntegerField(&slowlog_max_len, 128, 0, INT_MAX)},
{"purge-backup-on-fullsync", false, new YesNoField(&purge_backup_on_fullsync, false)},
{"rename-command", true, new MultiStringField(&rename_command_, std::vector<std::string>{})},
{"auto-resize-block-and-sst", false, new YesNoField(&auto_resize_block_and_sst, true)},
{"fullsync-recv-file-delay", false, new IntField(&fullsync_recv_file_delay, 0, 0, INT_MAX)},
{"fullsync-recv-file-delay", false, new IntegerField(&fullsync_recv_file_delay, 0, 0, INT_MAX)},
{"cluster-enabled", true, new YesNoField(&cluster_enabled, false)},
{"migrate-speed", false, new IntField(&migrate_speed, 4096, 0, INT_MAX)},
{"migrate-pipeline-size", false, new IntField(&pipeline_size, 16, 1, INT_MAX)},
{"migrate-sequence-gap", false, new IntField(&sequence_gap, 10000, 1, INT_MAX)},
{"migrate-speed", false, new IntegerField(&migrate_speed, 4096, 0, INT_MAX)},
{"migrate-pipeline-size", false, new IntegerField(&pipeline_size, 16, 1, INT_MAX)},
{"migrate-sequence-gap", false, new IntegerField(&sequence_gap, 10000, 1, INT_MAX)},
{"unixsocket", true, new StringField(&unixsocket, "")},
{"unixsocketperm", true, new OctalField(&unixsocketperm, 0777, 1, INT_MAX)},

/* rocksdb options */
{"rocksdb.compression", false, new EnumField(&RocksDB.compression, compression_type_enum, 0)},
{"rocksdb.block_size", true, new IntField(&RocksDB.block_size, 4096, 0, INT_MAX)},
{"rocksdb.max_open_files", false, new IntField(&RocksDB.max_open_files, 4096, -1, INT_MAX)},
{"rocksdb.write_buffer_size", false, new IntField(&RocksDB.write_buffer_size, 64, 0, 4096)},
{"rocksdb.max_write_buffer_number", false, new IntField(&RocksDB.max_write_buffer_number, 4, 0, 256)},
{"rocksdb.target_file_size_base", false, new IntField(&RocksDB.target_file_size_base, 128, 1, 1024)},
{"rocksdb.max_background_compactions", false, new IntField(&RocksDB.max_background_compactions, 2, 0, 32)},
{"rocksdb.max_background_flushes", true, new IntField(&RocksDB.max_background_flushes, 2, 0, 32)},
{"rocksdb.max_sub_compactions", false, new IntField(&RocksDB.max_sub_compactions, 1, 0, 16)},
{"rocksdb.delayed_write_rate", false, new Int64Field(&RocksDB.delayed_write_rate, 0, 0, INT64_MAX)},
{"rocksdb.wal_ttl_seconds", true, new IntField(&RocksDB.WAL_ttl_seconds, 3 * 3600, 0, INT_MAX)},
{"rocksdb.wal_size_limit_mb", true, new IntField(&RocksDB.WAL_size_limit_MB, 16384, 0, INT_MAX)},
{"rocksdb.max_total_wal_size", false, new IntField(&RocksDB.max_total_wal_size, 64 * 4 * 2, 0, INT_MAX)},
{"rocksdb.block_size", true, new IntegerField(&RocksDB.block_size, 4096, 0, INT_MAX)},
{"rocksdb.max_open_files", false, new IntegerField(&RocksDB.max_open_files, 4096, -1, INT_MAX)},
{"rocksdb.write_buffer_size", false, new IntegerField(&RocksDB.write_buffer_size, 64, 0, 4096)},
{"rocksdb.max_write_buffer_number", false, new IntegerField(&RocksDB.max_write_buffer_number, 4, 0, 256)},
{"rocksdb.target_file_size_base", false, new IntegerField(&RocksDB.target_file_size_base, 128, 1, 1024)},
{"rocksdb.max_background_compactions", false, new IntegerField(&RocksDB.max_background_compactions, 2, 0, 32)},
{"rocksdb.max_background_flushes", true, new IntegerField(&RocksDB.max_background_flushes, 2, 0, 32)},
{"rocksdb.max_sub_compactions", false, new IntegerField(&RocksDB.max_sub_compactions, 1, 0, 16)},
{"rocksdb.delayed_write_rate", false,
new IntegerField(&RocksDB.delayed_write_rate, (int64_t)0, (int64_t)0, INT64_MAX)},
{"rocksdb.wal_ttl_seconds", true, new IntegerField(&RocksDB.WAL_ttl_seconds, 3 * 3600, 0, INT_MAX)},
{"rocksdb.wal_size_limit_mb", true, new IntegerField(&RocksDB.WAL_size_limit_MB, 16384, 0, INT_MAX)},
{"rocksdb.max_total_wal_size", false, new IntegerField(&RocksDB.max_total_wal_size, 64 * 4 * 2, 0, INT_MAX)},
{"rocksdb.disable_auto_compactions", false, new YesNoField(&RocksDB.disable_auto_compactions, false)},
{"rocksdb.enable_pipelined_write", true, new YesNoField(&RocksDB.enable_pipelined_write, false)},
{"rocksdb.stats_dump_period_sec", false, new IntField(&RocksDB.stats_dump_period_sec, 0, 0, INT_MAX)},
{"rocksdb.stats_dump_period_sec", false, new IntegerField(&RocksDB.stats_dump_period_sec, 0, 0, INT_MAX)},
{"rocksdb.cache_index_and_filter_blocks", true, new YesNoField(&RocksDB.cache_index_and_filter_blocks, false)},
{"rocksdb.subkey_block_cache_size", true, new IntField(&RocksDB.subkey_block_cache_size, 2048, 0, INT_MAX)},
{"rocksdb.metadata_block_cache_size", true, new IntField(&RocksDB.metadata_block_cache_size, 2048, 0, INT_MAX)},
{"rocksdb.subkey_block_cache_size", true, new IntegerField(&RocksDB.subkey_block_cache_size, 2048, 0, INT_MAX)},
{"rocksdb.metadata_block_cache_size", true,
new IntegerField(&RocksDB.metadata_block_cache_size, 2048, 0, INT_MAX)},
{"rocksdb.share_metadata_and_subkey_block_cache", true,
new YesNoField(&RocksDB.share_metadata_and_subkey_block_cache, true)},
{"rocksdb.row_cache_size", true, new IntField(&RocksDB.row_cache_size, 0, 0, INT_MAX)},
{"rocksdb.row_cache_size", true, new IntegerField(&RocksDB.row_cache_size, 0, 0, INT_MAX)},
{"rocksdb.compaction_readahead_size", false,
new IntField(&RocksDB.compaction_readahead_size, 2 * MiB, 0, 64 * MiB)},
new IntegerField(&RocksDB.compaction_readahead_size, static_cast<int>(2 * MiB), 0, static_cast<int>(64 * MiB))},
{"rocksdb.level0_slowdown_writes_trigger", false,
new IntField(&RocksDB.level0_slowdown_writes_trigger, 20, 1, 1024)},
{"rocksdb.level0_stop_writes_trigger", false, new IntField(&RocksDB.level0_stop_writes_trigger, 40, 1, 1024)},
new IntegerField(&RocksDB.level0_slowdown_writes_trigger, 20, 1, 1024)},
{"rocksdb.level0_stop_writes_trigger", false, new IntegerField(&RocksDB.level0_stop_writes_trigger, 40, 1, 1024)},
{"rocksdb.level0_file_num_compaction_trigger", false,
new IntField(&RocksDB.level0_file_num_compaction_trigger, 4, 1, 1024)},
new IntegerField(&RocksDB.level0_file_num_compaction_trigger, 4, 1, 1024)},
{"rocksdb.enable_blob_files", false, new YesNoField(&RocksDB.enable_blob_files, false)},
{"rocksdb.min_blob_size", false, new IntField(&RocksDB.min_blob_size, 4096, 0, INT_MAX)},
{"rocksdb.blob_file_size", false, new IntField(&RocksDB.blob_file_size, 268435456, 0, INT_MAX)},
{"rocksdb.min_blob_size", false, new IntegerField(&RocksDB.min_blob_size, 4096, 0, INT_MAX)},
{"rocksdb.blob_file_size", false, new IntegerField(&RocksDB.blob_file_size, 268435456, 0, INT_MAX)},
{"rocksdb.enable_blob_garbage_collection", false, new YesNoField(&RocksDB.enable_blob_garbage_collection, true)},
{"rocksdb.blob_garbage_collection_age_cutoff", false,
new IntField(&RocksDB.blob_garbage_collection_age_cutoff, 25, 0, 100)},
new IntegerField(&RocksDB.blob_garbage_collection_age_cutoff, 25, 0, 100)},
{"rocksdb.max_bytes_for_level_base", false,
new IntField(&RocksDB.max_bytes_for_level_base, 268435456, 0, INT_MAX)},
new IntegerField(&RocksDB.max_bytes_for_level_base, 268435456, 0, INT_MAX)},
{"rocksdb.max_bytes_for_level_multiplier", false,
new IntField(&RocksDB.max_bytes_for_level_multiplier, 10, 1, 100)},
new IntegerField(&RocksDB.max_bytes_for_level_multiplier, 10, 1, 100)},
{"rocksdb.level_compaction_dynamic_level_bytes", false,
new YesNoField(&RocksDB.level_compaction_dynamic_level_bytes, false)},

Expand Down
2 changes: 1 addition & 1 deletion src/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace Engine {
class Storage;
}

constexpr const uint16_t PORT_LIMIT = 65535;
constexpr const uint32_t PORT_LIMIT = 65535;

enum SupervisedMode { kSupervisedNone = 0, kSupervisedAutoDetect, kSupervisedSystemd, kSupervisedUpStart };

Expand Down
73 changes: 14 additions & 59 deletions src/config/config_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@

#include <fmt/format.h>

#include <limits>
#include <string>
#include <utility>

#include "parse_util.h"
#include "status.h"
#include "string_util.h"

Expand Down Expand Up @@ -101,27 +103,30 @@ class MultiStringField : public ConfigField {
std::vector<std::string> *receiver_;
};

class IntField : public ConfigField {
template <typename IntegerType>
class IntegerField : public ConfigField {
public:
IntField(int *receiver, int n, int min, int max) : receiver_(receiver), min_(min), max_(max) { *receiver_ = n; }
~IntField() override = default;
IntegerField(IntegerType *receiver, IntegerType n, IntegerType min, IntegerType max)
: receiver_(receiver), min_(min), max_(max) {
*receiver_ = n;
}
~IntegerField() override = default;
std::string ToString() override { return std::to_string(*receiver_); }
Status ToNumber(int64_t *n) override {
*n = *receiver_;
return Status::OK();
}
Status Set(const std::string &v) override {
int64_t n;
auto s = Util::DecimalStringToNum(v, &n, min_, max_);
auto s = ParseInt(v, {min_, max_});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto s = ParseInt(v, {min_, max_});
auto s = ParseInt<IntegerType>(v, {min_, max_});

Copy link
Contributor Author

@MaximSmolskiy MaximSmolskiy Dec 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be deduced. Is it better to explicitly pass type?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to pass type explicitly here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if (!s.IsOK()) return s;
*receiver_ = static_cast<int>(n);
*receiver_ = s.GetValue();
return Status::OK();
}

private:
int *receiver_;
int min_ = INT_MIN;
int max_ = INT_MAX;
IntegerType *receiver_;
IntegerType min_ = std::numeric_limits<IntegerType>::min();
IntegerType max_ = std::numeric_limits<IntegerType>::max();
};

class OctalField : public ConfigField {
Expand All @@ -147,31 +152,6 @@ class OctalField : public ConfigField {
int max_ = INT_MAX;
};

class Int64Field : public ConfigField {
public:
Int64Field(int64_t *receiver, int64_t n, int64_t min, int64_t max) : receiver_(receiver), min_(min), max_(max) {
*receiver_ = n;
}
~Int64Field() override = default;
std::string ToString() override { return std::to_string(*receiver_); }
Status ToNumber(int64_t *n) override {
*n = *receiver_;
return Status::OK();
}
Status Set(const std::string &v) override {
int64_t n;
auto s = Util::DecimalStringToNum(v, &n, min_, max_);
if (!s.IsOK()) return s;
*receiver_ = n;
return Status::OK();
}

private:
int64_t *receiver_;
int64_t min_ = INT64_MIN;
int64_t max_ = INT64_MAX;
};

class YesNoField : public ConfigField {
public:
YesNoField(bool *receiver, bool b) : receiver_(receiver) { *receiver_ = b; }
Expand Down Expand Up @@ -218,28 +198,3 @@ class EnumField : public ConfigField {
int *receiver_;
configEnum *enums_ = nullptr;
};

class Uint32Field : public ConfigField {
public:
Uint32Field(uint32_t *receiver, uint32_t n, uint32_t min, uint32_t max) : receiver_(receiver), min_(min), max_(max) {
*receiver_ = n;
}
~Uint32Field() override = default;
std::string ToString() override { return std::to_string(*receiver_); }
Status ToNumber(int64_t *n) override {
*n = *receiver_;
return Status::OK();
}
Status Set(const std::string &v) override {
int64_t n;
auto s = Util::DecimalStringToNum(v, &n, min_, max_);
if (!s.IsOK()) return s;
*receiver_ = static_cast<uint32_t>(n);
return Status::OK();
}

private:
uint32_t *receiver_;
uint32_t min_ = INT_MIN;
uint32_t max_ = INT_MAX;
};