X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fprops%2Fcondition.cxx;h=2c8a3e9fbf1e39c46b683cf5aea35f770f8aec11;hb=aefe9bc11682f39b3936b9f01a0d37e9d6428078;hp=b1314af421c7c0bab77fa357ce71e6a442e98c69;hpb=d8a75897526f2ba2a030225a22dfbd93c7c39a7e;p=simgear.git diff --git a/simgear/props/condition.cxx b/simgear/props/condition.cxx index b1314af4..2c8a3e9f 100644 --- a/simgear/props/condition.cxx +++ b/simgear/props/condition.cxx @@ -8,19 +8,20 @@ // $Id$ #ifdef HAVE_CONFIG_H -# include +# include #endif -// #include STL_IOSTREAM +// #include -#include +#include #include "props.hxx" - #include "condition.hxx" -SG_USING_STD(istream); -SG_USING_STD(ostream); +#include + +using std::istream; +using std::ostream; @@ -66,7 +67,6 @@ SGNotCondition::SGNotCondition (SGCondition * condition) SGNotCondition::~SGNotCondition () { - delete _condition; } bool @@ -87,8 +87,6 @@ SGAndCondition::SGAndCondition () SGAndCondition::~SGAndCondition () { - for (unsigned int i = 0; i < _conditions.size(); i++) - delete _conditions[i]; } bool @@ -120,8 +118,6 @@ SGOrCondition::SGOrCondition () SGOrCondition::~SGOrCondition () { - for (unsigned int i = 0; i < _conditions.size(); i++) - delete _conditions[i]; } bool @@ -150,8 +146,9 @@ SGOrCondition::addCondition (SGCondition * condition) static int doComparison (const SGPropertyNode * left, const SGPropertyNode *right) { + using namespace simgear; switch (left->getType()) { - case SGPropertyNode::BOOL: { + case props::BOOL: { bool v1 = left->getBoolValue(); bool v2 = right->getBoolValue(); if (v1 < v2) @@ -162,7 +159,7 @@ doComparison (const SGPropertyNode * left, const SGPropertyNode *right) return SGComparisonCondition::EQUALS; break; } - case SGPropertyNode::INT: { + case props::INT: { int v1 = left->getIntValue(); int v2 = right->getIntValue(); if (v1 < v2) @@ -173,7 +170,7 @@ doComparison (const SGPropertyNode * left, const SGPropertyNode *right) return SGComparisonCondition::EQUALS; break; } - case SGPropertyNode::LONG: { + case props::LONG: { long v1 = left->getLongValue(); long v2 = right->getLongValue(); if (v1 < v2) @@ -184,7 +181,7 @@ doComparison (const SGPropertyNode * left, const SGPropertyNode *right) return SGComparisonCondition::EQUALS; break; } - case SGPropertyNode::FLOAT: { + case props::FLOAT: { float v1 = left->getFloatValue(); float v2 = right->getFloatValue(); if (v1 < v2) @@ -195,7 +192,7 @@ doComparison (const SGPropertyNode * left, const SGPropertyNode *right) return SGComparisonCondition::EQUALS; break; } - case SGPropertyNode::DOUBLE: { + case props::DOUBLE: { double v1 = left->getDoubleValue(); double v2 = right->getDoubleValue(); if (v1 < v2) @@ -206,9 +203,9 @@ doComparison (const SGPropertyNode * left, const SGPropertyNode *right) return SGComparisonCondition::EQUALS; break; } - case SGPropertyNode::STRING: - case SGPropertyNode::NONE: - case SGPropertyNode::UNSPECIFIED: { + case props::STRING: + case props::NONE: + case props::UNSPECIFIED: { string v1 = left->getStringValue(); string v2 = right->getStringValue(); if (v1 < v2) @@ -219,8 +216,10 @@ doComparison (const SGPropertyNode * left, const SGPropertyNode *right) return SGComparisonCondition::EQUALS; break; } + default: + throw sg_exception("condition: unrecognized node type in comparison"); } - throw sg_exception("Unrecognized node type"); + return 0; } @@ -236,7 +235,6 @@ SGComparisonCondition::SGComparisonCondition (Type type, bool reverse) SGComparisonCondition::~SGComparisonCondition () { - delete _right_value; } bool @@ -268,7 +266,6 @@ void SGComparisonCondition::setRightProperty( SGPropertyNode *prop_root, const char * propname ) { - delete _right_value; _right_value = 0; _right_property = prop_root->getNode(propname, true); } @@ -277,7 +274,6 @@ void SGComparisonCondition::setRightValue (const SGPropertyNode *node) { _right_property = 0; - delete _right_value; _right_value = new SGPropertyNode(*node); } @@ -308,7 +304,7 @@ readNotCondition( SGPropertyNode *prop_root, const SGPropertyNode *node ) if (condition != 0) return new SGNotCondition(condition); } - SG_LOG(SG_COCKPIT, SG_ALERT, "Panel: empty 'not' condition"); + SG_LOG(SG_COCKPIT, SG_ALERT, "empty 'not' condition"); return 0; } @@ -350,8 +346,10 @@ readComparison( SGPropertyNode *prop_root, condition->setLeftProperty(prop_root, node->getStringValue("property[0]")); if (node->hasValue("property[1]")) condition->setRightProperty(prop_root, node->getStringValue("property[1]")); - else + else if (node->hasValue("value")) condition->setRightValue(node->getChild("value", 0)); + else + throw sg_exception("condition: comparison without property[1] or value"); return condition; } @@ -402,13 +400,11 @@ SGConditional::SGConditional () SGConditional::~SGConditional () { - delete _condition; } void SGConditional::setCondition (SGCondition * condition) { - delete _condition; _condition = condition; }