默认值支持条件值
This commit is contained in:
parent
631fa03792
commit
9fd6746a15
|
@ -863,6 +863,10 @@ void device_option::clear(void)
|
||||||
for (auto& v : range_value_)
|
for (auto& v : range_value_)
|
||||||
delete v.second;
|
delete v.second;
|
||||||
range_value_.clear();
|
range_value_.clear();
|
||||||
|
|
||||||
|
for (auto& v : init_value_)
|
||||||
|
delete v.second;
|
||||||
|
init_value_.clear();
|
||||||
}
|
}
|
||||||
gb_json* device_option::group_opt(const char* title)
|
gb_json* device_option::group_opt(const char* title)
|
||||||
{
|
{
|
||||||
|
@ -972,12 +976,27 @@ void device_option::init_depends(gb_json* opt)
|
||||||
|
|
||||||
opt->get_value("type", dpnd);
|
opt->get_value("type", dpnd);
|
||||||
if (val->set_value(range, dpnd.c_str(), this))
|
if (val->set_value(range, dpnd.c_str(), this))
|
||||||
range_value_[opt->key().c_str()] = val;
|
range_value_[opt->key()] = val;
|
||||||
else
|
else
|
||||||
delete val;
|
delete val;
|
||||||
|
|
||||||
range->release();
|
range->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// default:
|
||||||
|
range = nullptr;
|
||||||
|
opt->get_value("default", range);
|
||||||
|
opt->get_value("type", dpnd);
|
||||||
|
if (range)
|
||||||
|
{
|
||||||
|
range_value* rv = new range_value();
|
||||||
|
if (rv->set_value(range, dpnd.c_str(), this))
|
||||||
|
init_value_[opt->key()] = rv;
|
||||||
|
else
|
||||||
|
delete rv;
|
||||||
|
|
||||||
|
range->release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
gb_json* device_option::copy_opt(gb_json* from)
|
gb_json* device_option::copy_opt(gb_json* from)
|
||||||
{
|
{
|
||||||
|
@ -1005,7 +1024,31 @@ gb_json* device_option::copy_opt(gb_json* from)
|
||||||
if (slaver_.count(to->key()))
|
if (slaver_.count(to->key()))
|
||||||
to->set_value("enabled", slaver_[to->key()]->value(&device_option::calc_simple_logic_expression, this));
|
to->set_value("enabled", slaver_[to->key()]->value(&device_option::calc_simple_logic_expression, this));
|
||||||
|
|
||||||
// 3: range value ...
|
// 3: default value ...
|
||||||
|
if (init_value_.count(to->key()))
|
||||||
|
{
|
||||||
|
std::string val(init_value_[to->key()]->first_value(&device_option::calc_simple_logic_expression, this));
|
||||||
|
for (int i = 0; i < init_value_[to->key()]->count(); ++i)
|
||||||
|
{
|
||||||
|
if (!val.empty())
|
||||||
|
{
|
||||||
|
std::string type("");
|
||||||
|
to->get_value("type", type);
|
||||||
|
if (type == JSON_SANE_TYPE_BOOL)
|
||||||
|
to->set_value("default", *(bool*)val.c_str());
|
||||||
|
else if(type == JSON_SANE_TYPE_INT)
|
||||||
|
to->set_value("default", *(int*)val.c_str());
|
||||||
|
else if(type == JSON_SANE_TYPE_FIXED)
|
||||||
|
to->set_value("default", *(double*)val.c_str());
|
||||||
|
else if(type == JSON_SANE_TYPE_STRING)
|
||||||
|
to->set_value("default", (const wchar_t*)val.c_str());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
val = init_value_[to->key()]->next_value(&device_option::calc_simple_logic_expression, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4: range value ...
|
||||||
if (range_value_.count(to->key()))
|
if (range_value_.count(to->key()))
|
||||||
{
|
{
|
||||||
gb_json* src = nullptr, * dst = nullptr;
|
gb_json* src = nullptr, * dst = nullptr;
|
||||||
|
|
|
@ -127,6 +127,7 @@ class device_option
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
std::map<std::string, range_value*> range_value_;
|
std::map<std::string, range_value*> range_value_;
|
||||||
|
std::map<std::string, range_value*> init_value_;
|
||||||
|
|
||||||
static bool is_equal_b(gb_json* opt, void* val, void* v1, void* v2);
|
static bool is_equal_b(gb_json* opt, void* val, void* v1, void* v2);
|
||||||
static bool is_equal_i(gb_json* opt, void* val, void* v1, void* v2);
|
static bool is_equal_i(gb_json* opt, void* val, void* v1, void* v2);
|
||||||
|
|
Loading…
Reference in New Issue