2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 // $TOG: FeatureValue.C /main/6 1998/04/17 11:49:16 mgreess $
24 #include "StyleSheetExceptions.h"
27 #include "FeatureValue.h"
28 #include "Expression.h"
30 #include <utility/funcs.h>
37 FeatureValueInt::clone() const
39 return new FeatureValueInt(*this);
42 FeatureValueReal::clone() const
44 return new FeatureValueReal(*this);
47 FeatureValueString::clone() const
49 return new FeatureValueString(*this);
52 FeatureValueSymbol::clone() const
54 return new FeatureValueSymbol(*this);
57 FeatureValueExpression::clone() const
59 return new FeatureValueExpression(*this);
62 FeatureValueFeatureSet::clone() const
64 return new FeatureValueFeatureSet(*this);
67 FeatureValueDimension::clone() const
69 return new FeatureValueDimension(*this);
74 /* -------- Int -------- */
76 FeatureValueInt::FeatureValueInt(const FeatureValueInt &object)
77 : FeatureValue(integer), f_value(object.f_value)
81 /* -------- real -------- */
82 FeatureValueReal::FeatureValueReal(const FeatureValueReal &object)
83 : FeatureValue(real), f_value(object.f_value)
87 /* -------- String -------- */
88 FeatureValueString::FeatureValueString(const FeatureValueString &object)
89 : FeatureValue(string), f_value(object.f_value)
94 /* -------- Symbol -------- */
95 FeatureValueSymbol::FeatureValueSymbol(const FeatureValueSymbol &object)
96 : FeatureValue(symbol), f_value(object.f_value)
100 /* -------- Expression -------- */
101 FeatureValueExpression::FeatureValueExpression(const FeatureValueExpression &object)
102 : FeatureValue(expression), f_value(new Expression(*object.f_value))
105 FeatureValueExpression::FeatureValueExpression(Expression *e)
106 : FeatureValue(expression), f_value(e)
110 /* -------- Feature Set -------- */
111 FeatureValueFeatureSet::FeatureValueFeatureSet(FeatureSet *fs)
112 : FeatureValue(featureset), f_value(fs)
116 FeatureValueFeatureSet::FeatureValueFeatureSet(const FeatureValueFeatureSet &object)
117 : FeatureValue(featureset), f_value(new FeatureSet(*object.f_value))
122 FeatureValueDimension::FeatureValueDimension(const FeatureValueDimension& object)
123 : FeatureValue(dimension),
124 f_cachedValue(object.f_cachedValue),
125 f_unit(object.f_unit)
127 f_value = (object.f_value == 0) ? 0 : object.f_value -> clone();
131 // /////////////////////////////////////////////////////////////////////////
133 // /////////////////////////////////////////////////////////////////////////
135 FeatureValue::~FeatureValue()
140 FeatureValueString::~FeatureValueString()
144 FeatureValueExpression::~FeatureValueExpression()
149 FeatureValueFeatureSet::~FeatureValueFeatureSet()
154 FeatureValueDimension::~FeatureValueDimension()
161 virtual FeatureValue *operator+(FeatureValue&);
162 virtual FeatureValue *operator-(FeatureValue&);
163 virtual FeatureValue *operator*(FeatureValue&);
164 virtual FeatureValue *operator/(FeatureValue&);
168 FeatureValue::operator+(const FeatureValue &) const
170 // if we are here, then we did not override this function, and therefore
171 // cannot properly respond, so we use zero as our value
172 throw(CASTBEEXCEPT badEvaluationException());
177 FeatureValue::operator-(const FeatureValue &) const
179 // if we are here, then we did not override this function, and therefore
180 // cannot properly respond, so we use zero as our value
181 throw (CASTBEEXCEPT badEvaluationException());
186 FeatureValue::operator*(const FeatureValue &) const
188 // if we are here, then we did not override this function, and therefore
189 // cannot properly respond, so we use zero as our value
190 throw(CASTBEEXCEPT badEvaluationException());
195 FeatureValue::operator/(const FeatureValue &) const
197 throw(CASTBEEXCEPT badEvaluationException());
202 FeatureValue::operator+(const int) const
204 throw(CASTBEEXCEPT badEvaluationException());
208 FeatureValue::operator-(const int) const
210 throw(CASTBEEXCEPT badEvaluationException());
215 FeatureValue::operator*(const int) const
217 throw(CASTBEEXCEPT badEvaluationException());
222 FeatureValue::operator/(const int) const
224 throw(CASTBEEXCEPT badEvaluationException());
229 FeatureValue::operator+(const float) const
231 throw(CASTBEEXCEPT badEvaluationException());
237 FeatureValue::operator-(const float) const
239 throw(CASTBEEXCEPT badEvaluationException());
243 FeatureValue::operator*(const float) const
245 throw(CASTBEEXCEPT badEvaluationException());
250 FeatureValue::operator/(const float) const
252 throw(CASTBEEXCEPT badEvaluationException());
258 FeatureValue::operator+(const FeatureValueInt&) const
260 throw(CASTBEEXCEPT badEvaluationException());
265 FeatureValue::operator-(const FeatureValueInt&) const
267 throw(CASTBEEXCEPT badEvaluationException());
272 FeatureValue::operator*(const FeatureValueInt&) const
274 throw(CASTBEEXCEPT badEvaluationException());
279 FeatureValue::operator/(const FeatureValueInt&) const
281 throw(CASTBEEXCEPT badEvaluationException());
287 FeatureValue::operator+(const FeatureValueReal&) const
289 throw(CASTBEEXCEPT badEvaluationException());
294 FeatureValue::operator-(const FeatureValueReal&) const
296 throw(CASTBEEXCEPT badEvaluationException());
301 FeatureValue::operator*(const FeatureValueReal&) const
303 throw(CASTBEEXCEPT badEvaluationException());
308 FeatureValue::operator/(const FeatureValueReal&) const
310 throw(CASTBEEXCEPT badEvaluationException());
316 FeatureValue::operator+(const FeatureValueDimension&) const
318 throw(CASTBEEXCEPT badEvaluationException());
323 FeatureValue::operator-(const FeatureValueDimension&) const
325 throw(CASTBEEXCEPT badEvaluationException());
330 FeatureValue::operator*(const FeatureValueDimension&) const
332 throw(CASTBEEXCEPT badEvaluationException());
337 FeatureValue::operator/(const FeatureValueDimension&) const
339 throw(CASTBEEXCEPT badEvaluationException());
345 FeatureValue::operator+(const FeatureValueExpression&) const
347 throw(CASTBEEXCEPT badEvaluationException());
352 FeatureValue::operator-(const FeatureValueExpression&) const
354 throw(CASTBEEXCEPT badEvaluationException());
359 FeatureValue::operator*(const FeatureValueExpression&) const
361 throw(CASTBEEXCEPT badEvaluationException());
366 FeatureValue::operator/(const FeatureValueExpression&) const
368 throw(CASTBEEXCEPT badEvaluationException());
373 // /////////////////////////////////////////////////////////////////////////
374 // operators for FeatureValueInt
375 // /////////////////////////////////////////////////////////////////////////
378 FeatureValueInt::operator+(const FeatureValue &value) const
380 return value + f_value ;
384 FeatureValueInt::operator-(const FeatureValue &value) const
386 return value.rsub(f_value) ;
390 FeatureValueInt::operator*(const FeatureValue &value) const
392 return value * f_value ;
396 FeatureValueInt::operator/(const FeatureValue &value) const
398 return value.rdiv(f_value);
401 // now comes the ability to do actual operations because all types are know
404 FeatureValueInt::operator+(const int i) const
406 return new FeatureValueInt(f_value + i);
410 FeatureValueInt::operator-(const int i) const
412 return new FeatureValueInt(f_value - i);
416 FeatureValueInt::operator*(const int i) const
418 return new FeatureValueInt(f_value * i);
422 FeatureValueInt::operator/(const int i) const
424 return new FeatureValueReal((float)f_value / (float)i);
428 // /////////////////////////////////////////////////////////////////////////
430 // /////////////////////////////////////////////////////////////////////////
432 // output operator, uses virtual function print
433 ostream & operator << (ostream &o, const FeatureValue &f)
439 FeatureValueReal::print(ostream &o) const
441 return o << f_value ;
444 FeatureValueInt::print(ostream &o) const
446 return o << f_value ;
449 FeatureValueString::print(ostream &o) const
451 return o << '"' << f_value << '"';
454 FeatureValueSymbol::print(ostream &o) const
456 return o << f_value ;
459 FeatureValueExpression::print(ostream &o) const
461 return o << *f_value ;
464 FeatureValueFeatureSet::print(ostream &o) const
466 return o << *f_value ;
470 // /////////////////////////////////////////////////////////////////////////
472 // /////////////////////////////////////////////////////////////////////////
474 FeatureValue::operator const FeatureSet *() const
476 throw(CASTBCEXCEPT badCastException());
480 FeatureValueFeatureSet::operator const FeatureSet *() const
485 FeatureValue::operator float() const
487 throw(CASTBCEXCEPT badCastException());
490 FeatureValue::operator int() const
492 throw(CASTBCEXCEPT badCastException());
495 FeatureValue::operator const char *() const
497 throw(CASTBCEXCEPT badCastException());
501 FeatureValueReal::operator int() const
503 return (int)f_value ;
506 FeatureValueReal::operator float() const
512 FeatureValueString::operator+(const FeatureValue& x) const
514 if ( x.type() != string )
515 return FeatureValue::operator+(x);
517 const char* str1 = *this;
518 const char* str2 = x;
520 int len1 = f_value.length();
521 int len2 = ((FeatureValueString*)&x) -> f_value.length();
523 char* newString = new char[len1 + len2 + 1];
526 for ( i=0; i<len1; i++ )
527 newString[i] = str1[i];
529 for ( i=0; i<len2; i++ )
530 newString[i+len1] = str2[i];
532 newString[len1+len2] = 0;
534 FeatureValueString *z = new FeatureValueString(newString);
542 FeatureValueString::operator+(const FeatureValueInt& x) const
544 return FeatureValue::operator+(x);
548 FeatureValueString::operator+(const FeatureValueReal& x) const
550 return FeatureValue::operator+(x);
554 FeatureValueString::operator+(const FeatureValueDimension& x) const
556 return FeatureValue::operator+(x);
560 FeatureValueString::operator+(const FeatureValueExpression& expr) const
579 FeatureValueString::operator+(const int i) const
581 return FeatureValue::operator+(i);
585 FeatureValueString::operator+(const float f) const
587 return FeatureValue::operator+(f);
590 FeatureValueString::operator const char *() const
595 FeatureValueSymbol::operator const char *() const
597 return strdup(f_value.name()) ;
600 FeatureValueInt::operator const char *() const
602 throw(CASTBCEXCEPT badCastException()) ;
606 FeatureValueExpression::operator const char *() const
608 throw(CASTBCEXCEPT badCastException()) ;
612 FeatureValueDimension::operator int () const
614 if ( f_cachedValue != -1 )
615 return (int)f_cachedValue;
618 throw(CASTBEEXCEPT badEvaluationException()) ;
620 FeatureValue *intermediate = f_value->doConvert(f_unit);
621 int i = *intermediate ;
622 delete intermediate ;
626 FeatureValueDimension::operator float() const
628 if ( f_cachedValue != -1 )
629 return f_cachedValue;
632 throw(CASTBEEXCEPT badEvaluationException()) ;
634 FeatureValue *intermediate = f_value->doConvert(f_unit);
635 float f = *intermediate ;
636 delete intermediate ;
640 FeatureValueDimension::operator const char *() const
642 throw(CASTBCEXCEPT badCastException()) ;
646 // /////////////////////////////////////////////////////////////////////////
648 // /////////////////////////////////////////////////////////////////////////
651 FeatureValue::evaluate() const
657 FeatureValueFeatureSet::evaluate() const
660 FeatureSet* fs = new FeatureSet;
661 return new FeatureValueFeatureSet(f_value->evaluate(fs));
663 return new FeatureValueFeatureSet(f_value->evaluate());
668 FeatureValueExpression::evaluate() const
670 return f_value->evaluate();
673 // /////////////////////////////////////////////////////////////////////////
674 // more math for Expression
675 // /////////////////////////////////////////////////////////////////////////
678 FeatureValueExpression::operator/(const FeatureValue &f) const
680 // Need parameters for evaluate
681 FeatureValue *eval = evaluate();
682 FeatureValue *rval = (*eval) / f ;
688 FeatureValueExpression::operator*(const FeatureValue &f) const
690 // Need parameters for evaluate
691 FeatureValue *eval = evaluate();
692 FeatureValue *rval = (*eval) * f ;
697 FeatureValueExpression::operator-(const FeatureValue &f) const
699 // Need parameters for evaluate
700 FeatureValue *eval = evaluate();
701 FeatureValue *rval = (*eval) - f ;
706 FeatureValueExpression::operator+(const FeatureValue &f) const
708 // Need parameters for evaluate
709 FeatureValue *eval = evaluate();
710 FeatureValue *rval = (*eval) + f ;
716 FeatureValueExpression::operator/(const float f) const
718 // need values for evaluate
719 FeatureValue *eval = evaluate();
720 FeatureValue *rval = (*eval) / f ;
725 FeatureValueExpression::operator*(const float f) const
727 // need values for evaluate
728 FeatureValue *eval = evaluate();
729 FeatureValue *rval = (*eval) * f ;
734 FeatureValueExpression::operator-(const float f) const
736 // need values for evaluate
737 FeatureValue *eval = evaluate();
738 FeatureValue *rval = (*eval) - f ;
743 FeatureValueExpression::operator+(const float f) const
745 // need values for evaluate
746 FeatureValue *eval = evaluate();
747 FeatureValue *rval = (*eval) + f ;
754 FeatureValueExpression::operator/(const int f) const
756 // need values for evaluate
757 FeatureValue *eval = evaluate();
758 FeatureValue *rval = (*eval) / f ;
763 FeatureValueExpression::operator*(const int f) const
765 // need values for evaluate
766 FeatureValue *eval = evaluate();
767 FeatureValue *rval = (*eval) * f ;
772 FeatureValueExpression::operator-(const int f) const
774 // need values for evaluate
775 FeatureValue *eval = evaluate();
776 FeatureValue *rval = (*eval) - f ;
781 FeatureValueExpression::operator+(const int f) const
783 // need values for evaluate
784 FeatureValue *eval = evaluate();
785 FeatureValue *rval = (*eval) + f ;
791 FeatureValueInt::operator/(const float f) const
793 return new FeatureValueReal(f_value / f);
796 FeatureValueInt::operator*(const float f) const
798 return new FeatureValueReal(f_value * f);
802 FeatureValueInt::operator-(const float f) const
804 return new FeatureValueReal(f_value - f);
808 FeatureValueInt::operator+(const float f) const
810 return new FeatureValueReal(f_value + f);
813 FeatureValueReal::operator const char*(void) const
815 throw(CASTBEEXCEPT badEvaluationException());
819 FeatureValueString::operator int(void) const
822 throw(CASTBEEXCEPT badEvaluationException());
825 return atoi (f_value);
829 FeatureValueString::operator float(void) const
831 throw(CASTBEEXCEPT badEvaluationException());
835 FeatureValueSymbol::operator int(void) const
837 throw(CASTBEEXCEPT badEvaluationException());
841 FeatureValueSymbol::operator float(void) const
843 throw(CASTBEEXCEPT badEvaluationException());
848 FeatureValueReal::operator/(const FeatureValue &f) const
850 return f.rdiv(f_value);
854 FeatureValueReal::operator*(const FeatureValue &f) const
859 FeatureValueReal::operator-(const FeatureValue &f) const
861 return f.rsub(f_value);
864 FeatureValueReal::operator+(const FeatureValue &f) const
870 FeatureValueExpression::operator int(void) const
872 FeatureValue *eval = evaluate();
873 int i = (int)(*eval);
878 FeatureValueExpression::operator float(void) const
880 FeatureValue *eval = evaluate();
881 float f = (float)(*eval);
887 FeatureValueReal::operator/(const float f) const
889 return new FeatureValueReal(f_value / f);
892 FeatureValueReal::operator*(const float f) const
894 return new FeatureValueReal(f_value * f);
897 FeatureValueReal::operator-(const float f) const
899 return new FeatureValueReal(f_value - f);
902 FeatureValueReal::operator+(const float f) const
904 return new FeatureValueReal(f_value + f);
908 FeatureValueReal::operator/(const int i) const
910 return new FeatureValueReal(f_value / (float) i);
913 FeatureValueReal::operator*(const int i) const
915 return new FeatureValueReal(f_value * (float) i);
918 FeatureValueReal::operator-(const int i) const
920 return new FeatureValueReal(f_value - (float) i);
923 FeatureValueReal::operator+(const int i) const
925 return new FeatureValueReal(f_value + (float) i);
928 FeatureValueInt::operator int(void) const
933 FeatureValueInt::operator float(void) const
939 // /////////////////////////////////////////////////////////////////////////
941 // /////////////////////////////////////////////////////////////////////////
944 FeatureValue::operator==(const FeatureValue &) const
946 // false unless overridden by derived objects
950 FeatureValue::operator==(const FeatureValueInt &) const
955 FeatureValue::operator==(const FeatureValueReal &) const
960 FeatureValue::operator==(const FeatureValueString &) const
965 FeatureValue::operator==(const FeatureValueSymbol &) const
972 FeatureValueInt::operator==(const FeatureValue &f) const
978 FeatureValueInt::operator==(const FeatureValueInt &f) const
980 return f.f_value == f_value ;
983 FeatureValueInt::operator==(const FeatureValueReal &) const
988 FeatureValueInt::operator==(const FeatureValueString &) const
993 FeatureValueInt::operator==(const FeatureValueSymbol &) const
1000 FeatureValueReal::operator==(const FeatureValue &f) const
1006 FeatureValueReal::operator==(const FeatureValueReal &f) const
1008 return f.f_value == f_value ;
1011 FeatureValueReal::operator==(const FeatureValueInt &) const
1016 FeatureValueReal::operator==(const FeatureValueString &) const
1021 FeatureValueReal::operator==(const FeatureValueSymbol &) const
1027 FeatureValueSymbol::operator==(const FeatureValue &f) const
1032 FeatureValueSymbol::operator==(const FeatureValueSymbol &f) const
1034 return f.f_value == f_value ;
1037 FeatureValueSymbol::operator==(const FeatureValueInt &) const
1042 FeatureValueSymbol::operator==(const FeatureValueReal &) const
1047 FeatureValueSymbol::operator==(const FeatureValueString &) const
1053 FeatureValueString::operator==(const FeatureValue &f) const
1058 FeatureValueString::operator==(const FeatureValueString &f) const
1060 return !f_value.compareTo(f.f_value, CC_String::exact);
1063 FeatureValueString::operator==(const FeatureValueInt &) const
1068 FeatureValueString::operator==(const FeatureValueReal &) const
1073 FeatureValueString::operator==(const FeatureValueSymbol &) const
1078 // /////////////////////////////////////////////////////////////////////////
1080 // /////////////////////////////////////////////////////////////////////////
1084 FeatureValue::merge(const FeatureValue &f)
1090 FeatureValueFeatureSet::merge(const FeatureValue &f)
1092 if (f.type() == featureset)
1093 return new FeatureValueFeatureSet(new FeatureSet(*f_value,
1094 *((FeatureValueFeatureSet*)&f)->f_value));
1099 static float dimensionConversionTable[] = {72, 12, 1, 72/2.54};
1103 FeatureValue::Unit dimensionOfy,
1104 FeatureValue::Unit dimensionOfReturn
1107 if ( dimensionOfy == FeatureValue::NONE ||
1108 dimensionOfReturn == FeatureValue::NONE ||
1109 dimensionOfy == dimensionOfReturn
1113 // handle PIXEL case here.
1116 // handle INCH, PICA, POINT and CM cases here
1119 //debug(cerr, dimensionConversionTable[dimensionOfy]);
1120 //debug(cerr, dimensionConversionTable[dimensionOfReturn]);
1123 dimensionConversionTable[dimensionOfy] /
1124 dimensionConversionTable[dimensionOfReturn];
1129 FeatureValueDimension::convert(float y,
1131 Unit dimensionOfReturn
1134 return ::convert(y, dimensionOfy, dimensionOfReturn);
1137 FeatureValue *FeatureValueDimension::operator/(const FeatureValue& fv) const
1139 return fv.rdiv(*this);
1142 FeatureValue *FeatureValueDimension::operator*(const FeatureValue& fv) const
1147 FeatureValue *FeatureValueDimension::operator-(const FeatureValue& fv) const
1149 return fv.rsub(*this);
1152 FeatureValue *FeatureValueDimension::operator+(const FeatureValue& fv) const
1157 FeatureValue *FeatureValueDimension::operator/(const float x) const
1159 FeatureValue *intermediate = *f_value / x;
1160 FeatureValue *result = intermediate->convertTo(f_unit);
1161 delete intermediate;
1165 FeatureValue *FeatureValueDimension::operator*(const float x) const
1167 FeatureValue *intermediate = *f_value * x ;
1168 FeatureValue *result = intermediate->convertTo(f_unit);
1169 delete intermediate ;
1173 FeatureValue *FeatureValueDimension::operator-(const float x) const
1175 FeatureValue *intermediate = *f_value - x;
1176 FeatureValue *result = intermediate->convertTo(f_unit);
1177 delete intermediate;
1181 FeatureValue *FeatureValueDimension::operator+(const float x) const
1183 FeatureValue *intermediate = *f_value + x;
1184 FeatureValue *result = intermediate->convertTo(f_unit);
1185 delete intermediate;
1189 FeatureValue *FeatureValueDimension::operator/(const int x) const
1191 FeatureValue *intermediate = *f_value / x ;
1192 FeatureValue *result = intermediate->convertTo(f_unit);
1193 delete intermediate;
1197 FeatureValue *FeatureValueDimension::operator*(const int x) const
1199 FeatureValue *intermediate = *f_value * x ;
1200 FeatureValue *result = intermediate->convertTo(f_unit);
1201 delete intermediate;
1205 FeatureValue *FeatureValueDimension::operator-(const int x) const
1207 FeatureValue *intermediate = *f_value - x ;
1208 FeatureValue *result = intermediate->convertTo(f_unit);
1209 delete intermediate ;
1213 FeatureValue *FeatureValueDimension::operator+(const int x) const
1215 FeatureValue *intermediate = *f_value + x ;
1216 FeatureValue *result = intermediate->convertTo(f_unit);
1217 delete intermediate ;
1221 ostream& FeatureValueDimension::print(ostream& out) const
1225 if ( f_cachedValue != -1 )
1226 out << f_cachedValue << " ";
1228 throw(CASTBEEXCEPT badEvaluationException());
1230 out << *f_value << " ";
1250 throw(CASTBEEXCEPT badEvaluationException());
1256 FeatureValueDimension::FeatureValueDimension(float f, const char* u)
1257 : FeatureValue(dimension), f_value(0),
1260 f_unit = convertToUnit(u);
1263 FeatureValueDimension::FeatureValueDimension(FeatureValue *value, Unit unit)
1264 : FeatureValue(dimension),
1271 FeatureValueDimension::FeatureValueDimension(FeatureValue* f, const char* u)
1272 : FeatureValue(dimension), f_value(f), f_cachedValue(-1)
1274 f_unit = convertToUnit(u);
1278 FeatureValueDimension::convertToUnit(const char* u)
1281 if ( strcasecmp(u, "inch") == 0 || strcasecmp(u, "in") == 0 )
1284 if ( strcasecmp(u, "cm") == 0 )
1287 if ( strcasecmp(u, "pica") == 0 || strcasecmp(u, "pc") == 0 )
1290 if ( strcasecmp(u, "point") == 0 || strcasecmp(u, "pt") == 0 )
1293 if ( strcasecmp(u, "pixel") == 0 )
1296 throw(CASTBEEXCEPT badEvaluationException());
1301 float FeatureValueDimension::getValue(Unit u)
1303 return convert(float(*this), f_unit, u);
1309 FeatureValueReal::operator+(const FeatureValueInt &value) const
1311 return value + f_value ;
1315 FeatureValueReal::operator-(const FeatureValueInt &value) const
1317 return new FeatureValueReal(f_value - (int)value);
1321 FeatureValueReal::operator*(const FeatureValueInt &value) const
1323 return value * f_value ;
1327 FeatureValueReal::operator/(const FeatureValueInt &value) const
1329 return value.rdiv(f_value);
1334 FeatureValueReal::operator+(const FeatureValueReal &value) const
1336 return value + f_value ;
1340 FeatureValueReal::operator-(const FeatureValueReal &value) const
1342 return new FeatureValueReal(f_value - value.f_value) ;
1346 FeatureValueReal::operator*(const FeatureValueReal &value) const
1348 return value * f_value ;
1352 FeatureValueReal::operator/(const FeatureValueReal &value) const
1354 return value.rdiv(f_value);
1359 FeatureValueReal::operator+(const FeatureValueDimension &value) const
1361 return value + f_value ;
1365 FeatureValueReal::operator-(const FeatureValueDimension &value) const
1367 return value.rsub(f_value);
1371 FeatureValueReal::operator*(const FeatureValueDimension &value) const
1373 return value * f_value ;
1377 FeatureValueReal::operator/(const FeatureValueDimension &value) const
1379 return value.rdiv(f_value);
1384 FeatureValueReal::operator+(const FeatureValueExpression &value) const
1386 FeatureValue *eval = value.evaluate();
1387 FeatureValue *return_val = *eval + f_value ;
1393 FeatureValueReal::operator-(const FeatureValueExpression &value) const
1395 FeatureValue *eval = value.evaluate();
1396 FeatureValue *result = eval->rsub( f_value );
1402 FeatureValueReal::operator*(const FeatureValueExpression &value) const
1404 FeatureValue *eval = value.evaluate();
1405 FeatureValue *return_val = *eval * f_value ;
1411 FeatureValueReal::operator/(const FeatureValueExpression &value) const
1413 FeatureValue *eval = value.evaluate();
1414 FeatureValue *result = eval->rdiv(f_value) ;
1422 FeatureValueInt::operator+(const FeatureValueInt &value) const
1424 return value + f_value ;
1428 FeatureValueInt::operator-(const FeatureValueInt &value) const
1430 return value.rsub(f_value);
1434 FeatureValueInt::operator*(const FeatureValueInt &value) const
1436 return value * f_value ;
1440 FeatureValueInt::operator/(const FeatureValueInt &value) const
1442 return value.rdiv(f_value);
1447 FeatureValueInt::operator+(const FeatureValueReal &value) const
1449 return value + f_value ;
1453 FeatureValueInt::operator-(const FeatureValueReal &value) const
1455 return value.rsub(f_value);
1459 FeatureValueInt::operator*(const FeatureValueReal &value) const
1461 return value * f_value ;
1465 FeatureValueInt::operator/(const FeatureValueReal &value) const
1467 return value.rdiv(f_value);
1472 FeatureValueInt::operator+(const FeatureValueDimension &value) const
1474 return value + f_value ;
1478 FeatureValueInt::operator-(const FeatureValueDimension &value) const
1480 return value.rsub(f_value);
1484 FeatureValueInt::operator*(const FeatureValueDimension &value) const
1486 return value * f_value ;
1490 FeatureValueInt::operator/(const FeatureValueDimension &value) const
1492 return value.rdiv(f_value);
1497 FeatureValueInt::operator+(const FeatureValueExpression &value) const
1499 FeatureValue *eval = value.evaluate();
1500 FeatureValue *return_val = *eval + f_value ;
1506 FeatureValueInt::operator-(const FeatureValueExpression &value) const
1508 FeatureValue *eval = value.evaluate();
1509 FeatureValue *result = eval->rsub(f_value) ;
1515 FeatureValueInt::operator*(const FeatureValueExpression &value) const
1517 FeatureValue *eval = value.evaluate();
1518 FeatureValue *return_val = *eval * f_value ;
1524 FeatureValueInt::operator/(const FeatureValueExpression &value) const
1526 FeatureValue *eval = value.evaluate();
1527 FeatureValue *result = eval->rdiv(f_value) ;
1534 FeatureValueExpression::operator+(const FeatureValueInt &value) const
1536 FeatureValue *eval = evaluate();
1537 FeatureValue *return_val = *eval + value ;
1543 FeatureValueExpression::operator-(const FeatureValueInt &value) const
1545 FeatureValue *eval = evaluate();
1546 FeatureValue *return_val = *eval - value ;
1552 FeatureValueExpression::operator*(const FeatureValueInt &value) const
1554 FeatureValue *eval = evaluate();
1555 FeatureValue *return_val = *eval * value ;
1561 FeatureValueExpression::operator/(const FeatureValueInt &value) const
1563 FeatureValue *eval = evaluate();
1564 FeatureValue *return_val = *eval / value ;
1571 FeatureValueExpression::operator+(const FeatureValueReal &value) const
1573 FeatureValue *eval = evaluate();
1574 FeatureValue *return_val = *eval + value ;
1580 FeatureValueExpression::operator-(const FeatureValueReal &value) const
1582 FeatureValue *eval = evaluate();
1583 FeatureValue *return_val = *eval - value ;
1589 FeatureValueExpression::operator*(const FeatureValueReal &value) const
1591 FeatureValue *eval = evaluate();
1592 FeatureValue *return_val = *eval * value ;
1598 FeatureValueExpression::operator/(const FeatureValueReal &value) const
1600 FeatureValue *eval = evaluate();
1601 FeatureValue *return_val = *eval / value ;
1608 FeatureValueExpression::operator+(const FeatureValueDimension &value) const
1610 FeatureValue *eval = evaluate();
1611 FeatureValue *return_val = *eval + value ;
1617 FeatureValueExpression::operator-(const FeatureValueDimension &value) const
1619 FeatureValue *eval = evaluate();
1620 FeatureValue *return_val = *eval - value ;
1626 FeatureValueExpression::operator*(const FeatureValueDimension &value) const
1628 FeatureValue *eval = evaluate();
1629 FeatureValue *return_val = *eval * value ;
1635 FeatureValueExpression::operator/(const FeatureValueDimension &value) const
1637 FeatureValue *eval = evaluate();
1638 FeatureValue *return_val = *eval / value ;
1645 FeatureValueExpression::operator+(const FeatureValueExpression &value) const
1647 FeatureValue *eval = evaluate();
1648 FeatureValue *return_val = *eval + value ;
1654 FeatureValueExpression::operator-(const FeatureValueExpression &value) const
1656 FeatureValue *eval = evaluate();
1657 FeatureValue *return_val = *eval - value ;
1663 FeatureValueExpression::operator*(const FeatureValueExpression &value) const
1665 FeatureValue *eval = evaluate();
1666 FeatureValue *return_val = *eval * value ;
1672 FeatureValueExpression::operator/(const FeatureValueExpression &value) const
1674 FeatureValue *eval = evaluate();
1675 FeatureValue *return_val = *eval / value ;
1683 FeatureValueDimension::operator+(const FeatureValueInt &value) const
1685 FeatureValue *intermediate = *f_value + value ;
1686 FeatureValue *result = intermediate->convertTo(f_unit);
1687 delete intermediate;
1692 FeatureValueDimension::operator-(const FeatureValueInt &value) const
1694 FeatureValue *intermediate = *f_value - value ;
1695 FeatureValue *result = intermediate->convertTo(f_unit);
1696 delete intermediate;
1701 FeatureValueDimension::operator*(const FeatureValueInt &value) const
1703 FeatureValue *intermediate = *f_value * value;
1704 FeatureValue *result = intermediate->convertTo(f_unit);
1705 delete intermediate;
1710 FeatureValueDimension::operator/(const FeatureValueInt &value) const
1712 FeatureValue *intermediate = *f_value / value;
1713 FeatureValue *result = intermediate->convertTo(f_unit);
1714 delete intermediate;
1720 FeatureValueDimension::operator+(const FeatureValueReal &value) const
1722 FeatureValue *intermediate = *f_value + value;
1723 FeatureValue *result = intermediate->convertTo(f_unit);
1724 delete intermediate;
1729 FeatureValueDimension::operator-(const FeatureValueReal &value) const
1731 FeatureValue *intermediate = *f_value - value;
1732 FeatureValue *result = intermediate->convertTo(f_unit);
1733 delete intermediate;
1738 FeatureValueDimension::operator*(const FeatureValueReal &value) const
1740 FeatureValue *intermediate = *f_value * value;
1741 FeatureValue *result = intermediate->convertTo(f_unit);
1742 delete intermediate;
1747 FeatureValueDimension::operator/(const FeatureValueReal &value) const
1749 FeatureValue *intermediate = *f_value / value;
1750 FeatureValue *result = intermediate->convertTo(f_unit);
1751 delete intermediate;
1757 FeatureValueDimension::operator+(const FeatureValueDimension &value) const
1759 FeatureValue *i1 = value.doConvert(f_unit);
1760 FeatureValue *i2 = f_value->doConvert(f_unit);
1761 FeatureValue *i3 = *i1 + *i2 ;
1764 return new FeatureValueDimension(i3, f_unit) ;
1768 FeatureValueDimension::operator-(const FeatureValueDimension &value) const
1770 FeatureValue *intermediate = *f_value - value;
1771 FeatureValue *result = intermediate->convertTo(f_unit);
1772 delete intermediate;
1777 FeatureValueDimension::operator*(const FeatureValueDimension &value) const
1779 FeatureValue *intermediate = *f_value * value;
1780 FeatureValue *result = intermediate->convertTo(f_unit);
1781 delete intermediate;
1786 FeatureValueDimension::operator/(const FeatureValueDimension &value) const
1788 FeatureValue *intermediate = *f_value / value;
1789 FeatureValue *result = intermediate->convertTo(f_unit);
1790 delete intermediate;
1796 FeatureValueDimension::operator+(const FeatureValueExpression &value) const
1798 FeatureValue *intermediate = *f_value + value;
1799 FeatureValue *result = intermediate->convertTo(f_unit);
1800 delete intermediate;
1805 FeatureValueDimension::operator-(const FeatureValueExpression &value) const
1807 FeatureValue *intermediate = *f_value - value;
1808 FeatureValue *result = intermediate->convertTo(f_unit);
1809 delete intermediate;
1814 FeatureValueDimension::operator*(const FeatureValueExpression &value) const
1816 FeatureValue *intermediate = *f_value * value;
1817 FeatureValue *result = intermediate->convertTo(f_unit);
1818 delete intermediate;
1823 FeatureValueDimension::operator/(const FeatureValueExpression &value) const
1825 FeatureValue *intermediate = *f_value / value;
1826 FeatureValue *result = intermediate->convertTo(f_unit);
1827 delete intermediate;
1832 /* -------- rdiv, rsub -------- */
1835 FeatureValue::rdiv(const FeatureValue &) const
1837 throw(CASTBEEXCEPT badEvaluationException());
1841 FeatureValue::rsub(const FeatureValue &) const
1843 throw(CASTBEEXCEPT badEvaluationException());
1847 FeatureValue::rdiv(const FeatureValueInt &) const
1849 throw(CASTBEEXCEPT badEvaluationException());
1853 FeatureValue::rsub(const FeatureValueInt &) const
1855 throw(CASTBEEXCEPT badEvaluationException());
1859 FeatureValue::rdiv(const FeatureValueReal &) const
1861 throw(CASTBEEXCEPT badEvaluationException());
1865 FeatureValue::rsub(const FeatureValueReal &) const
1867 throw(CASTBEEXCEPT badEvaluationException());
1871 FeatureValue::rdiv(const FeatureValueExpression &) const
1873 throw(CASTBEEXCEPT badEvaluationException());
1877 FeatureValue::rsub(const FeatureValueExpression &) const
1879 throw(CASTBEEXCEPT badEvaluationException());
1883 FeatureValue::rdiv(const FeatureValueDimension &) const
1885 throw(CASTBEEXCEPT badEvaluationException());
1889 FeatureValue::rsub(const FeatureValueDimension &) const
1891 throw(CASTBEEXCEPT badEvaluationException());
1895 FeatureValue::rdiv(const int) const
1897 throw(CASTBEEXCEPT badEvaluationException());
1901 FeatureValue::rsub(const int) const
1903 throw(CASTBEEXCEPT badEvaluationException());
1907 FeatureValue::rdiv(const float) const
1909 throw(CASTBEEXCEPT badEvaluationException());
1913 FeatureValue::rsub(const float) const
1915 throw(CASTBEEXCEPT badEvaluationException());
1919 /* -------- FeatureValueInt rdiv, rsub -------- */
1922 FeatureValueInt::rdiv(const FeatureValue &f) const
1927 FeatureValueInt::rsub(const FeatureValue &f) const
1929 return f - f_value ;
1932 FeatureValueInt::rdiv(const FeatureValueInt &i) const
1934 return i / f_value ;
1937 FeatureValueInt::rsub(const FeatureValueInt &i) const
1939 return i - f_value ;
1942 FeatureValueInt::rdiv(const FeatureValueReal &r) const
1944 return r / f_value ;
1947 FeatureValueInt::rsub(const FeatureValueReal &r) const
1949 return r - f_value ;
1952 FeatureValueInt::rdiv(const FeatureValueExpression &e) const
1954 return e / f_value ;
1957 FeatureValueInt::rsub(const FeatureValueExpression &e) const
1959 return e - f_value ;
1962 FeatureValueInt::rdiv(const FeatureValueDimension &d) const
1964 return d / f_value ;
1967 FeatureValueInt::rsub(const FeatureValueDimension &d) const
1969 return d - f_value ;
1972 FeatureValueInt::rdiv(const int i) const
1974 return new FeatureValueInt(i / f_value);
1977 FeatureValueInt::rsub(const int i) const
1979 return new FeatureValueInt(i - f_value);
1982 FeatureValueInt::rdiv(const float f) const
1984 return new FeatureValueReal(f / f_value);
1987 FeatureValueInt::rsub(const float f) const
1989 return new FeatureValueReal(f - f_value);
1991 /* -------- FeatureValueReal rdiv, rsub -------- */
1993 FeatureValueReal::rdiv(const FeatureValue &f) const
1995 return f / f_value ;
1998 FeatureValueReal::rsub(const FeatureValue &f) const
2000 return f - f_value ;
2003 FeatureValueReal::rdiv(const FeatureValueInt &i) const
2005 return i / f_value ;
2008 FeatureValueReal::rsub(const FeatureValueInt &i) const
2010 return i - f_value ;
2013 FeatureValueReal::rdiv(const FeatureValueReal &r) const
2015 return r / f_value ;
2018 FeatureValueReal::rsub(const FeatureValueReal &r) const
2020 return r - f_value ;
2023 FeatureValueReal::rdiv(const FeatureValueExpression &e) const
2025 return e / f_value ;
2028 FeatureValueReal::rsub(const FeatureValueExpression &e) const
2030 return e - f_value ;
2033 FeatureValueReal::rdiv(const FeatureValueDimension &d) const
2035 return d / f_value ;
2038 FeatureValueReal::rsub(const FeatureValueDimension &d) const
2040 return d - f_value ;
2043 FeatureValueReal::rdiv(const int i) const
2045 return new FeatureValueReal(i / f_value);
2048 FeatureValueReal::rsub(const int i) const
2050 return new FeatureValueReal(i - f_value);
2053 FeatureValueReal::rdiv(const float f) const
2055 return new FeatureValueReal(f / f_value);
2058 FeatureValueReal::rsub(const float f) const
2060 return new FeatureValueReal(f - f_value);
2062 /* -------- FeatureValueExpression rdiv, rsub -------- */
2065 FeatureValueExpression::rdiv(const FeatureValue &f) const
2070 FeatureValueExpression::rsub(const FeatureValue &f) const
2075 FeatureValueExpression::rdiv(const FeatureValueInt &i) const
2080 FeatureValueExpression::rsub(const FeatureValueInt &i) const
2085 FeatureValueExpression::rdiv(const FeatureValueReal &r) const
2090 FeatureValueExpression::rsub(const FeatureValueReal &r) const
2095 FeatureValueExpression::rdiv(const FeatureValueExpression &e) const
2100 FeatureValueExpression::rsub(const FeatureValueExpression &e) const
2105 FeatureValueExpression::rdiv(const FeatureValueDimension &d) const
2110 FeatureValueExpression::rsub(const FeatureValueDimension &d) const
2115 FeatureValueExpression::rdiv(const int i) const
2117 FeatureValue *e = evaluate();
2118 FeatureValue *intermediate = e->rdiv(i);
2120 return intermediate;
2123 FeatureValueExpression::rsub(const int i) const
2125 FeatureValue *e = evaluate();
2126 FeatureValue *intermediate = e->rsub(i);
2128 return intermediate;
2131 FeatureValueExpression::rdiv(const float f) const
2133 FeatureValue *e = evaluate();
2134 FeatureValue *intermediate = e->rdiv(f);
2136 return intermediate;
2139 FeatureValueExpression::rsub(const float f) const
2141 FeatureValue *e = evaluate();
2142 FeatureValue *intermediate = e->rsub(f);
2144 return intermediate;
2146 /* -------- FeatureValueDimension rdiv, rsub -------- */
2148 FeatureValueDimension::rdiv(const FeatureValue &f) const
2153 FeatureValueDimension::rsub(const FeatureValue &f) const
2158 FeatureValueDimension::rdiv(const FeatureValueInt &i) const
2163 FeatureValueDimension::rsub(const FeatureValueInt &i) const
2168 FeatureValueDimension::rdiv(const FeatureValueReal &r) const
2173 FeatureValueDimension::rsub(const FeatureValueReal &r) const
2178 FeatureValueDimension::rdiv(const FeatureValueExpression &e) const
2183 FeatureValueDimension::rsub(const FeatureValueExpression &e) const
2188 FeatureValueDimension::rdiv(const FeatureValueDimension &d) const
2193 FeatureValueDimension::rsub(const FeatureValueDimension &d) const
2198 FeatureValueDimension::rdiv(const int i) const
2200 // rdiv the value then convert result to our unit type
2201 FeatureValue *intermediate = f_value->rdiv(i);
2202 FeatureValue *result = intermediate->convertTo(f_unit);
2203 delete intermediate;
2208 FeatureValueDimension::rsub(const int i) const
2210 FeatureValue *intermediate = f_value->rsub(i);
2211 FeatureValue *result = intermediate->convertTo(f_unit);
2212 delete intermediate;
2216 FeatureValueDimension::rdiv(const float f) const
2218 FeatureValue *intermediate = f_value->rdiv(f);
2219 FeatureValue *result = intermediate->convertTo(f_unit);
2220 delete intermediate;
2224 FeatureValueDimension::rsub(const float f) const
2226 FeatureValue *intermediate = f_value->rsub(f);
2227 FeatureValue *result = intermediate->convertTo(f_unit);
2228 delete intermediate;
2232 /* -------- convert To -------- */
2235 FeatureValue::convertTo(Unit ) const
2237 throw(CASTBEEXCEPT badEvaluationException());
2242 FeatureValueInt::convertTo(Unit unit) const
2244 return new FeatureValueDimension(new FeatureValueInt(*this), unit);
2248 FeatureValueReal::convertTo(Unit unit) const
2250 return new FeatureValueDimension(new FeatureValueReal(*this), unit);
2254 FeatureValueDimension::convertTo(Unit unit) const
2257 return new FeatureValueDimension(*this);
2259 // convert our value to new unit type
2260 return new FeatureValueDimension(f_value->convertTo(f_unit, unit),
2265 FeatureValue::convertTo(Unit, Unit) const
2267 throw(CASTBEEXCEPT badEvaluationException());
2272 FeatureValueReal::convertTo(Unit old_unit,
2273 Unit new_unit) const
2275 return new FeatureValueReal(convert(f_value,old_unit, new_unit));
2278 FeatureValueInt::convertTo(Unit old_unit,
2279 Unit new_unit) const
2281 return new FeatureValueReal(convert(f_value,old_unit, new_unit));
2285 FeatureValueDimension::convertTo(Unit old_unit,
2286 Unit new_unit) const
2288 FeatureValue *intermediate = f_value->convertTo(old_unit, f_unit);
2289 FeatureValue *result = intermediate->convertTo(new_unit);
2290 delete intermediate;
2294 /* -------- FeatureValueDimension::evaluate -------- */
2297 FeatureValueDimension::evaluate() const
2299 FeatureValue *intermediate = f_value->evaluate();
2300 FeatureValue *result = intermediate->convertTo(f_unit);
2301 delete intermediate;
2307 FeatureValue::doConvert(Unit) const
2309 throw(CASTBEEXCEPT badEvaluationException());
2314 FeatureValueReal::doConvert(Unit) const
2316 return new FeatureValueReal(*this);
2320 FeatureValueInt::doConvert(Unit) const
2322 return new FeatureValueInt(*this);
2326 FeatureValueDimension::doConvert(Unit unit) const
2329 return f_value->doConvert(unit);
2331 return f_value->convertTo(f_unit, unit);
2334 ///////////////////////////////////////////////////
2335 // FeatureValueArray
2336 ///////////////////////////////////////////////////
2338 FeatureValueArray::FeatureValueArray(const char* nm, int size) :
2339 FeatureValue(array), pointer_vector<FeatureValue>(size, 0), f_name(strdup(nm))
2343 FeatureValueArray::FeatureValueArray(const FeatureValueArray& x) :
2344 FeatureValue(array), pointer_vector<FeatureValue>(x.length(), 0),
2345 f_name(strdup(x.f_name))
2349 for ( unsigned int i=0; i<length(); i++ )
2350 (*this)[i] = x[i] -> clone();
2355 for ( unsigned int i=0; i<length(); i++ )
2362 FeatureValueArray::~FeatureValueArray()
2364 for ( unsigned int i=0; i<length(); i++ )
2371 FeatureValueArray::evaluate() const
2373 FeatureValueArray *result = new FeatureValueArray(f_name, length());
2377 for ( unsigned int i=0; i<length(); i++ ) {
2378 (*result)[i] = (*this)[i] -> evaluate();
2391 FeatureValueArray::print(ostream& out) const
2393 out << f_name << "[\n";
2395 for ( unsigned int i=0; i<length(); i++ ) {
2397 if ( (*this)[i] == 0 ) {
2398 MESSAGE(cerr, form("%d is a null slot", i));
2402 out << "\t" << *((*this)[i]) << "\n";