-//{{{ Banner
+//{{{ Banner
//============================================================================
//
//
//============================================================================
//####COPYRIGHTBEGIN####
-//
+//
// ----------------------------------------------------------------------------
// Copyright (C) 2002 Bart Veer
// Copyright (C) 1999, 2000, 2001 Red Hat, Inc.
//
// This file is part of the eCos host tools.
//
-// This program is free software; you can redistribute it and/or modify it
-// under the terms of the GNU General Public License as published by the Free
-// Software Foundation; either version 2 of the License, or (at your option)
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 of the License, or (at your option)
// any later version.
-//
-// This program is distributed in the hope that it will be useful, but WITHOUT
-// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
-//
+//
// You should have received a copy of the GNU General Public License along with
-// this program; if not, write to the Free Software Foundation, Inc.,
+// this program; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// ----------------------------------------------------------------------------
-//
+//
//####COPYRIGHTEND####
//============================================================================
//#####DESCRIPTIONBEGIN####
//============================================================================
//}}}
-//{{{ #include's
+//{{{ #include's
// ----------------------------------------------------------------------------
#include "cdlconfig.h"
//}}}
-//{{{ Statics
+//{{{ Statics
// ----------------------------------------------------------------------------
CYGDBG_DEFINE_MEMLEAK_COUNTER(CdlValue);
CYGDBG_DEFINE_MEMLEAK_COUNTER(CdlValuableBody);
//}}}
-//{{{ CdlSimpleValue class
+//{{{ CdlSimpleValue class
-//{{{ Constructors
+//{{{ Constructors
// ----------------------------------------------------------------------------
double_value = 0.0;
valid_flags = string_valid;
format = CdlValueFormat_Default;
-
+
CYG_REPORT_RETURN();
}
double_value = 0.0;
valid_flags = int_valid;
format = CdlValueFormat_Default;
-
+
CYG_REPORT_RETURN();
}
double_value = 0.0;
valid_flags = string_valid | int_valid;
format = CdlValueFormat_Default;
-
+
CYG_REPORT_RETURN();
}
double_value = original.double_value;
valid_flags = original.valid_flags;
format = original.format;
-
+
CYG_REPORT_RETURN();
}
//}}}
-//{{{ Destructor
+//{{{ Destructor
// ----------------------------------------------------------------------------
}
//}}}
-//{{{ Assignment operators
+//{{{ Assignment operators
// ----------------------------------------------------------------------------
CYG_REPORT_FUNCARG2XV(this, &original);
if (this != &original) {
- value = original.value;
- int_value = original.int_value;
- double_value = original.double_value;
- valid_flags = original.valid_flags;
- format = original.format;
+ value = original.value;
+ int_value = original.int_value;
+ double_value = original.double_value;
+ valid_flags = original.valid_flags;
+ format = original.format;
}
-
+
CYG_REPORT_RETURN();
return *this;
}
double_value = 0.0;
valid_flags = int_valid;
format = CdlValueFormat_Default;
-
+
CYG_REPORT_RETURN();
return *this;
}
}
//}}}
-//{{{ CdlValuable -> CdlSimpleValue
+//{{{ CdlValuable -> CdlSimpleValue
// ----------------------------------------------------------------------------
// This routine bridges the gap between the full data held in the CdlValuable
// always zero for the purposes of expression evaluation.
// FIXME: this check should be on a per-transaction basis.
if (((0 != context.transaction) && !context.transaction->is_active(valuable)) ||
- ((0 == context.transaction) && !valuable->is_active())) {
-
- result.value = "0";
- result.int_value = 0;
- result.double_value = 0.0;
- result.valid_flags = string_valid | int_valid;
- result.format = CdlValueFormat_Default;
- CYG_REPORT_RETURN();
- return;
+ ((0 == context.transaction) && !valuable->is_active())) {
+
+ result.value = "0";
+ result.int_value = 0;
+ result.double_value = 0.0;
+ result.valid_flags = string_valid | int_valid;
+ result.format = CdlValueFormat_Default;
+ CYG_REPORT_RETURN();
+ return;
}
// Get hold of the underlying CdlValue object
const CdlValue& val = (0 != context.transaction) ?
- context.transaction->get_whole_value(valuable) : valuable->get_whole_value();
-
+ context.transaction->get_whole_value(valuable) : valuable->get_whole_value();
+
// Otherwise the value depends on the flavor.
switch(val.get_flavor()) {
case CdlValueFlavor_None :
{
- // This could be treated as an error, but since valuables with flavor
- // none are permanently enabled a constant "1" is a better result.
- result.value = "1";
- result.int_value = 1;
- result.double_value = 0.0;
- result.valid_flags = string_valid | int_valid;
- result.format = CdlValueFormat_Default;
- break;
+ // This could be treated as an error, but since valuables with flavor
+ // none are permanently enabled a constant "1" is a better result.
+ result.value = "1";
+ result.int_value = 1;
+ result.double_value = 0.0;
+ result.valid_flags = string_valid | int_valid;
+ result.format = CdlValueFormat_Default;
+ break;
}
case CdlValueFlavor_Bool :
{
- bool enabled = val.is_enabled();
- result.value = (enabled) ? "1" : "0";
- result.int_value = (enabled) ? 1 : 0;
- result.double_value = 0.0;
- result.valid_flags = string_valid | int_valid;
- result.format = CdlValueFormat_Default;
- break;
+ bool enabled = val.is_enabled();
+ result.value = (enabled) ? "1" : "0";
+ result.int_value = (enabled) ? 1 : 0;
+ result.double_value = 0.0;
+ result.valid_flags = string_valid | int_valid;
+ result.format = CdlValueFormat_Default;
+ break;
}
case CdlValueFlavor_BoolData :
{
- if (!val.is_enabled()) {
-
- result.value = "0";
- result.int_value = 0;
- result.double_value = 0.0;
- result.valid_flags = string_valid | int_valid;
- result.format = CdlValueFormat_Default;
-
- } else {
-
- // Just use a copy constructor, let the compiler optimise things.
- result = val.get_simple_value();
- }
- break;
+ if (!val.is_enabled()) {
+
+ result.value = "0";
+ result.int_value = 0;
+ result.double_value = 0.0;
+ result.valid_flags = string_valid | int_valid;
+ result.format = CdlValueFormat_Default;
+
+ } else {
+
+ // Just use a copy constructor, let the compiler optimise things.
+ result = val.get_simple_value();
+ }
+ break;
}
case CdlValueFlavor_Data :
{
- // Just like BoolData, but with no need to check the enabled flag.
- result = val.get_simple_value();
- break;
+ // Just like BoolData, but with no need to check the enabled flag.
+ result = val.get_simple_value();
+ break;
}
default:
{
- CYG_FAIL("Valuable object with an unknown flavor encountered.");
+ CYG_FAIL("Valuable object with an unknown flavor encountered.");
}
}
}
//}}}
-//{{{ Getting the value
+//{{{ Getting the value
// ----------------------------------------------------------------------------
// Some of these calls involve conversion operators.
CYG_REPORT_FUNCARG1XV(this);
if (!(valid_flags & string_valid)) {
- if (valid_flags & int_valid) {
- Cdl::integer_to_string(int_value, value, format);
- } else if (valid_flags & double_valid) {
- Cdl::double_to_string(double_value, value, format);
- } else {
- CYG_FAIL("Attempt to use uninitialized SimpleValue");
- }
- valid_flags |= string_valid;
+ if (valid_flags & int_valid) {
+ Cdl::integer_to_string(int_value, value, format);
+ } else if (valid_flags & double_valid) {
+ Cdl::double_to_string(double_value, value, format);
+ } else {
+ CYG_FAIL("Attempt to use uninitialized SimpleValue");
+ }
+ valid_flags |= string_valid;
}
CYG_REPORT_RETURN();
CYG_REPORT_FUNCARG1XV(this);
if (!(valid_flags & (int_valid | int_invalid))) {
- if (valid_flags & double_valid) {
- if (Cdl::double_to_integer(double_value, int_value)) {
- valid_flags |= int_valid;
- } else {
- valid_flags |= int_invalid;
- }
- } else if (valid_flags & string_valid) {
- if (Cdl::string_to_integer(value, int_value)) {
- valid_flags |= int_valid;
- } else {
- valid_flags |= int_invalid;
- }
- } else {
- CYG_FAIL("Attempt to use uninitialized SimpleValue");
- }
+ if (valid_flags & double_valid) {
+ if (Cdl::double_to_integer(double_value, int_value)) {
+ valid_flags |= int_valid;
+ } else {
+ valid_flags |= int_invalid;
+ }
+ } else if (valid_flags & string_valid) {
+ if (Cdl::string_to_integer(value, int_value)) {
+ valid_flags |= int_valid;
+ } else {
+ valid_flags |= int_invalid;
+ }
+ } else {
+ CYG_FAIL("Attempt to use uninitialized SimpleValue");
+ }
}
-
+
bool result = (valid_flags & int_valid);
CYG_REPORT_RETVAL(result);
return result;
cdl_int result = 0;
if ((valid_flags & int_valid) || has_integer_value()) {
- result = int_value;
+ result = int_value;
}
CYG_REPORT_RETVAL((int) result);
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");
- }
+ 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);
double result = 0.0;
if ((valid_flags & double_valid) || has_double_value()) {
- result = double_value;
+ result = double_value;
}
CYG_REPORT_RETURN();
bool result = false;
if (valid_flags & int_valid) {
- if (0 != int_value) {
- result = true;
- }
+ 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;
+ // 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;
- }
- }
+ // 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;
+ // No value defined, default to false.
+ result = false;
}
CYG_REPORT_RETVAL(result);
}
//}}}
-//{{{ Updating the value
+//{{{ Updating the value
// ----------------------------------------------------------------------------
// Normally the assignment operators will be used for this instead.
}
//}}}
-//{{{ Value format support
+//{{{ Value format support
// ----------------------------------------------------------------------------
CYG_REPORT_FUNCARG2XV(this, new_format);
format = new_format;
-
+
CYG_REPORT_RETURN();
}
}
//}}}
-//{{{ Comparison operators
+//{{{ Comparison operators
// ----------------------------------------------------------------------------
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);
- }
+ 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);
- }
+ 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);
+ std::string val1 = get_value();
+ std::string val2 = other.get_value();
+ result = (val1 == val2);
}
-
+
CYG_REPORT_RETVAL(result);
return result;
}
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);
- }
+ 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);
- }
+ 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);
+ std::string val1 = get_value();
+ std::string val2 = other.get_value();
+ result = (val1 != val2);
}
//}}}
//}}}
-//{{{ CdlValue class
+//{{{ CdlValue class
// ----------------------------------------------------------------------------
// This should really be a class static constant, but VC++ does not implement
static const int CdlValue_number_of_sources = 4;
-//{{{ Constructors
+//{{{ Constructors
// ----------------------------------------------------------------------------
// The default flavor depends on the type of entity being created. For
enabled[CdlValueSource_User] = false;
// The SimpleValues will initialize themselves.
-
+
cdlvalue_cookie = CdlValue_Magic;
CYGDBG_MEMLEAK_CONSTRUCTOR();
// This cannot happen until after the object is valid.
set_flavor(flavor_arg);
-
+
CYG_POSTCONDITION_THISC();
CYG_REPORT_RETURN();
}
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];
+ 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();
}
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];
- }
+ 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;
}
//}}}
-//{{{ Destructor
+//{{{ Destructor
// ----------------------------------------------------------------------------
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.
+ source_valid[i] = false;
+ enabled[i] = false;
+ // The CdlSimpleValue array will take care of itself.
}
CYGDBG_MEMLEAK_DESTRUCTOR();
}
//}}}
-//{{{ check_this()
+//{{{ check_this()
// ----------------------------------------------------------------------------
bool
CdlValue::check_this(cyg_assert_class_zeal zeal) const
{
if (CdlValue_Magic != cdlvalue_cookie) {
- return false;
+ return false;
}
CYGDBG_MEMLEAK_CHECKTHIS();
if (!source_valid[CdlValueSource_Default]) {
- return false;
+ 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 (!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;
- }
- }
+ if (source_valid[i]) {
+ if (!values[i].check_this(zeal)) {
+ return false;
+ }
+ }
}
-
+
return true;
}
//}}}
-//{{{ Flavor manipulation
+//{{{ Flavor manipulation
// ----------------------------------------------------------------------------
// Get hold of the current flavor.
{
CYG_REPORT_FUNCNAME("CdlValue:: set_flavor");
CYG_REPORT_FUNCARG2XV(this, flavor_arg);
-
+
// No precondition here, set_flavor() is called from inside the constructor
CYG_PRECONDITIONC((CdlValueFlavor_None == flavor_arg) || \
- (CdlValueFlavor_Bool == flavor_arg) || \
- (CdlValueFlavor_BoolData == flavor_arg) || \
- (CdlValueFlavor_Data == flavor_arg));
+ (CdlValueFlavor_Bool == flavor_arg) || \
+ (CdlValueFlavor_BoolData == flavor_arg) || \
+ (CdlValueFlavor_Data == flavor_arg));
flavor = flavor_arg;
switch(flavor) {
case CdlValueFlavor_None :
- {
- // All value sources are enabled, but "default" remains
- // the only valid one. All data parts are set to "1",
- // although that should not really matter.
- enabled[CdlValueSource_Default] = true;
- enabled[CdlValueSource_Inferred] = true;
- enabled[CdlValueSource_Wizard] = true;
- enabled[CdlValueSource_User] = true;
-
- CdlSimpleValue simple_val((cdl_int) 1);
- values[CdlValueSource_Default] = simple_val;
- values[CdlValueSource_Inferred] = simple_val;
- values[CdlValueSource_Wizard] = simple_val;
- values[CdlValueSource_User] = simple_val;
- break;
- }
-
+ {
+ // All value sources are enabled, but "default" remains
+ // the only valid one. All data parts are set to "1",
+ // although that should not really matter.
+ enabled[CdlValueSource_Default] = true;
+ enabled[CdlValueSource_Inferred] = true;
+ enabled[CdlValueSource_Wizard] = true;
+ enabled[CdlValueSource_User] = true;
+
+ CdlSimpleValue simple_val((cdl_int) 1);
+ values[CdlValueSource_Default] = simple_val;
+ values[CdlValueSource_Inferred] = simple_val;
+ values[CdlValueSource_Wizard] = simple_val;
+ values[CdlValueSource_User] = simple_val;
+ break;
+ }
+
case CdlValueFlavor_Bool :
- {
- // All value sources start out as disabled, but with a
- // constant data part of 1. Users can only control the
- // boolean part. This is consistent with header file
- // generation: no #define is generated for disabled
- // options, but if the option is enabled then the data
- // part will be used for the value.
- enabled[CdlValueSource_Default] = false;
- enabled[CdlValueSource_Inferred] = false;
- enabled[CdlValueSource_Wizard] = false;
- enabled[CdlValueSource_User] = false;
-
- // BLV - keep the data part at 0 for now. There is too
- // much confusion in the code between value as a string
- // representation, and value as the data part of the
- // bool/data pair. This needs to be fixed, but it requires
- // significant API changes.
-#if 0
- CdlSimpleValue simple_val(cdl_int(1));
+ {
+ // All value sources start out as disabled, but with a
+ // constant data part of 1. Users can only control the
+ // boolean part. This is consistent with header file
+ // generation: no #define is generated for disabled
+ // options, but if the option is enabled then the data
+ // part will be used for the value.
+ enabled[CdlValueSource_Default] = false;
+ enabled[CdlValueSource_Inferred] = false;
+ enabled[CdlValueSource_Wizard] = false;
+ enabled[CdlValueSource_User] = false;
+
+ // BLV - keep the data part at 0 for now. There is too
+ // much confusion in the code between value as a string
+ // representation, and value as the data part of the
+ // bool/data pair. This needs to be fixed, but it requires
+ // significant API changes.
+#if 0
+ CdlSimpleValue simple_val(cdl_int(1));
#else
- CdlSimpleValue simple_val(cdl_int(0));
-#endif
- values[CdlValueSource_Default] = simple_val;
- values[CdlValueSource_Inferred] = simple_val;
- values[CdlValueSource_Wizard] = simple_val;
- values[CdlValueSource_User] = simple_val;
- break;
- }
-
+ CdlSimpleValue simple_val(cdl_int(0));
+#endif
+ values[CdlValueSource_Default] = simple_val;
+ values[CdlValueSource_Inferred] = simple_val;
+ values[CdlValueSource_Wizard] = simple_val;
+ values[CdlValueSource_User] = simple_val;
+ break;
+ }
+
case CdlValueFlavor_BoolData :
- {
- // All value sources start out as disabled, just like
- // booleans. Nothing is known about the data part.
- enabled[CdlValueSource_Default] = false;
- enabled[CdlValueSource_Inferred] = false;
- enabled[CdlValueSource_Wizard] = false;
- enabled[CdlValueSource_User] = false;
- break;
- }
-
+ {
+ // All value sources start out as disabled, just like
+ // booleans. Nothing is known about the data part.
+ enabled[CdlValueSource_Default] = false;
+ enabled[CdlValueSource_Inferred] = false;
+ enabled[CdlValueSource_Wizard] = false;
+ enabled[CdlValueSource_User] = false;
+ break;
+ }
+
case CdlValueFlavor_Data :
- {
- // All value sources start out as enabled, and cannot be
- // changed. Nothing is known about the data part.
- enabled[CdlValueSource_Default] = true;
- enabled[CdlValueSource_Inferred] = true;
- enabled[CdlValueSource_Wizard] = true;
- enabled[CdlValueSource_User] = true;
- break;
- }
+ {
+ // All value sources start out as enabled, and cannot be
+ // changed. Nothing is known about the data part.
+ enabled[CdlValueSource_Default] = true;
+ enabled[CdlValueSource_Inferred] = true;
+ enabled[CdlValueSource_Wizard] = true;
+ enabled[CdlValueSource_User] = true;
+ break;
+ }
default :
- break;
+ break;
}
-
+
CYG_REPORT_RETURN();
}
//}}}
-//{{{ Source manipulation
+//{{{ Source manipulation
// ----------------------------------------------------------------------------
CYG_PRECONDITIONC((0 <= source) && (source < CdlValue_number_of_sources));
if (CdlValueSource_Default != source) {
- source_valid[source] = false;
- if (current_source == source) {
- if (source_valid[CdlValueSource_User]) {
- current_source = CdlValueSource_User;
- } else if (source_valid[CdlValueSource_Wizard]) {
- current_source = CdlValueSource_Wizard;
- } else if (source_valid[CdlValueSource_Inferred]) {
- current_source = CdlValueSource_Inferred;
- } else {
- current_source = CdlValueSource_Default;
- }
- }
+ source_valid[source] = false;
+ if (current_source == source) {
+ if (source_valid[CdlValueSource_User]) {
+ current_source = CdlValueSource_User;
+ } else if (source_valid[CdlValueSource_Wizard]) {
+ current_source = CdlValueSource_Wizard;
+ } else if (source_valid[CdlValueSource_Inferred]) {
+ current_source = CdlValueSource_Inferred;
+ } else {
+ current_source = CdlValueSource_Default;
+ }
+ }
}
-
+
CYG_POSTCONDITIONC(source_valid[current_source]);
}
//}}}
-//{{{ Retrieving the data
+//{{{ Retrieving the data
// ----------------------------------------------------------------------------
// Check the enabled flag for the appropriate source. The specified source
CYG_PRECONDITION_THISC();
if (CdlValueSource_Current == source) {
- source = current_source;
+ source = current_source;
}
CYG_PRECONDITIONC((0 <= source) && (source < CdlValue_number_of_sources));
CYG_PRECONDITIONC(source_valid[source]);
CYG_PRECONDITION_THISC();
if (CdlValueSource_Current == source) {
- source = current_source;
+ source = current_source;
}
CYG_PRECONDITIONC((0 <= source) && (source < CdlValue_number_of_sources));
CYG_PRECONDITIONC(source_valid[source]);
CYG_INVARIANT_THISC(CdlValue);
if (CdlValueSource_Current == source) {
- source = current_source;
+ source = current_source;
}
CYG_PRECONDITIONC((0 <= source) && (source < CdlValue_number_of_sources));
CYG_PRECONDITIONC(source_valid[source]);
CYG_REPORT_FUNCNAMETYPE("CdlValue::has_value", "result %d");
CYG_REPORT_FUNCARG2XV(this, source);
CYG_INVARIANT_THISC(CdlValue);
-
+
if (CdlValueSource_Current == source) {
- source = current_source;
+ source = current_source;
}
CYG_PRECONDITIONC((0 <= source) && (source < CdlValue_number_of_sources));
CYG_PRECONDITIONC(source_valid[source]);
CYG_PRECONDITION_THISC();
if (CdlValueSource_Current == source) {
- source = current_source;
+ source = current_source;
}
CYG_PRECONDITIONC((0 <= source) && (source < CdlValue_number_of_sources));
CYG_PRECONDITIONC(source_valid[source]);
CYG_PRECONDITION_THISC();
if (CdlValueSource_Current == source) {
- source = current_source;
+ source = current_source;
}
CYG_PRECONDITIONC((0 <= source) && (source < CdlValue_number_of_sources));
CYG_PRECONDITIONC(source_valid[source]);
CYG_PRECONDITION_THISC();
if (CdlValueSource_Current == source) {
- source = current_source;
+ source = current_source;
}
CYG_PRECONDITIONC((0 <= source) && (source < CdlValue_number_of_sources));
CYG_PRECONDITIONC(source_valid[source]);
}
//}}}
-//{{{ Value modification
+//{{{ Value modification
// ----------------------------------------------------------------------------
enabled[source] = val;
source_valid[source] = true;
if (source > current_source) {
- current_source = source;
+ current_source = source;
}
-
+
CYG_REPORT_RETURN();
}
CYG_INVARIANT_THISC(CdlValue);
CYG_PRECONDITIONC((CdlValueFlavor_BoolData == flavor) || (CdlValueFlavor_Data == flavor));
CYG_PRECONDITIONC((0 <= source) && (source < CdlValue_number_of_sources));
-
+
values[source] = val;
source_valid[source] = true;
if (source > current_source) {
- current_source = source;
+ current_source = source;
}
-
+
CYG_REPORT_RETURN();
}
values[source] = val;
source_valid[source] = true;
if (source > current_source) {
- current_source = source;
+ current_source = source;
}
-
+
CYG_REPORT_RETURN();
}
switch(flavor) {
case CdlValueFlavor_Bool:
- enabled[source] = val.get_bool_value();
- break;
+ enabled[source] = val.get_bool_value();
+ break;
case CdlValueFlavor_BoolData:
- if (!val.get_bool_value()) {
- enabled[source] = false;
- values[source] = (cdl_int) 0;
- } else {
- enabled[source] = true;
- values[source] = val;
- }
- break;
-
+ if (!val.get_bool_value()) {
+ enabled[source] = false;
+ values[source] = (cdl_int) 0;
+ } else {
+ enabled[source] = true;
+ values[source] = val;
+ }
+ break;
+
case CdlValueFlavor_Data:
- values[source] = val;
- break;
-
+ values[source] = val;
+ break;
+
default:
- CYG_FAIL("Unknown value flavor detected.");
+ CYG_FAIL("Unknown value flavor detected.");
}
-
+
source_valid[source] = true;
if (source > current_source) {
- current_source = source;
+ current_source = source;
}
CYG_REPORT_RETURN();
//}}}
//}}}
-//{{{ CdlListValue class
+//{{{ CdlListValue class
// ----------------------------------------------------------------------------
// List values. Most of this is straightforward.
// filled in already.
cdllistvalue_cookie = CdlListValue_Magic;
CYGDBG_MEMLEAK_CONSTRUCTOR();
-
+
CYG_POSTCONDITION_THISC();
CYG_REPORT_RETURN();
}
CYG_REPORT_FUNCNAME("CdlListValue:: copy constructor");
CYG_REPORT_FUNCARG2XV(this, &original);
CYG_INVARIANT_CLASSOC(CdlListValue, original);
-
+
// This may get expensive, but should not happen very often.
table = original.table;
integer_ranges = original.integer_ranges;
double_ranges = original.double_ranges;
cdllistvalue_cookie = CdlListValue_Magic;
CYGDBG_MEMLEAK_CONSTRUCTOR();
-
+
CYG_POSTCONDITION_THISC();
CYG_REPORT_RETURN();
}
CYG_INVARIANT_CLASSOC(CdlListValue, original);
if (this != &original) {
- table.clear();
- integer_ranges.clear();
- double_ranges.clear();
- table = original.table;
- integer_ranges = original.integer_ranges;
- double_ranges = original.double_ranges;
+ table.clear();
+ integer_ranges.clear();
+ double_ranges.clear();
+ table = original.table;
+ integer_ranges = original.integer_ranges;
+ double_ranges = original.double_ranges;
}
-
+
CYG_POSTCONDITION_THISC();
CYG_REPORT_RETURN();
return *this;
integer_ranges.clear();
double_ranges.clear();
CYGDBG_MEMLEAK_DESTRUCTOR();
-
+
CYG_REPORT_RETURN();
}
bool result = false;
if (val.has_integer_value()) {
- result = is_member(val.get_integer_value(), false);
+ result = is_member(val.get_integer_value(), false);
}
if (!result && val.has_double_value()) {
- result = is_member(val.get_double_value(), false);
+ result = is_member(val.get_double_value(), false);
}
if (!result) {
- result = is_member(val.get_value());
+ result = is_member(val.get_value());
}
-
+
CYG_REPORT_RETVAL(result);
return result;
}
bool result = false;
if (allow_conversions) {
- cdl_int integer_value;
- double double_value;
-
- if (Cdl::string_to_integer(val, integer_value)) {
- result = is_member(integer_value, false);
- }
- if (!result && Cdl::string_to_double(val, double_value)) {
- result = is_member(double_value, false);
- }
+ cdl_int integer_value;
+ double double_value;
+
+ if (Cdl::string_to_integer(val, integer_value)) {
+ result = is_member(integer_value, false);
+ }
+ if (!result && Cdl::string_to_double(val, double_value)) {
+ result = is_member(double_value, false);
+ }
}
if (!result) {
- for (std::vector<CdlSimpleValue>::const_iterator val_i = table.begin(); val_i != table.end(); val_i++) {
- if (val_i->get_value() == val) {
- result = true;
- break;
- }
- }
+ for (std::vector<CdlSimpleValue>::const_iterator val_i = table.begin(); val_i != table.end(); val_i++) {
+ if (val_i->get_value() == val) {
+ result = true;
+ break;
+ }
+ }
}
CYG_REPORT_RETVAL(result);
bool result = false;
for (std::vector<CdlSimpleValue>::const_iterator val_i = table.begin(); val_i != table.end(); val_i++) {
- if (val_i->has_integer_value() && (val_i->get_integer_value() == val)) {
- result = true;
- break;
- }
+ if (val_i->has_integer_value() && (val_i->get_integer_value() == val)) {
+ result = true;
+ break;
+ }
}
if (!result) {
- for (std::vector<std::pair<cdl_int,cdl_int> >::const_iterator i = integer_ranges.begin();
- i != integer_ranges.end(); i++) {
- if ((val >= i->first) && (val <= i->second)) {
- result = true;
- break;
- }
- }
+ for (std::vector<std::pair<cdl_int,cdl_int> >::const_iterator i = integer_ranges.begin();
+ i != integer_ranges.end(); i++) {
+ if ((val >= i->first) && (val <= i->second)) {
+ result = true;
+ break;
+ }
+ }
}
if (!result && allow_conversions) {
- double double_value = Cdl::integer_to_double(val);
- result = is_member(double_value, false);
+ double double_value = Cdl::integer_to_double(val);
+ result = is_member(double_value, false);
}
CYG_REPORT_RETVAL(result);
bool result = false;
for (std::vector<CdlSimpleValue>::const_iterator val_i = table.begin(); val_i != table.end(); val_i++) {
- if (val_i->has_double_value() && (val_i->get_double_value() == val)) {
- result = true;
- break;
- }
+ if (val_i->has_double_value() && (val_i->get_double_value() == val)) {
+ result = true;
+ break;
+ }
}
if (!result) {
- for (std::vector<std::pair<double,double> >::const_iterator i = double_ranges.begin();
- i != double_ranges.end(); i++) {
- if ((val >= i->first) && (val <= i->second)) {
- result = true;
- break;
- }
- }
+ for (std::vector<std::pair<double,double> >::const_iterator i = double_ranges.begin();
+ i != double_ranges.end(); i++) {
+ if ((val >= i->first) && (val <= i->second)) {
+ result = true;
+ break;
+ }
+ }
}
if (!result && allow_conversions) {
- cdl_int integer_value;
- if (Cdl::double_to_integer(val, integer_value)) {
- result = is_member(integer_value, false);
- }
+ cdl_int integer_value;
+ if (Cdl::double_to_integer(val, integer_value)) {
+ result = is_member(integer_value, false);
+ }
}
CYG_REPORT_RETVAL(result);
CdlListValue::check_this(cyg_assert_class_zeal zeal) const
{
if (CdlListValue_Magic != cdllistvalue_cookie) {
- return false;
+ return false;
}
CYGDBG_MEMLEAK_CHECKTHIS();
//}}}
-//{{{ dialog property
+//{{{ dialog property
// ----------------------------------------------------------------------------
// Syntax: dialog <reference>
void
CdlValuableBody::dialog_update_handler(CdlTransaction transaction, CdlNode source, CdlProperty prop, CdlNode dest,
- CdlUpdate change)
+ CdlUpdate change)
{
CYG_REPORT_FUNCNAME("CdlValuable::dialog_update_handler");
CYG_PRECONDITION_CLASSC(transaction);
CYG_PRECONDITION_CLASSC(source);
CYG_PRECONDITION_CLASSC(prop);
-
+
// The main update of interest is Loaded (iff dest != 0), and
// Created. These updates indicate that the destination now exists,
// so it is possible to check that the destination is a dialog.
if (((CdlUpdate_Loaded == change) && (0 != dest)) ||
- (CdlUpdate_Created == change)) {
-
- CYG_ASSERT_CLASSC(dest);
- CdlDialog dialog = dynamic_cast<CdlDialog>(dest);
- if (0 == dialog) {
- std::string msg = dest->get_class_name() + " " + dest->get_name() +
- " cannot be used in a dialog property, it is not a custom dialog.";
- CdlConflict_DataBody::make(transaction, source, prop, msg);
- }
-
+ (CdlUpdate_Created == change)) {
+
+ CYG_ASSERT_CLASSC(dest);
+ CdlDialog dialog = dynamic_cast<CdlDialog>(dest);
+ if (0 == dialog) {
+ std::string msg = dest->get_class_name() + " " + dest->get_name() +
+ " cannot be used in a dialog property, it is not a custom dialog.";
+ CdlConflict_DataBody::make(transaction, source, prop, msg);
+ }
+
} else if (CdlUpdate_Destroyed == change) {
- // If there was a data conflict object, it is no longer relevant
- transaction->clear_structural_conflicts(source, prop, &CdlConflict_DataBody::test);
+ // If there was a data conflict object, it is no longer relevant
+ transaction->clear_structural_conflicts(source, prop, &CdlConflict_DataBody::test);
}
CYG_REPORT_RETURN();
CYG_REPORT_FUNCNAMETYPE("parse_dialog", "result %d");
int result = CdlParse::parse_reference_property(interp, argc, argv, CdlPropertyId_Dialog, 0, 0, false, &dialog_update_handler);
-
+
CYG_REPORT_RETVAL(result);
return result;
}
bool result = false;
CdlProperty property = get_property(CdlPropertyId_Dialog);
if (0 != property) {
- CdlProperty_Reference ref_prop = dynamic_cast<CdlProperty_Reference>(property);
- CYG_ASSERTC(0 != ref_prop);
-
- CdlNode destination = ref_prop->get_destination();
- if (0 != destination) {
- CdlDialog dialog = dynamic_cast<CdlDialog>(destination);
- if (0 != dialog) {
- result = true;
- }
- }
+ CdlProperty_Reference ref_prop = dynamic_cast<CdlProperty_Reference>(property);
+ CYG_ASSERTC(0 != ref_prop);
+
+ CdlNode destination = ref_prop->get_destination();
+ if (0 != destination) {
+ CdlDialog dialog = dynamic_cast<CdlDialog>(destination);
+ if (0 != dialog) {
+ result = true;
+ }
+ }
}
CYG_REPORT_RETVAL(result);
return result;
CdlDialog result = 0;
CdlProperty property = get_property(CdlPropertyId_Dialog);
if (0 != property) {
- CdlProperty_Reference ref_prop = dynamic_cast<CdlProperty_Reference>(property);
- CYG_ASSERTC(0 != ref_prop);
+ CdlProperty_Reference ref_prop = dynamic_cast<CdlProperty_Reference>(property);
+ CYG_ASSERTC(0 != ref_prop);
- CdlNode destination = ref_prop->get_destination();
- if (0 != destination) {
- result = dynamic_cast<CdlDialog>(destination);
- }
+ CdlNode destination = ref_prop->get_destination();
+ if (0 != destination) {
+ result = dynamic_cast<CdlDialog>(destination);
+ }
}
CYG_REPORT_RETVAL(result);
}
//}}}
-//{{{ wizard property
+//{{{ wizard property
// ----------------------------------------------------------------------------
// Syntax: wizard <reference>
void
CdlValuableBody::wizard_update_handler(CdlTransaction transaction, CdlNode source, CdlProperty prop, CdlNode dest,
- CdlUpdate change)
+ CdlUpdate change)
{
CYG_REPORT_FUNCNAME("CdlValuable::wizard_update_handler");
CYG_PRECONDITION_CLASSC(transaction);
CYG_PRECONDITION_CLASSC(source);
CYG_PRECONDITION_CLASSC(prop);
-
+
// The main update of interest is Loaded (iff dest != 0), and
// Created. These updates indicate that the destination now exists,
// so it is possible to check that the destination is a dialog.
if (((CdlUpdate_Loaded == change) && (0 != dest)) ||
- (CdlUpdate_Created == change)) {
-
- CYG_ASSERT_CLASSC(dest);
- CdlWizard wizard = dynamic_cast<CdlWizard>(dest);
- if (0 == wizard) {
- std::string msg = dest->get_class_name() + " " + dest->get_name() +
- " cannot be used in a wizard property, it is not a wizard.";
- CdlConflict_DataBody::make(transaction, source, prop, msg);
- }
-
+ (CdlUpdate_Created == change)) {
+
+ CYG_ASSERT_CLASSC(dest);
+ CdlWizard wizard = dynamic_cast<CdlWizard>(dest);
+ if (0 == wizard) {
+ std::string msg = dest->get_class_name() + " " + dest->get_name() +
+ " cannot be used in a wizard property, it is not a wizard.";
+ CdlConflict_DataBody::make(transaction, source, prop, msg);
+ }
+
} else if (CdlUpdate_Destroyed == change) {
- // If there was a data conflict object, it is no longer relevant
- transaction->clear_structural_conflicts(source, prop, &CdlConflict_DataBody::test);
+ // If there was a data conflict object, it is no longer relevant
+ transaction->clear_structural_conflicts(source, prop, &CdlConflict_DataBody::test);
}
CYG_REPORT_RETURN();
bool result = false;
CdlProperty property = get_property(CdlPropertyId_Wizard);
if (0 != property) {
- CdlProperty_Reference ref_prop = dynamic_cast<CdlProperty_Reference>(property);
- CYG_ASSERTC(0 != ref_prop);
-
- CdlNode destination = ref_prop->get_destination();
- if (0 != destination) {
- CdlWizard wizard = dynamic_cast<CdlWizard>(destination);
- CYG_ASSERTC(0 != wizard);
- CYG_UNUSED_PARAM(CdlWizard, wizard);
- result = true;
- }
+ CdlProperty_Reference ref_prop = dynamic_cast<CdlProperty_Reference>(property);
+ CYG_ASSERTC(0 != ref_prop);
+
+ CdlNode destination = ref_prop->get_destination();
+ if (0 != destination) {
+ CdlWizard wizard = dynamic_cast<CdlWizard>(destination);
+ CYG_ASSERTC(0 != wizard);
+ CYG_UNUSED_PARAM(CdlWizard, wizard);
+ result = true;
+ }
}
CYG_REPORT_RETVAL(result);
return result;
CdlWizard result = 0;
CdlProperty property = get_property(CdlPropertyId_Wizard);
if (0 != property) {
- CdlProperty_Reference ref_prop = dynamic_cast<CdlProperty_Reference>(property);
- CYG_ASSERTC(0 != ref_prop);
-
- CdlNode destination = ref_prop->get_destination();
- if (0 != destination) {
- result = dynamic_cast<CdlWizard>(destination);
- CYG_ASSERTC(0 != result);
- }
+ CdlProperty_Reference ref_prop = dynamic_cast<CdlProperty_Reference>(property);
+ CYG_ASSERTC(0 != ref_prop);
+
+ CdlNode destination = ref_prop->get_destination();
+ if (0 != destination) {
+ result = dynamic_cast<CdlWizard>(destination);
+ CYG_ASSERTC(0 != result);
+ }
}
CYG_REPORT_RETVAL(result);
}
//}}}
-//{{{ legal_values property
+//{{{ legal_values property
// ----------------------------------------------------------------------------
// Syntax: legal_values <list expression>
void
CdlValuableBody::legal_values_update_handler(CdlTransaction transaction, CdlNode source, CdlProperty prop, CdlNode dest,
- CdlUpdate change)
+ CdlUpdate change)
{
CYG_REPORT_FUNCNAME("legal_values_update_handler");
// Any other change can affect the list expression and hence
// invalidate the current value.
if ((CdlUpdate_Loaded == change) || (CdlUpdate_Unloading == change)) {
- CYG_REPORT_RETURN();
- return;
+ CYG_REPORT_RETURN();
+ return;
}
CdlValuable valuable = dynamic_cast<CdlValuable>(source);
CYG_REPORT_FUNCNAMETYPE("parse_legal_values", "result %d");
int result = CdlParse::parse_listexpression_property(interp, argc, argv, CdlPropertyId_LegalValues, 0, 0,
- &legal_values_update_handler);
+ &legal_values_update_handler);
CYG_REPORT_RETVAL(result);
return result;
}
CdlProperty_ListExpression result = 0;
CdlProperty property = get_property(CdlPropertyId_LegalValues);
if (0 != property) {
- result = dynamic_cast<CdlProperty_ListExpression>(property);
- CYG_ASSERTC(0 != result);
+ result = dynamic_cast<CdlProperty_ListExpression>(property);
+ CYG_ASSERTC(0 != result);
}
CYG_REPORT_RETVAL(result);
}
//}}}
-//{{{ default_value property
+//{{{ default_value property
// ----------------------------------------------------------------------------
// syntax: default_value <expr>
void
CdlValuableBody::default_value_update_handler(CdlTransaction transaction, CdlNode source, CdlProperty prop, CdlNode dest,
- CdlUpdate change)
+ CdlUpdate change)
{
CYG_REPORT_FUNCNAME("CdlValuable::default_value_update_handler");
CYG_REPORT_FUNCARG5XV(transaction, source, prop, dest, change);
// Loaded and unloading should be ignored.
if ((CdlUpdate_Loaded == change) || (CdlUpdate_Unloading == change)) {
- CYG_REPORT_RETURN();
- return;
+ CYG_REPORT_RETURN();
+ return;
}
// Init, Created, Destroyed, ValueChange and ActiveChange should
CYG_ASSERTC(0 != valuable);
CdlProperty_Expression expr = dynamic_cast<CdlProperty_Expression>(prop);
CYG_ASSERTC(0 != expr);
-
+
CdlSimpleValue val;
try {
-
- CdlEvalContext context(transaction, source, prop);
- expr->eval(context, val);
- valuable->set(transaction, val, CdlValueSource_Default);
+ CdlEvalContext context(transaction, source, prop);
+ expr->eval(context, val);
+
+ valuable->set(transaction, val, CdlValueSource_Default);
} catch(CdlEvalException e) {
-
- // An EvalException conflict will have been created, so the
- // user knows that this default_value is not kosher. It is
- // still a good idea to make sure that the object retains a
- // sensible value.
- val = (cdl_int) 0;
- valuable->set(transaction, val, CdlValueSource_Default);
+
+ // An EvalException conflict will have been created, so the
+ // user knows that this default_value is not kosher. It is
+ // still a good idea to make sure that the object retains a
+ // sensible value.
+ val = (cdl_int) 0;
+ valuable->set(transaction, val, CdlValueSource_Default);
}
CYG_UNUSED_PARAM(CdlNode, dest);
{
CYG_REPORT_FUNCNAMETYPE("parse_default_value", "result %d");
int result = CdlParse::parse_expression_property(interp, argc, argv, CdlPropertyId_DefaultValue, 0, 0,
- &default_value_update_handler);
+ &default_value_update_handler);
CYG_REPORT_RETVAL(result);
return result;
}
CdlProperty_Expression result = 0;
CdlProperty property = get_property(CdlPropertyId_DefaultValue);
if (0 != property) {
- result = dynamic_cast<CdlProperty_Expression>(property);
- CYG_ASSERTC(0 != result);
+ result = dynamic_cast<CdlProperty_Expression>(property);
+ CYG_ASSERTC(0 != result);
}
CYG_REPORT_RETVAL(result);
}
//}}}
-//{{{ calculated_property
+//{{{ calculated_property
// ----------------------------------------------------------------------------
// Syntax: calculated <expression>
void
CdlValuableBody::calculated_update_handler(CdlTransaction transaction, CdlNode source, CdlProperty prop, CdlNode dest,
- CdlUpdate change)
+ CdlUpdate change)
{
CYG_REPORT_FUNCNAME("CdlValuable::default_value_update_handler");
CYG_REPORT_FUNCARG5XV(transaction, source, prop, dest, change);
// Loaded and unloading should be ignored.
if ((CdlUpdate_Loaded == change) || (CdlUpdate_Unloading == change)) {
- CYG_REPORT_RETURN();
- return;
+ CYG_REPORT_RETURN();
+ return;
}
// Init, Created, Destroyed, ValueChange and ActiveChange should
CYG_ASSERTC(0 != valuable);
CdlProperty_Expression expr = dynamic_cast<CdlProperty_Expression>(prop);
CYG_ASSERTC(0 != expr);
-
+
CdlSimpleValue val;
try {
-
- CdlEvalContext context(transaction, source, prop);
- expr->eval(context, val);
- valuable->set(transaction, val, CdlValueSource_Default);
+ CdlEvalContext context(transaction, source, prop);
+ expr->eval(context, val);
+
+ valuable->set(transaction, val, CdlValueSource_Default);
} catch(CdlEvalException e) {
-
- // An EvalException conflict will have been created, so the
- // user knows that this default_value is not kosher. It is
- // still a good idea to make sure that the object retains a
- // sensible value.
- val = (cdl_int) 0;
- valuable->set(transaction, val, CdlValueSource_Default);
+
+ // An EvalException conflict will have been created, so the
+ // user knows that this default_value is not kosher. It is
+ // still a good idea to make sure that the object retains a
+ // sensible value.
+ val = (cdl_int) 0;
+ valuable->set(transaction, val, CdlValueSource_Default);
}
CYG_UNUSED_PARAM(CdlNode, dest);
CYG_REPORT_FUNCNAMETYPE("parse_calculated", "result %d");
int result = CdlParse::parse_expression_property(interp, argc, argv, CdlPropertyId_Calculated, 0, 0,
- &calculated_update_handler);
+ &calculated_update_handler);
CYG_REPORT_RETVAL(result);
return result;
}
CdlProperty_Expression result = 0;
CdlProperty property = get_property(CdlPropertyId_Calculated);
if (0 != property) {
- result = dynamic_cast<CdlProperty_Expression>(property);
- CYG_ASSERTC(0 != result);
+ result = dynamic_cast<CdlProperty_Expression>(property);
+ CYG_ASSERTC(0 != result);
}
CYG_REPORT_RETVAL(result);
}
//}}}
-//{{{ active_if property
+//{{{ active_if property
// ----------------------------------------------------------------------------
// Syntax:
void
CdlValuableBody::active_if_update_handler(CdlTransaction transaction, CdlNode source, CdlProperty prop, CdlNode dest,
- CdlUpdate change)
+ CdlUpdate change)
{
CYG_REPORT_FUNCNAME("CdlValuable::active_if_update_handler");
CYG_REPORT_FUNCARG5XV(transaction, source, prop, dest, change);
// Loaded should be ignored here, the world is still getting sorted out.
// Unloading is of no interest, the source is disappearing anyway.
if ((CdlUpdate_Loaded == change) || (CdlUpdate_Unloading == change)) {
- CYG_REPORT_RETURN();
- return;
+ CYG_REPORT_RETURN();
+ return;
}
// Any other change warrants re-evaluating the active status of the source.
bool old_state = transaction->is_active(source);
bool new_state = source->test_active(transaction);
if (old_state != new_state) {
- transaction->set_active(source, new_state);
+ transaction->set_active(source, new_state);
}
-
+
CYG_UNUSED_PARAM(CdlNode, dest);
CYG_REPORT_RETURN();
}
CYG_REPORT_FUNCNAMETYPE("parse_active_if", "result %d");
int result = CdlParse::parse_goalexpression_property(interp, argc, argv, CdlPropertyId_ActiveIf, 0, 0,
- &active_if_update_handler);
+ &active_if_update_handler);
CYG_REPORT_RETVAL(result);
return result;
}
get_properties(CdlPropertyId_ActiveIf, properties);
std::vector<CdlProperty>::const_iterator i;
for (i = properties.begin(); i != properties.end(); i++) {
- CdlProperty_GoalExpression goal = dynamic_cast<CdlProperty_GoalExpression>(*i);
- CYG_ASSERTC(0 != goal);
- result.push_back(goal);
+ CdlProperty_GoalExpression goal = dynamic_cast<CdlProperty_GoalExpression>(*i);
+ CYG_ASSERTC(0 != goal);
+ result.push_back(goal);
}
CYG_REPORT_RETURN();
}
//}}}
-//{{{ requires property
+//{{{ requires property
// ----------------------------------------------------------------------------
// Syntax: requires <goal expression>
void
CdlValuableBody::requires_update_handler(CdlTransaction transaction, CdlNode source, CdlProperty prop, CdlNode dest,
- CdlUpdate change)
+ CdlUpdate change)
{
CYG_REPORT_FUNCNAME("CdlValuable::requires_update_handler");
CYG_REPORT_FUNCARG5XV(transaction, source, prop, dest, change);
// Loaded and Unloading are not of interest.
if ((CdlUpdate_Loaded == change) || (CdlUpdate_Unloading == change)) {
- CYG_REPORT_RETURN();
- return;
+ CYG_REPORT_RETURN();
+ return;
}
-
+
// Any other change should cause normal handling. This happens in
// a separate function because "requires" properties also need to
// be checked when e.g. the source becomes inactive.
CYG_REPORT_FUNCNAMETYPE("parse_requires", "result %d");
int result = CdlParse::parse_goalexpression_property(interp, argc, argv, CdlPropertyId_Requires, 0, 0,
- &requires_update_handler);
+ &requires_update_handler);
CYG_REPORT_RETVAL(result);
return result;
}
get_properties(CdlPropertyId_Requires, properties);
std::vector<CdlProperty>::const_iterator i;
for (i = properties.begin(); i != properties.end(); i++) {
- CdlProperty_GoalExpression goal = dynamic_cast<CdlProperty_GoalExpression>(*i);
- CYG_ASSERTC(0 != goal);
- result.push_back(goal);
+ CdlProperty_GoalExpression goal = dynamic_cast<CdlProperty_GoalExpression>(*i);
+ CYG_ASSERTC(0 != goal);
+ result.push_back(goal);
}
CYG_REPORT_RETURN();
}
//}}}
-//{{{ implements property
+//{{{ implements property
// ----------------------------------------------------------------------------
// Syntax: implements <reference to interface>
void
CdlValuableBody::implements_update_handler(CdlTransaction transaction, CdlNode source, CdlProperty prop, CdlNode dest,
- CdlUpdate change)
+ CdlUpdate change)
{
CYG_REPORT_FUNCNAME("CdlValuable::implements_update_handler");
CYG_REPORT_FUNCARG5XV(transaction, source, prop, dest, change);
// Any changes to the interface itself can be ignored.
if ((CdlUpdate_ValueChange == change) || (CdlUpdate_ActiveChange == change)) {
- CYG_REPORT_RETURN();
- return;
+ CYG_REPORT_RETURN();
+ return;
}
// The second stage init is irrelevant
if (CdlUpdate_Init == change) {
- CYG_REPORT_RETURN();
- return;
+ CYG_REPORT_RETURN();
+ return;
}
// Possibilities:
//
// If the dest is invalid, a structural conflict has to be created.
if (CdlUpdate_Destroyed == change) {
- // There is no need to do any clean-ups in the dest.
- dest = 0;
+ // There is no need to do any clean-ups in the dest.
+ dest = 0;
}
if (0 == dest) {
- transaction->clear_structural_conflicts(source, prop, &CdlConflict_DataBody::test);
+ transaction->clear_structural_conflicts(source, prop, &CdlConflict_DataBody::test);
} else {
- CdlInterface interface = dynamic_cast<CdlInterface>(dest);
-
- if (0 == interface) {
- std::string msg = source->get_class_name() + " " + source->get_name() + " cannot implement " +
- dest->get_name() + "\n The latter is not an interface.";
- CdlConflict_DataBody::make(transaction, source, prop, msg);
- } else {
- transaction->clear_structural_conflicts(source, prop, &CdlConflict_DataBody::test);
- interface->recalculate(transaction);
- }
+ CdlInterface interface = dynamic_cast<CdlInterface>(dest);
+
+ if (0 == interface) {
+ std::string msg = source->get_class_name() + " " + source->get_name() + " cannot implement " +
+ dest->get_name() + "\n The latter is not an interface.";
+ CdlConflict_DataBody::make(transaction, source, prop, msg);
+ } else {
+ transaction->clear_structural_conflicts(source, prop, &CdlConflict_DataBody::test);
+ interface->recalculate(transaction);
+ }
}
-
+
CYG_REPORT_RETURN();
}
CYG_REPORT_FUNCNAMETYPE("parse_implements", "result %d");
int result = CdlParse::parse_reference_property(interp, argc, argv, CdlPropertyId_Implements, 0, 0, false,
- &implements_update_handler);
-
+ &implements_update_handler);
+
CYG_REPORT_RETVAL(result);
return result;
}
get_properties(CdlPropertyId_Implements, properties);
std::vector<CdlProperty>::const_iterator i;
for (i = properties.begin(); i != properties.end(); i++) {
- CdlProperty_Reference refprop = dynamic_cast<CdlProperty_Reference>(*i);
- CYG_ASSERTC(0 != refprop);
- CdlNode node = refprop->get_destination();
- if (0 != node) {
- CdlInterface interface = dynamic_cast<CdlInterface>(node);
- CYG_ASSERT_CLASSC(interface);
- result.push_back(interface);
- }
+ CdlProperty_Reference refprop = dynamic_cast<CdlProperty_Reference>(*i);
+ CYG_ASSERTC(0 != refprop);
+ CdlNode node = refprop->get_destination();
+ if (0 != node) {
+ CdlInterface interface = dynamic_cast<CdlInterface>(node);
+ CYG_ASSERT_CLASSC(interface);
+ result.push_back(interface);
+ }
}
CYG_REPORT_RETURN();
}
//}}}
-//{{{ Other properties
+//{{{ Other properties
// ----------------------------------------------------------------------------
// Syntax: flavor <legal flavor>
CYG_REPORT_FUNCNAME("parse_flavor_final_check");
CYG_PRECONDITION_CLASSC(interp);
CYG_PRECONDITION_CLASSC(prop);
-
+
const std::string& str = prop->get_string();
std::string copy = std::string(str);
CdlValueFlavor flavor;
if (!Cdl::string_to_flavor(copy, flavor)) {
- CdlParse::report_property_parse_error(interp, prop, str + " is not a valid CDL flavor.");
+ CdlParse::report_property_parse_error(interp, prop, str + " is not a valid CDL flavor.");
}
-
+
CYG_REPORT_RETURN();
}
CYG_REPORT_FUNCNAMETYPE("parse_group", "result %d");
int result = CdlParse::parse_string_property(interp, argc, argv, CdlPropertyId_Group, 0, 0);
-
+
CYG_REPORT_RETVAL(result);
return result;
}
CYG_REPORT_FUNCNAMETYPE("parse_check_proc", "result %d");
int result = CdlParse::parse_tclcode_property(interp, argc, argv, CdlPropertyId_CheckProc, 0, 0);
-
+
CYG_REPORT_RETVAL(result);
return result;
}
cdl_tcl_code result = "";
CdlProperty property = get_property(CdlPropertyId_CheckProc);
if (0 != property) {
- CdlProperty_TclCode code_prop = dynamic_cast<CdlProperty_TclCode>(property);
- CYG_ASSERTC(0 != code_prop);
- result = code_prop->get_code();
+ CdlProperty_TclCode code_prop = dynamic_cast<CdlProperty_TclCode>(property);
+ CYG_ASSERTC(0 != code_prop);
+ result = code_prop->get_code();
}
-
+
CYG_REPORT_RETURN();
return result;
}
CYG_REPORT_FUNCNAMETYPE("parse_entry_proc", "result %d");
int result = CdlParse::parse_tclcode_property(interp, argc, argv, CdlPropertyId_EntryProc, 0, 0);
-
+
CYG_REPORT_RETVAL(result);
return result;
}
cdl_tcl_code result = "";
CdlProperty property = get_property(CdlPropertyId_EntryProc);
if (0 != property) {
- CdlProperty_TclCode code_prop = dynamic_cast<CdlProperty_TclCode>(property);
- CYG_ASSERTC(0 != code_prop);
- result = code_prop->get_code();
+ CdlProperty_TclCode code_prop = dynamic_cast<CdlProperty_TclCode>(property);
+ CYG_ASSERTC(0 != code_prop);
+ result = code_prop->get_code();
}
CYG_REPORT_RETURN();
//}}}
-//{{{ CdlValuable misc
+//{{{ CdlValuable misc
// ----------------------------------------------------------------------------
// Objects with flavor none are not modifiable. Also, objects with the
bool result = true;
if (CdlValueFlavor_None == get_flavor()) {
- result = false;
+ result = false;
} else if (has_property(CdlPropertyId_Calculated)) {
- result = false;
+ result = false;
}
CYG_REPORT_RETVAL(result);
}
//}}}
-//{{{ CdlValuable::get_widget_hint()
+//{{{ CdlValuable::get_widget_hint()
// ----------------------------------------------------------------------------
// separate dialog, followed by a tree redisplay
CdlConstLoadable loadable = dynamic_cast<CdlConstLoadable>(this);
if (0 != loadable) {
- hint.value_widget = CdlValueWidget_Loadable;
- CYG_REPORT_RETURN();
- return;
+ hint.value_widget = CdlValueWidget_Loadable;
+ CYG_REPORT_RETURN();
+ return;
}
-
+
// If the valuable is not modifiable then we are already done.
CdlValueFlavor flavor = this->get_flavor();
if ((CdlValueFlavor_None == flavor) || !this->is_modifiable()) {
- CYG_REPORT_RETURN();
- return;
+ CYG_REPORT_RETURN();
+ return;
}
// If there is a custom dialog and dialogs are enabled, use it.
if (this->has_dialog() && CdlDialogBody::dialogs_are_enabled()) {
- if ((CdlValueFlavor_Bool == flavor) || (CdlValueFlavor_BoolData == flavor)) {
- hint.bool_widget = CdlBoolWidget_CustomDialog;
- }
- if ((CdlValueFlavor_Data == flavor) || (CdlValueFlavor_BoolData == flavor)) {
- hint.value_widget = CdlValueWidget_CustomDialog;
- }
- CYG_REPORT_RETURN();
- return;
+ if ((CdlValueFlavor_Bool == flavor) || (CdlValueFlavor_BoolData == flavor)) {
+ hint.bool_widget = CdlBoolWidget_CustomDialog;
+ }
+ if ((CdlValueFlavor_Data == flavor) || (CdlValueFlavor_BoolData == flavor)) {
+ hint.value_widget = CdlValueWidget_CustomDialog;
+ }
+ CYG_REPORT_RETURN();
+ return;
}
-
+
// Process the bool part, if any
if ((CdlValueFlavor_Bool == flavor) || (CdlValueFlavor_BoolData == flavor)) {
-
- // Default to a CheckButton
- hint.bool_widget = CdlBoolWidget_CheckButton;
-
- // Under some circumstances it is appropriate to use a radio button instead.
- // This is the case when there are several mutually exclusive entities.
- // Most of the time radio buttons should actually be handled by a single
- // option which has a list of legal values. There are a couple of cases
- // where this is not appropriate:
- //
- // 1) grouping. Some of the mutually exclusive entities could be containers.
- // With clever use of a single option and some active_if properties it
- // would be possible to get almost the same effect, but not quite.
- //
- // 2) external packages. It should be possible to have a third party package
- // which could add e.g. a new scheduler.
- //
- // The implementation of this involves interfaces. Basically mutually
- // exclusive entities should implement the same interface, and that
- // interface should have an explicit requires $cdl_value == 1
- // In addition all of the options involved should have the same parent.
- // An entity may implement multiple interfaces, so they all have to be checked
- CdlInterface radio_interface = 0;
- std::vector<CdlProperty> implements = this->get_properties(CdlPropertyId_Implements);
- std::vector<CdlProperty>::const_iterator imp_i;
- for (imp_i = implements.begin(); (imp_i != implements.end()) && (0 == radio_interface); imp_i++) {
- CdlProperty_Reference refprop = dynamic_cast<CdlProperty_Reference>(*imp_i);
- CYG_ASSERT_CLASSC(refprop);
-
- CdlNode destnode = refprop->get_destination();
- if (0 == destnode) {
- continue;
- }
- CdlInterface interface = dynamic_cast<CdlInterface>(destnode);
- CYG_ASSERT_CLASSC(interface);
-
- std::vector<CdlProperty_GoalExpression> requires;
- std::vector<CdlProperty_GoalExpression>::const_iterator req_i;
- interface->get_requires_goals(requires);
- for (req_i = requires.begin(); req_i != requires.end(); req_i++) {
-
- CdlExpression expr = (*req_i)->get_expression();
- CdlSubexpression& subexpr = expr->sub_expressions[expr->first_subexpression];
- if (CdlExprOp_Equal != subexpr.op) {
- continue;
- }
-
- CdlSubexpression& lhs = expr->sub_expressions[subexpr.lhs_index];
- CdlSubexpression& rhs = expr->sub_expressions[subexpr.rhs_index];
- CdlSubexpression* ref_operand = &lhs;
-
- // Allow for "a == 1" or "1 == a"
- if ((CdlExprOp_IntegerConstant == lhs.op) && (1 == lhs.constants.get_integer_value())) {
- ref_operand = &rhs;
- } else if ((CdlExprOp_IntegerConstant == rhs.op) && (1 == rhs.constants.get_integer_value())) {
- ref_operand = &lhs;
- } else {
- continue;
- }
-
- if (CdlExprOp_Reference != ref_operand->op) {
- continue;
- }
- CdlReference& ref = expr->references[ref_operand->reference_index];
- if (ref.get_destination() == interface) {
- break;
- }
- }
- if (req_i == requires.end()) {
- continue;
- }
-
- CdlContainer parent = this->get_parent();
- CYG_ASSERT_CLASSC(parent);
-
- std::vector<CdlValuable> implementers;
- std::vector<CdlValuable>::const_iterator imp_i;
- interface->get_implementers(implementers);
- for (imp_i = implementers.begin(); imp_i != implementers.end(); imp_i++) {
- if (parent != (*imp_i)->get_parent()) {
- break;
- }
- }
-
- if (imp_i == implementers.end()) {
- // An interface has been found that matches the constraints.
- radio_interface = interface;
- }
- }
- if (0 != radio_interface) {
- hint.bool_widget = CdlBoolWidget_Radio;
- hint.radio_button_interface = radio_interface->get_name();
- }
+
+ // Default to a CheckButton
+ hint.bool_widget = CdlBoolWidget_CheckButton;
+
+ // Under some circumstances it is appropriate to use a radio button instead.
+ // This is the case when there are several mutually exclusive entities.
+ // Most of the time radio buttons should actually be handled by a single
+ // option which has a list of legal values. There are a couple of cases
+ // where this is not appropriate:
+ //
+ // 1) grouping. Some of the mutually exclusive entities could be containers.
+ // With clever use of a single option and some active_if properties it
+ // would be possible to get almost the same effect, but not quite.
+ //
+ // 2) external packages. It should be possible to have a third party package
+ // which could add e.g. a new scheduler.
+ //
+ // The implementation of this involves interfaces. Basically mutually
+ // exclusive entities should implement the same interface, and that
+ // interface should have an explicit requires $cdl_value == 1
+ // In addition all of the options involved should have the same parent.
+ // An entity may implement multiple interfaces, so they all have to be checked
+ CdlInterface radio_interface = 0;
+ std::vector<CdlProperty> implements = this->get_properties(CdlPropertyId_Implements);
+ std::vector<CdlProperty>::const_iterator imp_i;
+ for (imp_i = implements.begin(); (imp_i != implements.end()) && (0 == radio_interface); imp_i++) {
+ CdlProperty_Reference refprop = dynamic_cast<CdlProperty_Reference>(*imp_i);
+ CYG_ASSERT_CLASSC(refprop);
+
+ CdlNode destnode = refprop->get_destination();
+ if (0 == destnode) {
+ continue;
+ }
+ CdlInterface interface = dynamic_cast<CdlInterface>(destnode);
+ CYG_ASSERT_CLASSC(interface);
+
+ std::vector<CdlProperty_GoalExpression> requires;
+ std::vector<CdlProperty_GoalExpression>::const_iterator req_i;
+ interface->get_requires_goals(requires);
+ for (req_i = requires.begin(); req_i != requires.end(); req_i++) {
+
+ CdlExpression expr = (*req_i)->get_expression();
+ CdlSubexpression& subexpr = expr->sub_expressions[expr->first_subexpression];
+ if (CdlExprOp_Equal != subexpr.op) {
+ continue;
+ }
+
+ CdlSubexpression& lhs = expr->sub_expressions[subexpr.lhs_index];
+ CdlSubexpression& rhs = expr->sub_expressions[subexpr.rhs_index];
+ CdlSubexpression* ref_operand = &lhs;
+
+ // Allow for "a == 1" or "1 == a"
+ if ((CdlExprOp_IntegerConstant == lhs.op) && (1 == lhs.constants.get_integer_value())) {
+ ref_operand = &rhs;
+ } else if ((CdlExprOp_IntegerConstant == rhs.op) && (1 == rhs.constants.get_integer_value())) {
+ ref_operand = &lhs;
+ } else {
+ continue;
+ }
+
+ if (CdlExprOp_Reference != ref_operand->op) {
+ continue;
+ }
+ CdlReference& ref = expr->references[ref_operand->reference_index];
+ if (ref.get_destination() == interface) {
+ break;
+ }
+ }
+ if (req_i == requires.end()) {
+ continue;
+ }
+
+ CdlContainer parent = this->get_parent();
+ CYG_ASSERT_CLASSC(parent);
+
+ std::vector<CdlValuable> implementers;
+ std::vector<CdlValuable>::const_iterator imp_i;
+ interface->get_implementers(implementers);
+ for (imp_i = implementers.begin(); imp_i != implementers.end(); imp_i++) {
+ if (parent != (*imp_i)->get_parent()) {
+ break;
+ }
+ }
+
+ if (imp_i == implementers.end()) {
+ // An interface has been found that matches the constraints.
+ radio_interface = interface;
+ }
+ }
+ if (0 != radio_interface) {
+ hint.bool_widget = CdlBoolWidget_Radio;
+ hint.radio_button_interface = radio_interface->get_name();
+ }
}
// Process the data part, if any
if ((CdlValueFlavor_Data == flavor) || (CdlValueFlavor_BoolData == flavor)) {
-
- // Default to a simple entry box.
- hint.value_widget = CdlValueWidget_EntryBox;
-
- // If there is a legal_values list, this will normally indicate
- // which widget should be used.
- if (this->has_legal_values()) {
- // The legal_values expression needs to be evaluated and examined.
- // If the result is a simple numerical range then all we need to
- // figure out is whether to default to decimal, hex, octal or double.
- // Otherwise if the result is a simple list and all of the entries
- // are numerical, that is sufficient information. If a list with
- // non-numerical entries that is fine as well. Anything more complicated
- // needs to revert to an entry box.
- CdlProperty_ListExpression lexpr = this->get_legal_values();
- CdlEvalContext context(0, this, lexpr);
- CdlListValue val;
-
- try {
- lexpr->eval(context, val);
- const std::vector<CdlSimpleValue>& table = val.get_table();
- const std::vector<std::pair<cdl_int, cdl_int> >& int_ranges = val.get_integer_ranges();
- const std::vector<std::pair<double, double> >& double_ranges = val.get_double_ranges();
-
- if ((0 == table.size()) && (0 == int_ranges.size()) && (1 == double_ranges.size())) {
-
- // A straightforward range of double precision numbers
- hint.value_widget = CdlValueWidget_DoubleRange;
-
- } else if ((0 == table.size()) && (1 == int_ranges.size()) && (0 == double_ranges.size())) {
-
- // Bummer. The formatting information has been lost.
- // To fix this the two sets of ranges should be collapsed into pairs of
- // CdlSimpleValue's.
- hint.value_widget = CdlValueWidget_DecimalRange;
-
- } else if ((1 <= table.size() && (0 == int_ranges.size()) && (0 == double_ranges.size()))) {
-
- // If all of the values are numerical, then we have a numeric set.
- // Otherwise we have a string set.
- bool all_numeric = true;
- std::vector<CdlSimpleValue>::const_iterator tab_i;
- for (tab_i = table.begin(); (tab_i != table.end()) && all_numeric; tab_i++) {
- if (!tab_i->has_double_value() && !tab_i->has_integer_value()) {
- all_numeric = false;
- }
- }
- if (all_numeric) {
- hint.value_widget = CdlValueWidget_NumericSet;
- } else {
- hint.value_widget = CdlValueWidget_StringSet;
- }
-
- } else {
- // The list expression is a complex combination. Leave it as an entry box.
- // In some cases it would be possible to do better, for example
- // legal_values -1 1 to 4 8 to 12
- // Support for cases like these may get added in future, if such cases
- // ever arise in practice.
- }
-
- } catch(...) {
- // Not a lot that can be done here, unfortunately
- }
- } else {
- // There is no legal_values property, so an entry box is probably the
- // right thing to use. There is a special case for multiline strings,
- // identified by a default_value expression that contains a newline.
- if (this->has_default_value_expression()) {
- CdlProperty_Expression expr = this->get_default_value_expression();
- CdlEvalContext context(0, this, expr);
- CdlSimpleValue val;
- try {
- expr->eval(context, val);
- std::string tmp = val.get_value();
- if (std::string::npos != tmp.find('\n')) {
- hint.value_widget = CdlValueWidget_MultilineString;
- }
- } catch(...) {
- // Not a lot that can be done here, unfortunately
- }
- }
- }
+
+ // Default to a simple entry box.
+ hint.value_widget = CdlValueWidget_EntryBox;
+
+ // If there is a legal_values list, this will normally indicate
+ // which widget should be used.
+ if (this->has_legal_values()) {
+ // The legal_values expression needs to be evaluated and examined.
+ // If the result is a simple numerical range then all we need to
+ // figure out is whether to default to decimal, hex, octal or double.
+ // Otherwise if the result is a simple list and all of the entries
+ // are numerical, that is sufficient information. If a list with
+ // non-numerical entries that is fine as well. Anything more complicated
+ // needs to revert to an entry box.
+ CdlProperty_ListExpression lexpr = this->get_legal_values();
+ CdlEvalContext context(0, this, lexpr);
+ CdlListValue val;
+
+ try {
+ lexpr->eval(context, val);
+ const std::vector<CdlSimpleValue>& table = val.get_table();
+ const std::vector<std::pair<cdl_int, cdl_int> >& int_ranges = val.get_integer_ranges();
+ const std::vector<std::pair<double, double> >& double_ranges = val.get_double_ranges();
+
+ if ((0 == table.size()) && (0 == int_ranges.size()) && (1 == double_ranges.size())) {
+
+ // A straightforward range of double precision numbers
+ hint.value_widget = CdlValueWidget_DoubleRange;
+
+ } else if ((0 == table.size()) && (1 == int_ranges.size()) && (0 == double_ranges.size())) {
+
+ // Bummer. The formatting information has been lost.
+ // To fix this the two sets of ranges should be collapsed into pairs of
+ // CdlSimpleValue's.
+ hint.value_widget = CdlValueWidget_DecimalRange;
+
+ } else if ((1 <= table.size() && (0 == int_ranges.size()) && (0 == double_ranges.size()))) {
+
+ // If all of the values are numerical, then we have a numeric set.
+ // Otherwise we have a string set.
+ bool all_numeric = true;
+ std::vector<CdlSimpleValue>::const_iterator tab_i;
+ for (tab_i = table.begin(); (tab_i != table.end()) && all_numeric; tab_i++) {
+ if (!tab_i->has_double_value() && !tab_i->has_integer_value()) {
+ all_numeric = false;
+ }
+ }
+ if (all_numeric) {
+ hint.value_widget = CdlValueWidget_NumericSet;
+ } else {
+ hint.value_widget = CdlValueWidget_StringSet;
+ }
+
+ } else {
+ // The list expression is a complex combination. Leave it as an entry box.
+ // In some cases it would be possible to do better, for example
+ // legal_values -1 1 to 4 8 to 12
+ // Support for cases like these may get added in future, if such cases
+ // ever arise in practice.
+ }
+
+ } catch(...) {
+ // Not a lot that can be done here, unfortunately
+ }
+ } else {
+ // There is no legal_values property, so an entry box is probably the
+ // right thing to use. There is a special case for multiline strings,
+ // identified by a default_value expression that contains a newline.
+ if (this->has_default_value_expression()) {
+ CdlProperty_Expression expr = this->get_default_value_expression();
+ CdlEvalContext context(0, this, expr);
+ CdlSimpleValue val;
+ try {
+ expr->eval(context, val);
+ std::string tmp = val.get_value();
+ if (std::string::npos != tmp.find('\n')) {
+ hint.value_widget = CdlValueWidget_MultilineString;
+ }
+ } catch(...) {
+ // Not a lot that can be done here, unfortunately
+ }
+ }
+ }
}
-
+
CYG_REPORT_RETURN();
}
//}}}
-//{{{ CdlValuable get operations
+//{{{ CdlValuable get operations
// ----------------------------------------------------------------------------
const CdlValue&
}
//}}}
-//{{{ CdlValuable internal modify ops
+//{{{ CdlValuable internal modify ops
// ----------------------------------------------------------------------------
// There has been a change to either the value itself or to the
// values.
CdlValueFlavor flavor = value.get_flavor();
if ((CdlValueFlavor_BoolData != flavor) && (CdlValueFlavor_Data != flavor)) {
- CYG_REPORT_RETURN();
- return;
+ CYG_REPORT_RETURN();
+ return;
}
// If the valuable is not currently active and enabled then it
// does not matter whether or not the value is legal. Any old
// conflicts should be destroyed.
if (!(transaction->is_active(this) && this->is_enabled(transaction))) {
- transaction->clear_conflicts(this, &CdlConflict_IllegalValueBody::test);
- CYG_REPORT_RETURN();
- return;
+ transaction->clear_conflicts(this, &CdlConflict_IllegalValueBody::test);
+ CYG_REPORT_RETURN();
+ return;
}
// If there is a legal_values property, check membership.
if (this->has_property(CdlPropertyId_LegalValues)) {
- CdlProperty_ListExpression lexpr = dynamic_cast<CdlProperty_ListExpression>(get_property(CdlPropertyId_LegalValues));
- CYG_ASSERT_CLASSC(lexpr);
-
- CdlSimpleValue val = this->get_simple_value(transaction);
- CdlEvalContext context(transaction, this, lexpr);
- try {
- if (!lexpr->is_member(context, val)) {
- if (!transaction->has_conflict(this, lexpr, &CdlConflict_IllegalValueBody::test)) {
- CdlConflict_IllegalValueBody::make(transaction, this, lexpr);
- }
-
- } else {
- // Tne current value is legal. Get rid of any old conflicts.
- transaction->clear_conflicts(this, lexpr, &CdlConflict_IllegalValueBody::test);
- }
- } catch(CdlEvalException e) {
- // There should now be an EvalException conflict for this
- // node, so there is no point in having an IllegalValue conflict
- // as well.
- transaction->clear_conflicts(this, lexpr, &CdlConflict_IllegalValueBody::test);
- }
-
- // FIXME: add support for check_proc
+ CdlProperty_ListExpression lexpr = dynamic_cast<CdlProperty_ListExpression>(get_property(CdlPropertyId_LegalValues));
+ CYG_ASSERT_CLASSC(lexpr);
+
+ CdlSimpleValue val = this->get_simple_value(transaction);
+ CdlEvalContext context(transaction, this, lexpr);
+ try {
+ if (!lexpr->is_member(context, val)) {
+ if (!transaction->has_conflict(this, lexpr, &CdlConflict_IllegalValueBody::test)) {
+ CdlConflict_IllegalValueBody::make(transaction, this, lexpr);
+ }
+
+ } else {
+ // Tne current value is legal. Get rid of any old conflicts.
+ transaction->clear_conflicts(this, lexpr, &CdlConflict_IllegalValueBody::test);
+ }
+ } catch(CdlEvalException e) {
+ // There should now be an EvalException conflict for this
+ // node, so there is no point in having an IllegalValue conflict
+ // as well.
+ transaction->clear_conflicts(this, lexpr, &CdlConflict_IllegalValueBody::test);
+ }
+
+ // FIXME: add support for check_proc
}
-
+
CYG_REPORT_RETURN();
}
get_properties(CdlPropertyId_Requires, requires_properties);
for (prop_i = requires_properties.begin(); prop_i != requires_properties.end(); prop_i++) {
- CdlProperty_GoalExpression gexpr = dynamic_cast<CdlProperty_GoalExpression>(*prop_i);
- CYG_ASSERT_CLASSC(gexpr);
- this->check_requires(transaction, gexpr);
+ CdlProperty_GoalExpression gexpr = dynamic_cast<CdlProperty_GoalExpression>(*prop_i);
+ CYG_ASSERT_CLASSC(gexpr);
+ this->check_requires(transaction, gexpr);
}
CYG_REPORT_RETURN();
// If the valuable is not currently active and enabled then the "requires"
// properties are irrelevant, and any old conflicts should be destroyed.
if (!transaction->is_active(this) || !this->is_enabled(transaction)) {
- transaction->clear_conflicts(this, gexpr, &CdlConflict_RequiresBody::test);
- CYG_REPORT_RETURN();
- return;
+ transaction->clear_conflicts(this, gexpr, &CdlConflict_RequiresBody::test);
+ CYG_REPORT_RETURN();
+ return;
}
// What is the current value of the goal expression?
try {
- CdlEvalContext context(transaction, this, gexpr);
- if (gexpr->eval(context)) {
- // The goal is satisfied.
- transaction->clear_conflicts(this, gexpr, &CdlConflict_RequiresBody::test);
- } else {
- // The goal is not satisfied. Make sure there is a conflict object.
- if (!transaction->has_conflict(this, gexpr, &CdlConflict_RequiresBody::test)) {
- CdlConflict_RequiresBody::make(transaction, this, gexpr);
- }
- }
+ CdlEvalContext context(transaction, this, gexpr);
+ if (gexpr->eval(context)) {
+ // The goal is satisfied.
+ transaction->clear_conflicts(this, gexpr, &CdlConflict_RequiresBody::test);
+ } else {
+ // The goal is not satisfied. Make sure there is a conflict object.
+ if (!transaction->has_conflict(this, gexpr, &CdlConflict_RequiresBody::test)) {
+ CdlConflict_RequiresBody::make(transaction, this, gexpr);
+ }
+ }
} catch(CdlEvalException e) {
- // There should now be an EvalException conflict associated with this node,
- // having a requires conflict as well serves no purpose
- transaction->clear_conflicts(this, gexpr, &CdlConflict_RequiresBody::test);
+ // There should now be an EvalException conflict associated with this node,
+ // having a requires conflict as well serves no purpose
+ transaction->clear_conflicts(this, gexpr, &CdlConflict_RequiresBody::test);
}
-
+
CYG_REPORT_RETURN();
}
CYG_PRECONDITION_CLASSC(transaction);
if ((CdlUpdate_ValueChange == update) || (CdlUpdate_ActiveChange == update)) {
- this->check_value(transaction);
- this->check_requires(transaction);
+ this->check_value(transaction);
+ this->check_requires(transaction);
}
-
+
CYG_REPORT_RETURN();
}
bool result = true;
if (!this->CdlNodeBody::test_active(transaction)) {
- result = false;
+ result = false;
}
if (result) {
- std::vector<CdlProperty> active_if_properties;
- std::vector<CdlProperty>::const_iterator prop_i;
-
- this->get_properties(CdlPropertyId_ActiveIf, active_if_properties);
- for (prop_i = active_if_properties.begin(); result && (prop_i != active_if_properties.end()); prop_i++) {
-
- CdlProperty_GoalExpression gexpr = dynamic_cast<CdlProperty_GoalExpression>(*prop_i);
- CYG_ASSERT_CLASSC(gexpr);
- CdlEvalContext context(transaction, this, gexpr);
- try {
- if (!gexpr->eval(context)) {
- result = false;
- }
- } catch(CdlEvalException e) {
- // Hmmm, an active_if property cannot be evaluated.
- // Tricky. If the node is inactive then its conflicts
- // are ignored, which would be a bad thing. For now
- // assume that the node is active, unless it was already
- // inactive for other reasons.
- }
- }
+ std::vector<CdlProperty> active_if_properties;
+ std::vector<CdlProperty>::const_iterator prop_i;
+
+ this->get_properties(CdlPropertyId_ActiveIf, active_if_properties);
+ for (prop_i = active_if_properties.begin(); result && (prop_i != active_if_properties.end()); prop_i++) {
+
+ CdlProperty_GoalExpression gexpr = dynamic_cast<CdlProperty_GoalExpression>(*prop_i);
+ CYG_ASSERT_CLASSC(gexpr);
+ CdlEvalContext context(transaction, this, gexpr);
+ try {
+ if (!gexpr->eval(context)) {
+ result = false;
+ }
+ } catch(CdlEvalException e) {
+ // Hmmm, an active_if property cannot be evaluated.
+ // Tricky. If the node is inactive then its conflicts
+ // are ignored, which would be a bad thing. For now
+ // assume that the node is active, unless it was already
+ // inactive for other reasons.
+ }
+ }
}
CYG_REPORT_RETVAL(result);
}
//}}}
-//{{{ CdlValuable modify operations
+//{{{ CdlValuable modify operations
// ----------------------------------------------------------------------------
// Start with the non-transaction versions. These allocate a new transaction,
CYG_REPORT_FUNCNAME("CdlValuable::set_source (no transaction)");
CYG_REPORT_FUNCARG2XV(this, source);
CYG_PRECONDITION_THISC();
-
+
CdlTransaction transaction = CdlTransactionBody::make(get_toplevel());
this->set_source(transaction, source);
transaction->body();
CYG_REPORT_FUNCNAME("CdlValuable::set_enabled (no transaction)");
CYG_REPORT_FUNCARG3XV(this, val, source);
CYG_PRECONDITION_THISC();
-
+
CdlTransaction transaction = CdlTransactionBody::make(get_toplevel());
this->set_enabled(transaction, val, source);
transaction->body();
CYG_ASSERTC((source == CdlValueSource_Default) || !has_property(CdlPropertyId_Calculated));
CYG_PRECONDITION_THISC();
CYG_PRECONDITION_CLASSC(transaction);
-
+
const CdlValue& old_value = transaction->get_whole_value(this);
CdlValue new_value = old_value;
new_value.set_source(source);
CYG_REPORT_FUNCARG3XV(this, transaction, source);
CYG_PRECONDITION_THISC();
CYG_PRECONDITION_CLASSC(transaction);
-
+
const CdlValue& old_value = transaction->get_whole_value(this);
CdlValue new_value = old_value;
new_value.invalidate_source(source);
transaction->set_whole_value(this, old_value, new_value);
-
+
CYG_REPORT_RETURN();
}
CdlValue new_value = old_value;
new_value.set_enabled(enabled_arg, source);
transaction->set_whole_value(this, old_value, new_value);
-
+
CYG_REPORT_RETURN();
}
CYG_ASSERTC((source == CdlValueSource_Default) || !has_property(CdlPropertyId_Calculated));
CYG_PRECONDITION_THISC();
CYG_PRECONDITION_CLASSC(transaction);
-
+
const CdlValue& old_value = transaction->get_whole_value(this);
CdlValue new_value = old_value;
new_value.set_value(val, source);
transaction->set_whole_value(this, old_value, new_value);
-
+
CYG_REPORT_RETURN();
}
void
CdlValuableBody::set_enabled_and_value(CdlTransaction transaction, bool enabled_arg, CdlSimpleValue& val,
- CdlValueSource source)
+ CdlValueSource source)
{
CYG_REPORT_FUNCNAME("CdlValuable::set_enabled");
CYG_REPORT_FUNCARG3XV(this, transaction, source);
CYG_ASSERTC((source == CdlValueSource_Default) || !has_property(CdlPropertyId_Calculated));
CYG_PRECONDITION_THISC();
CYG_PRECONDITION_CLASSC(transaction);
-
+
const CdlValue& old_value = transaction->get_whole_value(this);
CdlValue new_value = old_value;
new_value.set_enabled_and_value(enabled_arg, val, source);
transaction->set_whole_value(this, old_value, new_value);
-
+
CYG_REPORT_RETURN();
}
CYG_ASSERTC((source == CdlValueSource_Default) || !has_property(CdlPropertyId_Calculated));
CYG_PRECONDITION_THISC();
CYG_PRECONDITION_CLASSC(transaction);
-
+
const CdlValue& old_value = transaction->get_whole_value(this);
CdlValue new_value = old_value;
new_value.set(val, source);
transaction->set_whole_value(this, old_value, new_value);
-
+
CYG_REPORT_RETURN();
}
CYG_REPORT_FUNCARG2XV(this, transaction);
CYG_PRECONDITION_THISC();
CYG_PRECONDITION_CLASSC(transaction);
-
+
const CdlValue& old_value = transaction->get_whole_value(this);
CdlValue new_value = val;
transaction->set_whole_value(this, old_value, new_value);
}
//}}}
-//{{{ CdlValuable basics
+//{{{ CdlValuable basics
// ----------------------------------------------------------------------------
// The CdlValuable class implements the concept of CDL objects that take
cdlvaluablebody_cookie = CdlValuableBody_Magic;
CYGDBG_MEMLEAK_CONSTRUCTOR();
-
+
CYG_POSTCONDITION_THISC();
CYG_REPORT_RETURN();
}
cdlvaluablebody_cookie = CdlValuableBody_Invalid;
CYGDBG_MEMLEAK_DESTRUCTOR();
-
+
CYG_REPORT_RETURN();
}
CdlValuableBody::check_this(cyg_assert_class_zeal zeal) const
{
if (CdlValuableBody_Magic != cdlvaluablebody_cookie) {
- return false;
+ return false;
}
CYGDBG_MEMLEAK_CHECKTHIS();
if (has_property(CdlPropertyId_Calculated) && (CdlValueSource_Default != value.get_source())) {
- CYG_FAIL("Calculated valuables can only have a default value.");
- return false;
+ CYG_FAIL("Calculated valuables can only have a default value.");
+ return false;
}
-
+
return CdlNodeBody::check_this(zeal) && value.check_this(zeal);
}
//}}}
-//{{{ CdlValuable parsing support
+//{{{ CdlValuable parsing support
// ----------------------------------------------------------------------------
// Parsing support. Adding the appropriate parsers is straightforward.
static CdlInterpreterCommandEntry commands[] =
{
- CdlInterpreterCommandEntry("active_if", &parse_active_if ),
- CdlInterpreterCommandEntry("calculated", &parse_calculated ),
- CdlInterpreterCommandEntry("check_proc", &parse_check_proc ),
- CdlInterpreterCommandEntry("default_value", &parse_default_value),
- CdlInterpreterCommandEntry("dialog", &parse_dialog ),
- CdlInterpreterCommandEntry("entry_proc", &parse_entry_proc ),
- CdlInterpreterCommandEntry("flavor", &parse_flavor ),
- CdlInterpreterCommandEntry("group", &parse_group ),
- CdlInterpreterCommandEntry("implements", &parse_implements ),
- CdlInterpreterCommandEntry("legal_values", &parse_legal_values ),
- CdlInterpreterCommandEntry("requires", &parse_requires ),
- CdlInterpreterCommandEntry("wizard", &parse_wizard ),
- CdlInterpreterCommandEntry("", 0 )
+ CdlInterpreterCommandEntry("active_if", &parse_active_if ),
+ CdlInterpreterCommandEntry("calculated", &parse_calculated ),
+ CdlInterpreterCommandEntry("check_proc", &parse_check_proc ),
+ CdlInterpreterCommandEntry("default_value", &parse_default_value),
+ CdlInterpreterCommandEntry("dialog", &parse_dialog ),
+ CdlInterpreterCommandEntry("entry_proc", &parse_entry_proc ),
+ CdlInterpreterCommandEntry("flavor", &parse_flavor ),
+ CdlInterpreterCommandEntry("group", &parse_group ),
+ CdlInterpreterCommandEntry("implements", &parse_implements ),
+ CdlInterpreterCommandEntry("legal_values", &parse_legal_values ),
+ CdlInterpreterCommandEntry("requires", &parse_requires ),
+ CdlInterpreterCommandEntry("wizard", &parse_wizard ),
+ CdlInterpreterCommandEntry("", 0 )
};
for (int i = 0; commands[i].command != 0; i++) {
- std::vector<CdlInterpreterCommandEntry>::const_iterator j;
- for (j = parsers.begin(); j != parsers.end(); j++) {
- if (commands[i].name == j->name) {
- if (commands[i].command != j->command) {
- CYG_FAIL("Property names are being re-used");
- }
- break;
- }
- }
- if (j == parsers.end()) {
- parsers.push_back(commands[i]);
- }
+ std::vector<CdlInterpreterCommandEntry>::const_iterator j;
+ for (j = parsers.begin(); j != parsers.end(); j++) {
+ if (commands[i].name == j->name) {
+ if (commands[i].command != j->command) {
+ CYG_FAIL("Property names are being re-used");
+ }
+ break;
+ }
+ }
+ if (j == parsers.end()) {
+ parsers.push_back(commands[i]);
+ }
}
CdlNodeBody::add_property_parsers(parsers);
-
+
CYG_REPORT_RETURN();
}
// This could prove useful if there are a sensible number
// of library check_proc's.
if (count_properties(CdlPropertyId_Flavor) > 1) {
- CdlParse::report_error(interp, "", "There should be at most one flavor property.");
+ CdlParse::report_error(interp, "", "There should be at most one flavor property.");
}
if (count_properties(CdlPropertyId_EntryProc) > 1) {
- CdlParse::report_error(interp, "", "There should be at most one entry_proc property.");
+ CdlParse::report_error(interp, "", "There should be at most one entry_proc property.");
}
if (count_properties(CdlPropertyId_CheckProc) > 1) {
- CdlParse::report_error(interp, "", "There should be at most one check_proc property.");
+ CdlParse::report_error(interp, "", "There should be at most one check_proc property.");
}
if (count_properties(CdlPropertyId_DefaultValue) > 1) {
- CdlParse::report_error(interp, "", "There should be at most one default_value property.");
+ CdlParse::report_error(interp, "", "There should be at most one default_value property.");
}
if (count_properties(CdlPropertyId_LegalValues) > 1) {
- CdlParse::report_error(interp, "", "There should be at most one legal_values property.");
+ CdlParse::report_error(interp, "", "There should be at most one legal_values property.");
}
if (count_properties(CdlPropertyId_Dialog) > 1) {
- CdlParse::report_error(interp, "", "There should be at most one dialog property.");
+ CdlParse::report_error(interp, "", "There should be at most one dialog property.");
}
if (count_properties(CdlPropertyId_Wizard) > 1) {
- CdlParse::report_error(interp, "", "There should be at most one wizard property.");
+ CdlParse::report_error(interp, "", "There should be at most one wizard property.");
}
if (count_properties(CdlPropertyId_Calculated) > 1) {
- CdlParse::report_error(interp, "", "There should be at most one calculated property.");
+ CdlParse::report_error(interp, "", "There should be at most one calculated property.");
}
// If there is a flavor property, update the flavor in the base class
if (has_property(CdlPropertyId_Flavor)) {
- CdlProperty_String flavor_property = dynamic_cast<CdlProperty_String>(get_property(CdlPropertyId_Flavor));
- CYG_ASSERTC(0 != flavor_property);
-
- std::string flavor_string = flavor_property->get_string();
- CdlValueFlavor flavor;
- // The property parsing code should have caught any problems already.
- if (!Cdl::string_to_flavor(flavor_string, flavor)) {
- CdlParse::report_error(interp, "", "Invalid flavor " + flavor_string);
- } else {
- value.set_flavor(flavor);
- }
-
- // If the flavor is "none" then the entity is not modifiable,
- // and most of the properties do not make sense. However this
- // is not enforced at parse-time: temporarily switching to
- // flavor none may make sense during debugging.
- // FIXME: no longer correct
+ CdlProperty_String flavor_property = dynamic_cast<CdlProperty_String>(get_property(CdlPropertyId_Flavor));
+ CYG_ASSERTC(0 != flavor_property);
+
+ std::string flavor_string = flavor_property->get_string();
+ CdlValueFlavor flavor;
+ // The property parsing code should have caught any problems already.
+ if (!Cdl::string_to_flavor(flavor_string, flavor)) {
+ CdlParse::report_error(interp, "", "Invalid flavor " + flavor_string);
+ } else {
+ value.set_flavor(flavor);
+ }
+
+ // If the flavor is "none" then the entity is not modifiable,
+ // and most of the properties do not make sense. However this
+ // is not enforced at parse-time: temporarily switching to
+ // flavor none may make sense during debugging.
+ // FIXME: no longer correct
}
// For boolean entities legal_values does not make much sense.
// check_proc is allowed, this can be used to check programatically
// that the current value is legal.
if (CdlValueFlavor_Bool == get_flavor()) {
- if (has_property(CdlPropertyId_LegalValues)) {
- CdlParse::report_error(interp, "", "The \"legal_values\" property is not applicable to boolean entities.");
- }
+ if (has_property(CdlPropertyId_LegalValues)) {
+ CdlParse::report_error(interp, "", "The \"legal_values\" property is not applicable to boolean entities.");
+ }
}
// default_value and calculated are mutually exclusive
if (has_property(CdlPropertyId_Calculated) && has_property(CdlPropertyId_DefaultValue)) {
- CdlParse::report_error(interp, "", "The properties \"default_value\" and \"calculated\" cannot be used together.");
+ CdlParse::report_error(interp, "", "The properties \"default_value\" and \"calculated\" cannot be used together.");
}
#if 0
// a text entry widget will be used and an entry_proc may well be
// applicable.
if (has_property(CdlPropertyId_Dialog) && has_property(CdlPropertyId_EntryProc)) {
- CdlParse::report_error(interp, "", "The properties \"dialog\" and \"entry_proc\" cannot be used together.");
+ CdlParse::report_error(interp, "", "The properties \"dialog\" and \"entry_proc\" cannot be used together.");
}
-#endif
+#endif
// All of the expressions may be invalid because of unresolved references,
- // ditto for implements and for dialog.
-
+ // ditto for implements and for dialog.
+
CdlNodeBody::check_properties(interp);
-
+
CYG_REPORT_RETURN();
}
//}}}
-//{{{ CdlValuable persistence support
+//{{{ CdlValuable persistence support
// ----------------------------------------------------------------------------
void
bool result = false;
if (this->is_modifiable()) {
- if (this->has_source(CdlValueSource_User) ||
- this->has_source(CdlValueSource_Wizard) ||
- this->has_source(CdlValueSource_Inferred)) {
+ if (this->has_source(CdlValueSource_User) ||
+ this->has_source(CdlValueSource_Wizard) ||
+ this->has_source(CdlValueSource_Inferred)) {
- result = true;
- }
+ result = true;
+ }
}
-
+
CYG_REPORT_RETVAL(result);
return result;
}
CYG_REPORT_FUNCNAME("value_to_string");
std::string data = "";
-
+
switch(valuable->get_flavor()) {
case CdlValueFlavor_Bool :
- data += (valuable->is_enabled(source) ? one : zero);
- break;
+ data += (valuable->is_enabled(source) ? one : zero);
+ break;
case CdlValueFlavor_BoolData :
- data += (valuable->is_enabled(source) ? one : zero) + " " +
- CdlInterpreterBody::quote(valuable->get_value(source));
- break;
+ data += (valuable->is_enabled(source) ? one : zero) + " " +
+ CdlInterpreterBody::quote(valuable->get_value(source));
+ break;
case CdlValueFlavor_Data:
- data += CdlInterpreterBody::quote(valuable->get_value(source));
- break;
+ data += CdlInterpreterBody::quote(valuable->get_value(source));
+ break;
default:
- CYG_FAIL("Invalid value flavor detected");
- break;
+ CYG_FAIL("Invalid value flavor detected");
+ break;
}
return data;
}
CYG_REPORT_FUNCARG1XV(valuable);
CdlValueSource expected_source = CdlValueSource_Default;
-
+
if (valuable->has_source(CdlValueSource_User)) {
- expected_source = CdlValueSource_User;
+ expected_source = CdlValueSource_User;
} else if (valuable->has_source(CdlValueSource_Wizard)) {
- expected_source = CdlValueSource_Wizard;
+ expected_source = CdlValueSource_Wizard;
} else if (valuable->has_source(CdlValueSource_Inferred)) {
- expected_source = CdlValueSource_Inferred;
+ expected_source = CdlValueSource_Inferred;
}
CYG_REPORT_RETVAL((int) expected_source);
std::string data = "";
CdlSimpleValue simple_value;
std::vector<CdlReference>::const_iterator ref_i;
-
+
for (ref_i = expr->references.begin(); ref_i != expr->references.end(); ref_i++) {
- const std::string& refname = ref_i->get_destination_name();
- CdlNode refnode = ref_i->get_destination();
- CdlValuable refvaluable = 0;
- if (0 != refnode) {
- refvaluable = dynamic_cast<CdlValuable>(refnode);
- }
- data += refname + " ";
- if (0 == refvaluable) {
- data += "(unknown) == 0";
- } else {
- CdlEvalContext context(0, refvaluable, property);
- CdlSimpleValue::eval_valuable(context, refvaluable, simple_value);
- data += "== " + CdlInterpreterBody::quote(simple_value.get_value());
- }
- data += '\n';
+ const std::string& refname = ref_i->get_destination_name();
+ CdlNode refnode = ref_i->get_destination();
+ CdlValuable refvaluable = 0;
+ if (0 != refnode) {
+ refvaluable = dynamic_cast<CdlValuable>(refnode);
+ }
+ data += refname + " ";
+ if (0 == refvaluable) {
+ data += "(unknown) == 0";
+ } else {
+ CdlEvalContext context(0, refvaluable, property);
+ CdlSimpleValue::eval_valuable(context, refvaluable, simple_value);
+ data += "== " + CdlInterpreterBody::quote(simple_value.get_value());
+ }
+ data += '\n';
}
-
+
CYG_REPORT_RETURN();
return data;
}
// ----------------------------------------------------------------------------
void
-CdlValuableBody::save(CdlInterpreter interp, Tcl_Channel chan, int indentation, bool modifiable, bool minimal)
+CdlValuableBody::_save(CdlInterpreter interp, Tcl_Channel chan, int indentation, bool modifiable, bool minimal)
{
CYG_REPORT_FUNCNAME("CdlValuable::save");
CYG_REPORT_FUNCARG5XV(this, interp, chan, indentation, minimal);
// but the alternative is an awful lot of "if (minimal)" tests
// in the main code.
if (minimal) {
-
- if (modifiable) {
- if (this->has_source(CdlValueSource_User)) {
- data += indent_string + "user_value " + value_to_string(this, CdlValueSource_User) + "\n";
- }
- if (this->has_source(CdlValueSource_Wizard)) {
- data += indent_string + "wizard_value " + value_to_string(this, CdlValueSource_Wizard) + "\n";
- }
- if (this->has_source(CdlValueSource_Inferred)) {
- data += indent_string + "inferred_value " + value_to_string(this, CdlValueSource_Inferred) + "\n";
- }
- CdlValueSource expected_source = get_expected_source(this);
- if (expected_source != this->get_source()) {
- std::string current_source_string;
- if (!Cdl::source_to_string(this->get_source(), current_source_string)) {
- CYG_FAIL("Invalid current value source detected");
- }
- data += indent_string + "value_source " + current_source_string + "\n";
- }
- }
-
+ if (modifiable) {
+ if (this->has_source(CdlValueSource_User)) {
+ data += indent_string + "user_value " + value_to_string(this, CdlValueSource_User) + "\n";
+ }
+ if (this->has_source(CdlValueSource_Wizard)) {
+ data += indent_string + "wizard_value " + value_to_string(this, CdlValueSource_Wizard) + "\n";
+ }
+ if (this->has_source(CdlValueSource_Inferred)) {
+ data += indent_string + "inferred_value " + value_to_string(this, CdlValueSource_Inferred) + "\n";
+ }
+ CdlValueSource expected_source = get_expected_source(this);
+ if (expected_source != this->get_source()) {
+ std::string current_source_string;
+ if (!Cdl::source_to_string(this->get_source(), current_source_string)) {
+ CYG_FAIL("Invalid current value source detected");
+ }
+ data += indent_string + "value_source " + current_source_string + "\n";
+ }
+ }
} else {
-
- // Right at the start, indicate whether or not this property is active.
- if (!this->is_active()) {
- data += indent_string + "# This option is not active\n";
- // If the entity is inactive because the parent is inactive or disabled,
- // say so here. This is in addition to any unsatisfied active_if
- // conditions, which will be reported below.
- CdlContainer parent = this->get_parent();
- if (!parent->is_active()) {
- data += indent_string + "# The parent " + parent->get_name() + " is not active\n";
- }
- CdlValuable tmp = dynamic_cast<CdlValuable>(parent);
- if ((0 != tmp) && !tmp->is_enabled()) {
- data += indent_string + "# The parent " + parent->get_name() + " is disabled\n";
- }
- }
- if (this->has_active_if_conditions()) {
- std::vector<CdlProperty_GoalExpression> active_if_conditions;
- this->get_active_if_conditions(active_if_conditions);
- std::vector<CdlProperty_GoalExpression>::const_iterator expr_i;
- for (expr_i = active_if_conditions.begin(); expr_i != active_if_conditions.end(); expr_i++) {
- data += indent_string + "# ActiveIf constraint: " +
- CdlInterpreterBody::extend_comment((*expr_i)->get_original_string(), indentation, 4) +
- '\n';
-
- CdlExpression expr = (*expr_i)->get_expression();
- data += CdlInterpreterBody::multiline_comment(follow_expr_references(*expr_i, expr), indentation, 4);
- CdlEvalContext context(0, this, *expr_i);
- bool active_if_value = false;
- try {
- active_if_value = (*expr_i)->eval(context);
- } catch(CdlEvalException e) {
- active_if_value = false;
- } catch(std::bad_alloc) {
- throw;
- }
- data += indent_string + "# --> " + (active_if_value ? one : zero) + "\n";
- }
- }
-
- // If there has been any information related to the active status,
- // add a blank line before we start worrying about values.
- if (0 < data.size()) {
- data += '\n';
- }
-
- if (CdlValueFlavor_None == this->get_flavor()) {
- data += indent_string + "# There is no associated value.\n";
- } else if (this->has_property(CdlPropertyId_Calculated)) {
- CdlProperty_Expression expr = this->get_calculated_expression();
- data += indent_string + "# Calculated value: " +
- CdlInterpreterBody::extend_comment(expr->get_original_string(), indentation, 4) + '\n';
- data += CdlInterpreterBody::multiline_comment(follow_expr_references(expr, expr), indentation, 4);
- } else if (!modifiable) {
- data += indent_string + "# This value cannot be modified here.\n";
- }
-
- // Output the flavor. This clutters up the savefile a bit.
- // However it is necessary so that the user can distinguish
- // between bool, booldata and data items
- switch(this->get_flavor()) {
- case CdlValueFlavor_Bool:
- data += indent_string + "# Flavor: bool\n";
- break;
- case CdlValueFlavor_BoolData:
- data += indent_string + "# Flavor: booldata\n";
- break;
- case CdlValueFlavor_Data:
- data += indent_string + "# Flavor: data\n";
- break;
- default:
- break;
- }
-
- // If the value is not modifiable, just list the current value.
- // This is not in a form that allows users to change it easily.
- if (!modifiable) {
- switch(this->get_flavor()) {
- case CdlValueFlavor_None :
- break;
- case CdlValueFlavor_Bool :
- data += indent_string + "# Current value: " + (this->is_enabled() ? one : zero) + '\n';
- break;
- case CdlValueFlavor_BoolData :
- data += indent_string + "# Current value: " + (this->is_enabled() ? one : zero) + " " +
- CdlInterpreterBody::extend_comment(this->get_value(), indentation, 4) + '\n';
- break;
- case CdlValueFlavor_Data :
- data += indent_string + "# Current_value: " +
- CdlInterpreterBody::extend_comment(this->get_value(), indentation, 4) + '\n';
- break;
- default:
- break;
- }
-
- } else if (CdlValueFlavor_None != this->get_flavor()) {
-
- // If there is a user value, output it. Otherwise output
- // a comment that allows users to edit the user value conveniently.
- // It is assumed that the user will want a value similar to the
- // default one, so that is provided as the starting point
- if (this->has_source(CdlValueSource_User)) {
- data += indent_string + "user_value " + value_to_string(this, CdlValueSource_User) + "\n";
- } else {
- data += indent_string + "# No user value, uncomment the following line to provide one.\n" +
- indent_string + "# user_value " +
- CdlInterpreterBody::extend_comment(value_to_string(this, CdlValueSource_Default), indentation, 0) + "\n";
- }
-
- // Output a wizard value iff there is one. There is little point
- // in letting users edit a wizard value, they should be running
- // the wizard itself.
- if (this->has_source(CdlValueSource_Wizard)) {
- data += indent_string + "# The wizard value should not be edited directly.\n" +
- indent_string + "# Instead the wizard should be run again if necessary.\n";
- data += indent_string + "wizard_value " + value_to_string(this, CdlValueSource_Wizard) + "\n";
- }
-
- // List the inferred value. This needs to be a command,
- if (this->has_source(CdlValueSource_Inferred)) {
- data += indent_string + "# The inferred value should not be edited directly.\n";
- data += indent_string + "inferred_value " + value_to_string(this, CdlValueSource_Inferred) + "\n";
- }
-
- // Output the value source iff it is unusual. If the current
- // source is the highest priority one then there is no point
- // in outputting a command, but a comment is usual. The value
- // source needs to come after wizard and inferred values
- std::string current_source_string;
- CdlValueSource expected_source = get_expected_source(this);
- CdlValueSource current_source = this->get_source();
- if (!Cdl::source_to_string(current_source, current_source_string)) {
- CYG_FAIL("Invalid current value source detected");
- }
- if (this->get_source() == expected_source) {
- data += indent_string + "# value_source " + current_source_string + "\n";
- } else {
- data += indent_string + "value_source " + current_source_string + "\n";
- }
-
- // Always output the default value as a comment.
- data += indent_string + "# Default value: ";
-
- // If there is no default_value expression or if the expression involves
- // only constants, just output the current default value. Otherwise
- // output both the expression and the value
- CdlProperty prop = this->get_property(CdlPropertyId_DefaultValue);
- CdlProperty_Expression expr = dynamic_cast<CdlProperty_Expression>(prop);
- if ((0 == expr) || (0 == expr->references.size())) {
- // There is no default_value expression, so just output the current value
- data += CdlInterpreterBody::extend_comment(value_to_string(this, CdlValueSource_Default), indentation, 4)
- + "\n";
- } else {
- data += CdlInterpreterBody::extend_comment(expr->get_original_string(), indentation, 4) + "\n";
- data += CdlInterpreterBody::multiline_comment(follow_expr_references(expr, expr), indentation, 4);
- data += indent_string + "# --> " +
- CdlInterpreterBody::extend_comment(value_to_string(this, CdlValueSource_Default), indentation, 4) + "\n";
- }
- }
-
- // If there is a legal_values property, add the details.
- if (this->has_property(CdlPropertyId_LegalValues)) {
- CdlProperty_ListExpression lexpr = this->get_legal_values();
- data += indent_string + "# Legal values: " +
- CdlInterpreterBody::extend_comment(lexpr->get_original_string(), indentation, 4) + '\n';
-
- std::vector<CdlExpression>::const_iterator expr_i;
- std::vector<std::pair<CdlExpression,CdlExpression> >::const_iterator ranges_i;
- for (expr_i = lexpr->data.begin(); expr_i != lexpr->data.end(); expr_i++) {
- data += CdlInterpreterBody::multiline_comment(follow_expr_references(lexpr, *expr_i), indentation, 4);
- }
- for (ranges_i = lexpr->ranges.begin(); ranges_i != lexpr->ranges.end(); ranges_i++) {
- data += CdlInterpreterBody::multiline_comment(follow_expr_references(lexpr, ranges_i->first), indentation, 4);
- data += CdlInterpreterBody::multiline_comment(follow_expr_references(lexpr, ranges_i->second), indentation, 4);
- }
- }
-
- // If there is a check_proc property, mention this.
- if (this->has_property(CdlPropertyId_CheckProc)) {
- data += indent_string + "# There is a check_proc routine that will check the value.\n";
- }
-
- // Output all requires properties
- if (this->has_property(CdlPropertyId_Requires)) {
- std::vector<CdlProperty_GoalExpression> requires_goals;
- this->get_requires_goals(requires_goals);
- std::vector<CdlProperty_GoalExpression>::const_iterator expr_i;
- for (expr_i = requires_goals.begin(); expr_i != requires_goals.end(); expr_i++) {
- data += indent_string + "# Requires: " +
- CdlInterpreterBody::extend_comment((*expr_i)->get_original_string(), indentation, 4) + "\n";
-
- CdlExpression expr = (*expr_i)->get_expression();
- data += CdlInterpreterBody::multiline_comment(follow_expr_references(*expr_i, expr), indentation, 4);
- CdlEvalContext context(0, this, *expr_i);
- bool active_if_value = false;
- try {
- active_if_value = (*expr_i)->eval(context);
- } catch(CdlEvalException e) {
- active_if_value = false;
- } catch(std::bad_alloc) {
- throw;
- }
- data += indent_string + "# --> " + (active_if_value ? one : zero) + "\n";
- }
- }
-
- // Output all dependencies that other entities may have on this one.
- const std::vector<CdlReferrer>& referrers = this->get_referrers();
- if (0 != referrers.size()) {
- data += '\n' + indent_string + "# The following properties are affected by this value\n";
- std::vector<CdlReferrer>::const_iterator ref_i;
- for (ref_i = referrers.begin(); ref_i != referrers.end(); ref_i++) {
-
- CdlNode source = ref_i->get_source();
- CdlProperty source_prop = ref_i->get_source_property();
- std::string prop_id = source_prop->get_property_name();
-
- if ((prop_id == CdlPropertyId_ActiveIf) ||
- (prop_id == CdlPropertyId_Calculated) ||
- (prop_id == CdlPropertyId_DefaultValue) ||
- (prop_id == CdlPropertyId_LegalValues) ||
- (prop_id == CdlPropertyId_Requires)) {
-
- data += indent_string + "# " + source->get_class_name() + " " + source->get_name() + "\n";
- data += indent_string + "# " + prop_id + ": ";
- if ((prop_id == CdlPropertyId_Calculated) || (prop_id == CdlPropertyId_DefaultValue)) {
- CdlProperty_Expression expr = dynamic_cast<CdlProperty_Expression>(source_prop);
- CYG_ASSERT_CLASSC(expr);
- data += CdlInterpreterBody::extend_comment(expr->get_original_string(), indentation, 4);
- } else if (prop_id == CdlPropertyId_LegalValues) {
- CdlProperty_ListExpression lexpr = dynamic_cast<CdlProperty_ListExpression>(source_prop);
- CYG_ASSERT_CLASSC(lexpr);
- data += CdlInterpreterBody::extend_comment(lexpr->get_original_string(), indentation, 4);
- } else if ((prop_id == CdlPropertyId_ActiveIf) || (prop_id == CdlPropertyId_Requires)) {
- CdlProperty_GoalExpression gexpr = dynamic_cast<CdlProperty_GoalExpression>(source_prop);
- CYG_ASSERT_CLASSC(gexpr);
- data += CdlInterpreterBody::extend_comment(gexpr->get_original_string(), indentation, 4);
- }
- data += '\n';
- }
- }
- }
+ // Right at the start, indicate whether or not this property is active.
+ if (!this->is_active()) {
+ data += indent_string + "# This option is not active\n";
+ // If the entity is inactive because the parent is inactive or disabled,
+ // say so here. This is in addition to any unsatisfied active_if
+ // conditions, which will be reported below.
+ CdlContainer parent = this->get_parent();
+ if (!parent->is_active()) {
+ data += indent_string + "# The parent " + parent->get_name() + " is not active\n";
+ }
+ CdlValuable tmp = dynamic_cast<CdlValuable>(parent);
+ if ((0 != tmp) && !tmp->is_enabled()) {
+ data += indent_string + "# The parent " + parent->get_name() + " is disabled\n";
+ }
+ }
+ if (this->has_active_if_conditions()) {
+ std::vector<CdlProperty_GoalExpression> active_if_conditions;
+ this->get_active_if_conditions(active_if_conditions);
+ std::vector<CdlProperty_GoalExpression>::const_iterator expr_i;
+ for (expr_i = active_if_conditions.begin(); expr_i != active_if_conditions.end(); expr_i++) {
+ data += indent_string + "# ActiveIf constraint: " +
+ CdlInterpreterBody::extend_comment((*expr_i)->get_original_string(), indentation, 4) +
+ '\n';
+
+ CdlExpression expr = (*expr_i)->get_expression();
+ data += CdlInterpreterBody::multiline_comment(follow_expr_references(*expr_i, expr), indentation, 4);
+ CdlEvalContext context(0, this, *expr_i);
+ bool active_if_value = false;
+ try {
+ active_if_value = (*expr_i)->eval(context);
+ } catch(CdlEvalException e) {
+ active_if_value = false;
+ } catch(std::bad_alloc) {
+ throw;
+ }
+ data += indent_string + "# --> " + (active_if_value ? one : zero) + "\n";
+ }
+ }
+
+ // If there has been any information related to the active status,
+ // add a blank line before we start worrying about values.
+ if (0 < data.size()) {
+ data += '\n';
+ }
+
+ if (CdlValueFlavor_None == this->get_flavor()) {
+ data += indent_string + "# There is no associated value.\n";
+ } else if (this->has_property(CdlPropertyId_Calculated)) {
+ CdlProperty_Expression expr = this->get_calculated_expression();
+ data += indent_string + "# Calculated value: " +
+ CdlInterpreterBody::extend_comment(expr->get_original_string(), indentation, 4) + '\n';
+ data += CdlInterpreterBody::multiline_comment(follow_expr_references(expr, expr), indentation, 4);
+ } else if (!modifiable) {
+ data += indent_string + "# This value cannot be modified here.\n";
+ }
+
+ // Output the flavor. This clutters up the savefile a bit.
+ // However it is necessary so that the user can distinguish
+ // between bool, booldata and data items
+ switch(this->get_flavor()) {
+ case CdlValueFlavor_Bool:
+ data += indent_string + "# Flavor: bool\n";
+ break;
+ case CdlValueFlavor_BoolData:
+ data += indent_string + "# Flavor: booldata\n";
+ break;
+ case CdlValueFlavor_Data:
+ data += indent_string + "# Flavor: data\n";
+ break;
+ default:
+ break;
+ }
+
+ // If the value is not modifiable, just list the current value.
+ // This is not in a form that allows users to change it easily.
+ if (!modifiable) {
+ switch(this->get_flavor()) {
+ case CdlValueFlavor_None :
+ break;
+ case CdlValueFlavor_Bool :
+ data += indent_string + "# Current value: " + (this->is_enabled() ? one : zero) + '\n';
+ break;
+ case CdlValueFlavor_BoolData :
+ data += indent_string + "# Current value: " + (this->is_enabled() ? one : zero) + " " +
+ CdlInterpreterBody::extend_comment(this->get_value(), indentation, 4) + '\n';
+ break;
+ case CdlValueFlavor_Data :
+ data += indent_string + "# Current_value: " +
+ CdlInterpreterBody::extend_comment(this->get_value(), indentation, 4) + '\n';
+ break;
+ default:
+ break;
+ }
+
+ } else if (CdlValueFlavor_None != this->get_flavor()) {
+
+ // If there is a user value, output it. Otherwise output
+ // a comment that allows users to edit the user value conveniently.
+ // It is assumed that the user will want a value similar to the
+ // default one, so that is provided as the starting point
+ if (this->has_source(CdlValueSource_User)) {
+ data += indent_string + "user_value " + value_to_string(this, CdlValueSource_User) + "\n";
+ } else {
+ data += indent_string + "# No user value, uncomment the following line to provide one.\n" +
+ indent_string + "# user_value " +
+ CdlInterpreterBody::extend_comment(value_to_string(this, CdlValueSource_Default), indentation, 0) + "\n";
+ }
+
+ // Output a wizard value iff there is one. There is little point
+ // in letting users edit a wizard value, they should be running
+ // the wizard itself.
+ if (this->has_source(CdlValueSource_Wizard)) {
+ data += indent_string + "# The wizard value should not be edited directly.\n" +
+ indent_string + "# Instead the wizard should be run again if necessary.\n";
+ data += indent_string + "wizard_value " + value_to_string(this, CdlValueSource_Wizard) + "\n";
+ }
+
+ // List the inferred value. This needs to be a command,
+ if (this->has_source(CdlValueSource_Inferred)) {
+ data += indent_string + "# The inferred value should not be edited directly.\n";
+ data += indent_string + "inferred_value " + value_to_string(this, CdlValueSource_Inferred) + "\n";
+ }
+
+ // Output the value source iff it is unusual. If the current
+ // source is the highest priority one then there is no point
+ // in outputting a command, but a comment is usual. The value
+ // source needs to come after wizard and inferred values
+ std::string current_source_string;
+ CdlValueSource expected_source = get_expected_source(this);
+ CdlValueSource current_source = this->get_source();
+ if (!Cdl::source_to_string(current_source, current_source_string)) {
+ CYG_FAIL("Invalid current value source detected");
+ }
+ if (this->get_source() == expected_source) {
+ data += indent_string + "# value_source " + current_source_string + "\n";
+ } else {
+ data += indent_string + "value_source " + current_source_string + "\n";
+ }
+
+ // Always output the default value as a comment.
+ data += indent_string + "# Default value: ";
+
+ // If there is no default_value expression or if the expression involves
+ // only constants, just output the current default value. Otherwise
+ // output both the expression and the value
+ CdlProperty prop = this->get_property(CdlPropertyId_DefaultValue);
+ CdlProperty_Expression expr = dynamic_cast<CdlProperty_Expression>(prop);
+ if ((0 == expr) || (0 == expr->references.size())) {
+ // There is no default_value expression, so just output the current value
+ data += CdlInterpreterBody::extend_comment(value_to_string(this, CdlValueSource_Default), indentation, 4)
+ + "\n";
+ } else {
+ data += CdlInterpreterBody::extend_comment(expr->get_original_string(), indentation, 4) + "\n";
+ data += CdlInterpreterBody::multiline_comment(follow_expr_references(expr, expr), indentation, 4);
+ data += indent_string + "# --> " +
+ CdlInterpreterBody::extend_comment(value_to_string(this, CdlValueSource_Default), indentation, 4) + "\n";
+ }
+ }
+
+ // If there is a legal_values property, add the details.
+ if (this->has_property(CdlPropertyId_LegalValues)) {
+ CdlProperty_ListExpression lexpr = this->get_legal_values();
+ data += indent_string + "# Legal values: " +
+ CdlInterpreterBody::extend_comment(lexpr->get_original_string(), indentation, 4) + '\n';
+
+ std::vector<CdlExpression>::const_iterator expr_i;
+ std::vector<std::pair<CdlExpression,CdlExpression> >::const_iterator ranges_i;
+ for (expr_i = lexpr->data.begin(); expr_i != lexpr->data.end(); expr_i++) {
+ data += CdlInterpreterBody::multiline_comment(follow_expr_references(lexpr, *expr_i), indentation, 4);
+ }
+ for (ranges_i = lexpr->ranges.begin(); ranges_i != lexpr->ranges.end(); ranges_i++) {
+ data += CdlInterpreterBody::multiline_comment(follow_expr_references(lexpr, ranges_i->first), indentation, 4);
+ data += CdlInterpreterBody::multiline_comment(follow_expr_references(lexpr, ranges_i->second), indentation, 4);
+ }
+ }
+
+ // If there is a check_proc property, mention this.
+ if (this->has_property(CdlPropertyId_CheckProc)) {
+ data += indent_string + "# There is a check_proc routine that will check the value.\n";
+ }
+
+ // Output all requires properties
+ if (this->has_property(CdlPropertyId_Requires)) {
+ std::vector<CdlProperty_GoalExpression> requires_goals;
+ this->get_requires_goals(requires_goals);
+ std::vector<CdlProperty_GoalExpression>::const_iterator expr_i;
+ for (expr_i = requires_goals.begin(); expr_i != requires_goals.end(); expr_i++) {
+ data += indent_string + "# Requires: " +
+ CdlInterpreterBody::extend_comment((*expr_i)->get_original_string(), indentation, 4) + "\n";
+
+ CdlExpression expr = (*expr_i)->get_expression();
+ data += CdlInterpreterBody::multiline_comment(follow_expr_references(*expr_i, expr), indentation, 4);
+ CdlEvalContext context(0, this, *expr_i);
+ bool active_if_value = false;
+ try {
+ active_if_value = (*expr_i)->eval(context);
+ } catch(CdlEvalException e) {
+ active_if_value = false;
+ } catch(std::bad_alloc) {
+ throw;
+ }
+ data += indent_string + "# --> " + (active_if_value ? one : zero) + "\n";
+ }
+ }
+
+ // Output all dependencies that other entities may have on this one.
+ const std::vector<CdlReferrer>& referrers = this->get_referrers();
+ if (0 != referrers.size()) {
+ data += '\n' + indent_string + "# The following properties are affected by this value\n";
+ std::vector<CdlReferrer>::const_iterator ref_i;
+ for (ref_i = referrers.begin(); ref_i != referrers.end(); ref_i++) {
+
+ CdlNode source = ref_i->get_source();
+ CdlProperty source_prop = ref_i->get_source_property();
+ std::string prop_id = source_prop->get_property_name();
+
+ if ((prop_id == CdlPropertyId_ActiveIf) ||
+ (prop_id == CdlPropertyId_Calculated) ||
+ (prop_id == CdlPropertyId_DefaultValue) ||
+ (prop_id == CdlPropertyId_LegalValues) ||
+ (prop_id == CdlPropertyId_Requires)) {
+
+ data += indent_string + "# " + source->get_class_name() + " " + source->get_name() + "\n";
+ data += indent_string + "# " + prop_id + ": ";
+ if ((prop_id == CdlPropertyId_Calculated) || (prop_id == CdlPropertyId_DefaultValue)) {
+ CdlProperty_Expression expr = dynamic_cast<CdlProperty_Expression>(source_prop);
+ CYG_ASSERT_CLASSC(expr);
+ data += CdlInterpreterBody::extend_comment(expr->get_original_string(), indentation, 4);
+ } else if (prop_id == CdlPropertyId_LegalValues) {
+ CdlProperty_ListExpression lexpr = dynamic_cast<CdlProperty_ListExpression>(source_prop);
+ CYG_ASSERT_CLASSC(lexpr);
+ data += CdlInterpreterBody::extend_comment(lexpr->get_original_string(), indentation, 4);
+ } else if ((prop_id == CdlPropertyId_ActiveIf) || (prop_id == CdlPropertyId_Requires)) {
+ CdlProperty_GoalExpression gexpr = dynamic_cast<CdlProperty_GoalExpression>(source_prop);
+ CYG_ASSERT_CLASSC(gexpr);
+ data += CdlInterpreterBody::extend_comment(gexpr->get_original_string(), indentation, 4);
+ }
+ data += '\n';
+ }
+ }
+ }
}
interp->write_data(chan, data);
-
+
CYG_REPORT_RETURN();
}
CdlValueSource source = CdlValueSource_Invalid;
if ((2 != argc) || !Cdl::string_to_source(argv[1], source) || !valuable->has_source(transaction, source)) {
- std::string msg = "Invalid value_source command for ";
- msg += valuable->get_class_name() + " " + valuable->get_name() + "\n";
- if (CdlValueSource_Invalid == source) {
- msg += "Expecting one argument, which should \"user\", \"wizard\", \"inferred\" or \"default\"";
- } else {
- msg += "The specified value source is not valid.";
- }
- CdlParse::report_error(interp, "", msg);
+ std::string msg = "Invalid value_source command for ";
+ msg += valuable->get_class_name() + " " + valuable->get_name() + "\n";
+ if (CdlValueSource_Invalid == source) {
+ msg += "Expecting one argument, which should \"user\", \"wizard\", \"inferred\" or \"default\"";
+ } else {
+ msg += "The specified value source is not valid.";
+ }
+ CdlParse::report_error(interp, "", msg);
} else {
- valuable->set_source(transaction, source);
+ valuable->set_source(transaction, source);
}
-
+
return TCL_OK;
}
bool warn = false;
std::string msg = "";
if (CdlValueFlavor_None == valuable->get_flavor()) {
- msg = "Options with flavor \"none\" cannot be modified.";
- error = true;
+ msg = "Options with flavor \"none\" cannot be modified.";
+ error = true;
} else if (!valuable->is_modifiable()) {
- msg = "This option is not user-modifiable.";
- error = true;
+ msg = "This option is not user-modifiable.";
+ error = true;
} else {
- switch(valuable->get_flavor()) {
- case CdlValueFlavor_Bool :
- if (2 != argc) {
- msg = "Invalid boolean value, expecting 0 or 1";
- error = true;
- } else {
- bool x;
- Cdl::string_to_bool(argv[1], x);
- valuable->set_enabled(transact, x, source);
- }
- break;
- case CdlValueFlavor_Data :
- if (2 != argc) {
- msg = "Invalid data value, expecting a single string";
- error = true;
- } else {
- valuable->set_value(transact, argv[1], source);
- }
- break;
- case CdlValueFlavor_BoolData:
- if (3 != argc) {
- msg = "Invalid booldata value, expecting a boolean followed by a string";
- error = true;
- } else {
- bool x;
- Cdl::string_to_bool(argv[1], x);
- valuable->set_enabled_and_value(transact, x, argv[2], source);
- }
- break;
- default:
- CYG_FAIL("Invalid value flavor detected");
- break;
- }
+ switch(valuable->get_flavor()) {
+ case CdlValueFlavor_Bool :
+ if (2 != argc) {
+ msg = "Invalid boolean value, expecting 0 or 1";
+ error = true;
+ } else {
+ bool x;
+ Cdl::string_to_bool(argv[1], x);
+ valuable->set_enabled(transact, x, source);
+ }
+ break;
+ case CdlValueFlavor_Data :
+ if (2 != argc) {
+ msg = "Invalid data value, expecting a single string";
+ error = true;
+ } else {
+ valuable->set_value(transact, argv[1], source);
+ }
+ break;
+ case CdlValueFlavor_BoolData:
+ if (3 != argc) {
+ msg = "Invalid booldata value, expecting a boolean followed by a string";
+ error = true;
+ } else {
+ bool x;
+ Cdl::string_to_bool(argv[1], x);
+ valuable->set_enabled_and_value(transact, x, argv[2], source);
+ }
+ break;
+ default:
+ CYG_FAIL("Invalid value flavor detected");
+ break;
+ }
}
if (error || warn) {
- msg = std::string("Invalid value command for ") + valuable->get_class_name() + " " + valuable->get_name() + "\n"
- + msg;
- if (error) {
- CdlParse::report_error(interp, "", msg);
- } else {
- CdlParse::report_warning(interp, "", msg);
- }
+ msg = std::string("Invalid value command for ") + valuable->get_class_name() + " " + valuable->get_name() + "\n"
+ + msg;
+ if (error) {
+ CdlParse::report_error(interp, "", msg);
+ } else {
+ CdlParse::report_warning(interp, "", msg);
+ }
}
return TCL_OK;