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

feat:variable-length arguments in configuration(closes #146) #164

Open
wants to merge 4 commits into
base: unstable
Choose a base branch
from
Open
Changes from 1 commit
Commits
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
4 changes: 2 additions & 2 deletions src/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ Status StringValue::SetValue(const std::string& value) {
Status StringValueArray::SetValue(const std::string& value) {
auto values = SplitString(value, delimiter_);
if (!values_.empty()) { // if the value_ is not empty, check the number of parameters
if (values.size() != values_.size()) {
return Status::InvalidArgument("The number of parameters does not match.");
if (values.size() < values_.size()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

需要支持两种情况

  1. 需要校验默认参数和实际参数长度是否一致
  2. 不需要校验默认参数长度

可以在SetValue(const std::string& value) 加一个默认参数, 是否需要校验默认参数

比如

SetValue(const std::string& value, bool check = false)

大多数情况下,应该都不需要检查默认参数长度,所以默认参数用 false 即可

有一种情况需要注意, 配置的默认参数填了2个, 但 配置文件中填了一个,需要把默认的两个都覆盖了,只用配置文件中的一个

return Status::InvalidArgument("The number of parameters is less than required.");
}
} else { // if the value_ is empty, resize the value_ to the size of the values
values_.resize(values.size());
Expand Down
Loading