📄 value.cxx
字号:
result = int_value; } CYG_REPORT_RETVAL((int) result); return result;}boolCdlSimpleValue::has_double_value() const{ CYG_REPORT_FUNCNAMETYPE("CdlSimpleValue::has_double_value", "result %d"); CYG_REPORT_FUNCARG1XV(this); if (!(valid_flags & (double_valid | double_invalid))) { if (valid_flags & int_valid) { Cdl::integer_to_double(int_value, double_value); valid_flags |= double_valid; } else if (valid_flags & string_valid) { if (Cdl::string_to_double(value, double_value)) { valid_flags |= double_valid; } else { valid_flags |= double_invalid; } } else { CYG_FAIL("Attempt to use uninitialized SimpleValue"); } } bool result = (valid_flags & double_valid); CYG_REPORT_RETVAL(result); return result;}doubleCdlSimpleValue::get_double_value() const{ CYG_REPORT_FUNCNAME("CdlSimpleValue::get_double_value"); CYG_REPORT_FUNCARG1XV(this); double result = 0.0; if ((valid_flags & double_valid) || has_double_value()) { result = double_value; } CYG_REPORT_RETURN(); return result;}boolCdlSimpleValue::get_bool_value() const{ CYG_REPORT_FUNCNAMETYPE("CdlSimpleValue::get_bool_value", "result %d"); CYG_REPORT_FUNCARG1XV(this); bool result = false; if (valid_flags & int_valid) { if (0 != int_value) { result = true; } } else if (valid_flags & double_valid) { // Leave it to the compiler to decide what is valid result = double_value; } else if (valid_flags & string_valid) { // string_to_bool copes with "1", "true", and a few other cases. // If the current value does not match any of these then // true corresponds to a non-empty string. if (!Cdl::string_to_bool(value, result)) { if ("" == value) { result = false; } else { result = true; } } } else { // No value defined, default to false. result = false; } CYG_REPORT_RETVAL(result); return result;}//}}}//{{{ Updating the value // ----------------------------------------------------------------------------// Normally the assignment operators will be used for this instead.voidCdlSimpleValue::set_value(std::string val, CdlValueFormat new_format){ CYG_REPORT_FUNCNAME("CdlSimpleValue::set_value (string)"); CYG_REPORT_FUNCARG1XV(this); value = val; int_value = 0; double_value = 0.0; valid_flags = string_valid; format = new_format;}voidCdlSimpleValue::set_integer_value(cdl_int val, CdlValueFormat new_format){ CYG_REPORT_FUNCNAME("CdlSimpleValue::set_integer_value"); CYG_REPORT_FUNCARG2XV(this, (int) val); value = ""; int_value = val; double_value = 0.0; valid_flags = int_valid; format = new_format; CYG_REPORT_RETURN();}voidCdlSimpleValue::set_double_value(double val, CdlValueFormat new_format){ CYG_REPORT_FUNCNAME("CdlSimpleValue::set_double_value"); CYG_REPORT_FUNCARG1XV(this); value = ""; int_value = 0; double_value = val; valid_flags = double_valid; format = new_format; CYG_REPORT_RETURN();}//}}}//{{{ Value format support // ----------------------------------------------------------------------------CdlValueFormatCdlSimpleValue::get_value_format() const{ CYG_REPORT_FUNCNAMETYPE("CdlSimpleValue::get_value_format", "result %d"); CYG_REPORT_FUNCARG1XV(this); CdlValueFormat result = format; CYG_REPORT_RETVAL(result); return result;}voidCdlSimpleValue::set_value_format(CdlValueFormat new_format){ CYG_REPORT_FUNCNAME("CdlSimpleValue::set_value_format"); CYG_REPORT_FUNCARG2XV(this, new_format); format = new_format; CYG_REPORT_RETURN();}voidCdlSimpleValue::set_value_format(CdlSimpleValue& other_val){ CYG_REPORT_FUNCNAME("CdlSimpleValue::set_value_format (simple val)"); CYG_REPORT_FUNCARG2XV(this, &other_val); format = other_val.format; CYG_REPORT_RETURN();}// This gets used for binary operators, e.g. A + B// If A has a non-default format then that gets used.// Otherwise B's format gets used, which may or may not be default.//// e.g. 0x1000 + 4 -> 0x1004// 10 + 0x100 -> 0x10A// 10 + 32 -> 42voidCdlSimpleValue::set_value_format(CdlSimpleValue& val1, CdlSimpleValue& val2){ CYG_REPORT_FUNCNAME("CdlSimpleValue::set_value_format"); CYG_REPORT_FUNCARG3XV(this, &val1, &val2); format = (CdlValueFormat_Default != val1.format) ? val1.format : val2.format; CYG_REPORT_RETURN();}//}}}//{{{ Comparison operators // ----------------------------------------------------------------------------boolCdlSimpleValue::operator==(const CdlSimpleValue& other) const{ CYG_REPORT_FUNCNAMETYPE("CdlSimpleValue:: operator==", "result %d"); CYG_REPORT_FUNCARG2XV(this, &other); bool result = false; if (has_integer_value()) { if (other.has_integer_value()) { cdl_int val1 = get_integer_value(); cdl_int val2 = other.get_integer_value(); result = (val1 == val2); } } else if (has_double_value()) { if (other.has_double_value()) { double val1 = get_double_value(); double val2 = other.get_double_value(); result = (val1 == val2); } } else { std::string val1 = get_value(); std::string val2 = other.get_value(); result = (val1 == val2); } CYG_REPORT_RETVAL(result); return result;}boolCdlSimpleValue::operator!=(const CdlSimpleValue& other) const{ CYG_REPORT_FUNCNAMETYPE("CdlSimpleValue:: operator!=", "result %d"); CYG_REPORT_FUNCARG2XV(this, &other); bool result = true; if (has_integer_value()) { if (other.has_integer_value()) { cdl_int val1 = get_integer_value(); cdl_int val2 = other.get_integer_value(); result = (val1 != val2); } } else if (has_double_value()) { if (other.has_double_value()) { double val1 = get_double_value(); double val2 = other.get_double_value(); result = (val1 != val2); } } else { std::string val1 = get_value(); std::string val2 = other.get_value(); result = (val1 != val2); } CYG_REPORT_RETVAL(result); return result;}//}}}//}}}//{{{ CdlValue class // ----------------------------------------------------------------------------// This should really be a class static constant, but VC++ does not implement// that part of the language. A constant here avoids the need for lots of// occurrences of 4 throughout the value-related routines.static const int CdlValue_number_of_sources = 4;//{{{ Constructors // ----------------------------------------------------------------------------// The default flavor depends on the type of entity being created. For// example CDL options are boolean by default, but packages are booldata.// The intelligence to do the right thing lives in set_flavor().CdlValue::CdlValue(CdlValueFlavor flavor_arg){ CYG_REPORT_FUNCNAME("CdlValue:: constructor"); CYG_REPORT_FUNCARG1XV(this); current_source = CdlValueSource_Default; source_valid[CdlValueSource_Default] = true; source_valid[CdlValueSource_Inferred] = false; source_valid[CdlValueSource_Wizard] = false; source_valid[CdlValueSource_User] = false; enabled[CdlValueSource_Default] = false; enabled[CdlValueSource_Inferred] = false; enabled[CdlValueSource_Wizard] = false; enabled[CdlValueSource_User] = false; // The SimpleValues will initialize themselves. cdlvalue_cookie = CdlValue_Magic; CYGDBG_MEMLEAK_CONSTRUCTOR(); set_flavor(flavor_arg); CYG_POSTCONDITION_THISC(); CYG_REPORT_RETURN();}// ----------------------------------------------------------------------------// Copy constructor. This is not really required, a default// member-wise copy would be fine and more efficient, but it would// lose tracing and assertion.CdlValue::CdlValue(const CdlValue& original){ CYG_REPORT_FUNCNAME("CdlValue:: copy constructor"); CYG_REPORT_FUNCARG2XV(this, &original); CYG_INVARIANT_CLASSOC(CdlValue, original); flavor = original.flavor; current_source = original.current_source; for (int i = 0; i < CdlValue_number_of_sources; i++) { source_valid[i] = original.source_valid[i]; enabled[i] = original.enabled[i]; values[i] = original.values[i]; } cdlvalue_cookie = CdlValue_Magic; CYGDBG_MEMLEAK_CONSTRUCTOR(); CYG_POSTCONDITION_THISC(); CYG_REPORT_RETURN();}// ----------------------------------------------------------------------------// Assignment operator. Again this is not required, the default would be// fine and more efficient, but tracing and assertions are good things.CdlValue& CdlValue::operator=(const CdlValue& original){ CYG_REPORT_FUNCNAME("CdlValue:: assignment operator"); CYG_REPORT_FUNCARG2XV(this, &original); CYG_INVARIANT_CLASSOC(CdlValue, original); if (this != &original) { flavor = original.flavor; current_source = original.current_source; for (int i = 0; i < CdlValue_number_of_sources; i++) { source_valid[i] = original.source_valid[i]; enabled[i] = original.enabled[i]; values[i] = original.values[i]; } } cdlvalue_cookie = CdlValue_Magic; CYG_POSTCONDITION_THISC(); CYG_REPORT_RETURN(); return *this;}//}}}//{{{ Destructor // ----------------------------------------------------------------------------CdlValue::~CdlValue(){ CYG_REPORT_FUNCNAME("CdlValue:: destructor"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); cdlvalue_cookie = CdlValue_Invalid; flavor = CdlValueFlavor_Invalid; current_source = CdlValueSource_Invalid; for (int i = 0; i < CdlValue_number_of_sources; i++) { source_valid[i] = false; enabled[i] = false; // The CdlSimpleValue array will take care of itself. } CYGDBG_MEMLEAK_DESTRUCTOR(); CYG_REPORT_RETURN();}//}}}//{{{ check_this() // ----------------------------------------------------------------------------boolCdlValue::check_this(cyg_assert_class_zeal zeal) const{ if (CdlValue_Magic != cdlvalue_cookie) { return false; } CYGDBG_MEMLEAK_CHECKTHIS(); if (!source_valid[CdlValueSource_Default]) { return false; } if ((CdlValueFlavor_None == flavor) || (CdlValueFlavor_Data == flavor)) { for (int i = 0; i < CdlValue_number_of_sources; i++) { if (!enabled[i]) { return false; } } } for (int i = 0; i < CdlValue_number_of_sources; i++) { if (source_valid[i]) { if (!values[i].check_this(zeal)) { return false; } } } return true;}//}}}//{{{ Flavor manipulation // ----------------------------------------------------------------------------// Get hold of the current flavor.CdlValueFlavorCdlValue::get_flavor(void) const{ CYG_REPORT_FUNCNAMETYPE("CdlValue::get_flavor", "result %d"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); CdlValueFlavor result = flavor; CYG_REPORT_RETVAL(result); return result;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -