FeatureValue.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  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)
  10. * any later version.
  11. *
  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
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: FeatureValue.h /main/5 1996/08/21 15:50:29 drk $ */
  24. #ifndef _FeatureValue_h
  25. #define _FeatureValue_h
  26. //#include "Feature.h"
  27. #ifndef CDE_NEXT
  28. #else
  29. #include "dti_cc/cc_pvect.h"
  30. #endif
  31. #include <string.h>
  32. #if 0
  33. // SWM -- COMMENT THIS OUT -- MMDB utility/funcs.h defines this
  34. #ifdef _IBMR2
  35. extern "C" int strcasecmp(const char*, const char*);
  36. #endif
  37. #endif
  38. class FeatureValue;
  39. class FeatureSet;
  40. class Expression;
  41. ostream &operator << (ostream &, const FeatureValue &);
  42. /* **************************************************************
  43. * class FeatureValue
  44. * ************************************************************** */
  45. class FeatureValueDimension;
  46. class FeatureValueExpression;
  47. class FeatureValueFeatureSet;
  48. class FeatureValueInt;
  49. class FeatureValueReal;
  50. class FeatureValueString;
  51. class FeatureValueSymbol;
  52. class FeatureValueArray;
  53. class FeatureValue
  54. {
  55. public:
  56. enum FeatureType { real, integer, string, symbol, expression, featureset, dimension, array } ;
  57. enum Unit { INCH=0, PICA=1, POINT=2, CM=3, PIXEL=4, NONE=5 };
  58. FeatureValue (FeatureType type) : f_type(type) {}
  59. virtual ~FeatureValue();
  60. const FeatureType type() const { return f_type ; }
  61. virtual FeatureValue *clone() const = 0; /* deep copy */
  62. virtual FeatureValue *evaluate() const;
  63. virtual unsigned int operator==(const FeatureValue &) const;
  64. virtual unsigned int operator==(const FeatureValueInt &) const;
  65. virtual unsigned int operator==(const FeatureValueString &) const;
  66. virtual unsigned int operator==(const FeatureValueReal &) const;
  67. virtual unsigned int operator==(const FeatureValueSymbol &) const;
  68. // produce a new object which is a merge with this object and the parameter
  69. virtual FeatureValue *merge(const FeatureValue &);
  70. // these should return a FeatureValue of the appropriate type
  71. // the operations are resolved vi double dispatching
  72. // all non-numeric types will use zero for their value unless they
  73. // are the denominator in a division operation, then they will use a
  74. // value of 1
  75. virtual FeatureValue *operator+(const FeatureValue&) const ;
  76. virtual FeatureValue *operator-(const FeatureValue&) const ;
  77. virtual FeatureValue *operator*(const FeatureValue&) const ;
  78. virtual FeatureValue *operator/(const FeatureValue&) const ;
  79. virtual FeatureValue *operator+(const FeatureValueInt&) const ;
  80. virtual FeatureValue *operator-(const FeatureValueInt&) const ;
  81. virtual FeatureValue *operator*(const FeatureValueInt&) const ;
  82. virtual FeatureValue *operator/(const FeatureValueInt&) const ;
  83. virtual FeatureValue *operator+(const FeatureValueReal&) const ;
  84. virtual FeatureValue *operator-(const FeatureValueReal&) const ;
  85. virtual FeatureValue *operator*(const FeatureValueReal&) const ;
  86. virtual FeatureValue *operator/(const FeatureValueReal&) const ;
  87. virtual FeatureValue *operator+(const FeatureValueDimension&) const ;
  88. virtual FeatureValue *operator-(const FeatureValueDimension&) const ;
  89. virtual FeatureValue *operator*(const FeatureValueDimension&) const ;
  90. virtual FeatureValue *operator/(const FeatureValueDimension&) const ;
  91. virtual FeatureValue *operator+(const FeatureValueExpression&) const ;
  92. virtual FeatureValue *operator-(const FeatureValueExpression&) const ;
  93. virtual FeatureValue *operator*(const FeatureValueExpression&) const ;
  94. virtual FeatureValue *operator/(const FeatureValueExpression&) const ;
  95. virtual FeatureValue *operator+(const int i) const ; /* returns this + i */
  96. virtual FeatureValue *operator-(const int i) const ; /* returns this - i */
  97. virtual FeatureValue *operator*(const int i) const ; /* returns this * i */
  98. virtual FeatureValue *operator/(const int i) const ; /* returns this / i */
  99. virtual FeatureValue *operator+(const float f) const ; /* returns this + f */
  100. virtual FeatureValue *operator-(const float f) const ; /* returns this - f */
  101. virtual FeatureValue *operator*(const float f) const ; /* returns this * f */
  102. virtual FeatureValue *operator/(const float f) const ; /* returns this / f */
  103. virtual FeatureValue *rdiv(const FeatureValue &) const ;
  104. virtual FeatureValue *rsub(const FeatureValue &) const ;
  105. virtual FeatureValue *rdiv(const FeatureValueInt &) const ;
  106. virtual FeatureValue *rsub(const FeatureValueInt &) const ;
  107. virtual FeatureValue *rdiv(const FeatureValueReal &) const ;
  108. virtual FeatureValue *rsub(const FeatureValueReal &) const ;
  109. virtual FeatureValue *rdiv(const FeatureValueExpression &) const ;
  110. virtual FeatureValue *rsub(const FeatureValueExpression &) const ;
  111. virtual FeatureValue *rdiv(const FeatureValueDimension &) const ;
  112. virtual FeatureValue *rsub(const FeatureValueDimension &) const ;
  113. virtual FeatureValue *rdiv(const int) const ;
  114. virtual FeatureValue *rsub(const int) const ;
  115. virtual FeatureValue *rdiv(const float) const ;
  116. virtual FeatureValue *rsub(const float) const ;
  117. virtual operator float() const;
  118. virtual operator int() const;
  119. virtual operator const char *() const;
  120. virtual operator const FeatureSet * () const ;
  121. virtual ostream &print(ostream&) const = 0;
  122. virtual FeatureValue *doConvert(Unit) const ;
  123. virtual FeatureValue *convertTo(Unit) const ;
  124. virtual FeatureValue *convertTo(Unit from,
  125. Unit to) const ;
  126. private:
  127. FeatureType f_type;
  128. };
  129. class FeatureValueReal : public FeatureValue
  130. {
  131. public:
  132. FeatureValueReal(float value)
  133. : FeatureValue(real), f_value(value)
  134. {}
  135. FeatureValueReal(const FeatureValueReal &);
  136. virtual FeatureValue *clone() const; /* deep copy */
  137. // operators
  138. virtual unsigned int operator==(const FeatureValue &) const;
  139. virtual unsigned int operator==(const FeatureValueInt &) const;
  140. virtual unsigned int operator==(const FeatureValueString &) const;
  141. virtual unsigned int operator==(const FeatureValueReal &) const;
  142. virtual unsigned int operator==(const FeatureValueSymbol &) const;
  143. virtual FeatureValue *operator+(const FeatureValueInt&) const ;
  144. virtual FeatureValue *operator-(const FeatureValueInt&) const ;
  145. virtual FeatureValue *operator*(const FeatureValueInt&) const ;
  146. virtual FeatureValue *operator/(const FeatureValueInt&) const ;
  147. virtual FeatureValue *operator+(const FeatureValueReal&) const ;
  148. virtual FeatureValue *operator-(const FeatureValueReal&) const ;
  149. virtual FeatureValue *operator*(const FeatureValueReal&) const ;
  150. virtual FeatureValue *operator/(const FeatureValueReal&) const ;
  151. virtual FeatureValue *operator+(const FeatureValueDimension&) const ;
  152. virtual FeatureValue *operator-(const FeatureValueDimension&) const ;
  153. virtual FeatureValue *operator*(const FeatureValueDimension&) const ;
  154. virtual FeatureValue *operator/(const FeatureValueDimension&) const ;
  155. virtual FeatureValue *operator+(const FeatureValueExpression&) const ;
  156. virtual FeatureValue *operator-(const FeatureValueExpression&) const ;
  157. virtual FeatureValue *operator*(const FeatureValueExpression&) const ;
  158. virtual FeatureValue *operator/(const FeatureValueExpression&) const ;
  159. virtual FeatureValue *operator+(const FeatureValue&) const ;
  160. virtual FeatureValue *operator-(const FeatureValue&) const ;
  161. virtual FeatureValue *operator*(const FeatureValue&) const ;
  162. virtual FeatureValue *operator/(const FeatureValue&) const ;
  163. virtual FeatureValue *operator+(const int i) const ; /* returns this + i */
  164. virtual FeatureValue *operator-(const int i) const ; /* returns this - i */
  165. virtual FeatureValue *operator*(const int i) const ; /* returns this * i */
  166. virtual FeatureValue *operator/(const int i) const ; /* returns this / i */
  167. virtual FeatureValue *operator+(const float f) const ; /* returns this + f */
  168. virtual FeatureValue *operator-(const float f) const ; /* returns this - f */
  169. virtual FeatureValue *operator*(const float f) const ; /* returns this * f */
  170. virtual FeatureValue *operator/(const float f) const ; /* returns this / f */
  171. virtual FeatureValue *rdiv(const FeatureValue &) const ;
  172. virtual FeatureValue *rsub(const FeatureValue &) const ;
  173. virtual FeatureValue *rdiv(const FeatureValueInt &) const ;
  174. virtual FeatureValue *rsub(const FeatureValueInt &) const ;
  175. virtual FeatureValue *rdiv(const FeatureValueReal &) const ;
  176. virtual FeatureValue *rsub(const FeatureValueReal &) const ;
  177. virtual FeatureValue *rdiv(const FeatureValueExpression &) const ;
  178. virtual FeatureValue *rsub(const FeatureValueExpression &) const ;
  179. virtual FeatureValue *rdiv(const FeatureValueDimension &) const ;
  180. virtual FeatureValue *rsub(const FeatureValueDimension &) const ;
  181. virtual FeatureValue *rdiv(const int) const ;
  182. virtual FeatureValue *rsub(const int) const ;
  183. virtual FeatureValue *rdiv(const float) const ;
  184. virtual FeatureValue *rsub(const float) const ;
  185. virtual FeatureValue *convertTo(Unit) const ;
  186. virtual FeatureValue *convertTo(Unit from,
  187. Unit to) const ;
  188. virtual FeatureValue *doConvert(Unit) const ;
  189. virtual operator float() const;
  190. virtual operator int() const;
  191. virtual operator const char *() const;
  192. virtual ostream& print(ostream&) const;
  193. private:
  194. float f_value ;
  195. };
  196. class FeatureValueInt : public FeatureValue
  197. {
  198. public:
  199. FeatureValueInt(int value)
  200. : FeatureValue(integer), f_value(value)
  201. {}
  202. FeatureValueInt(const FeatureValueInt &);
  203. virtual FeatureValue *clone() const; /* deep copy */
  204. // operators
  205. virtual unsigned int operator==(const FeatureValue &) const;
  206. virtual unsigned int operator==(const FeatureValueInt &) const;
  207. virtual unsigned int operator==(const FeatureValueString &) const;
  208. virtual unsigned int operator==(const FeatureValueReal &) const;
  209. virtual unsigned int operator==(const FeatureValueSymbol &) const;
  210. virtual FeatureValue *operator+(const FeatureValue&) const ;
  211. virtual FeatureValue *operator-(const FeatureValue&) const ;
  212. virtual FeatureValue *operator*(const FeatureValue&) const ;
  213. virtual FeatureValue *operator/(const FeatureValue&) const ;
  214. virtual FeatureValue *operator+(const FeatureValueInt&) const ;
  215. virtual FeatureValue *operator-(const FeatureValueInt&) const ;
  216. virtual FeatureValue *operator*(const FeatureValueInt&) const ;
  217. virtual FeatureValue *operator/(const FeatureValueInt&) const ;
  218. virtual FeatureValue *operator+(const FeatureValueReal&) const ;
  219. virtual FeatureValue *operator-(const FeatureValueReal&) const ;
  220. virtual FeatureValue *operator*(const FeatureValueReal&) const ;
  221. virtual FeatureValue *operator/(const FeatureValueReal&) const ;
  222. virtual FeatureValue *operator+(const FeatureValueDimension&) const ;
  223. virtual FeatureValue *operator-(const FeatureValueDimension&) const ;
  224. virtual FeatureValue *operator*(const FeatureValueDimension&) const ;
  225. virtual FeatureValue *operator/(const FeatureValueDimension&) const ;
  226. virtual FeatureValue *operator+(const FeatureValueExpression&) const ;
  227. virtual FeatureValue *operator-(const FeatureValueExpression&) const ;
  228. virtual FeatureValue *operator*(const FeatureValueExpression&) const ;
  229. virtual FeatureValue *operator/(const FeatureValueExpression&) const ;
  230. virtual FeatureValue *operator+(const int i) const ; /* returns this + i */
  231. virtual FeatureValue *operator-(const int i) const ; /* returns this - i */
  232. virtual FeatureValue *operator*(const int i) const ; /* returns this * i */
  233. virtual FeatureValue *operator/(const int i) const ; /* returns this / i */
  234. virtual FeatureValue *operator+(const float f) const ; /* returns this + f */
  235. virtual FeatureValue *operator-(const float f) const ; /* returns this - f */
  236. virtual FeatureValue *operator*(const float f) const ; /* returns this * f */
  237. virtual FeatureValue *operator/(const float f) const ; /* returns this / f */
  238. virtual FeatureValue *rdiv(const FeatureValue &) const ;
  239. virtual FeatureValue *rsub(const FeatureValue &) const ;
  240. virtual FeatureValue *rdiv(const FeatureValueInt &) const ;
  241. virtual FeatureValue *rsub(const FeatureValueInt &) const ;
  242. virtual FeatureValue *rdiv(const FeatureValueReal &) const ;
  243. virtual FeatureValue *rsub(const FeatureValueReal &) const ;
  244. virtual FeatureValue *rdiv(const FeatureValueExpression &) const ;
  245. virtual FeatureValue *rsub(const FeatureValueExpression &) const ;
  246. virtual FeatureValue *rdiv(const FeatureValueDimension &) const ;
  247. virtual FeatureValue *rsub(const FeatureValueDimension &) const ;
  248. virtual FeatureValue *rdiv(const int) const ;
  249. virtual FeatureValue *rsub(const int) const ;
  250. virtual FeatureValue *rdiv(const float) const ;
  251. virtual FeatureValue *rsub(const float) const ;
  252. virtual FeatureValue *convertTo(Unit) const ;
  253. virtual FeatureValue *convertTo(Unit from, Unit to) const ;
  254. virtual FeatureValue *doConvert(Unit) const ;
  255. virtual operator float() const;
  256. virtual operator int() const;
  257. virtual operator const char *() const;
  258. virtual ostream& print(ostream&) const;
  259. private:
  260. int f_value ;
  261. };
  262. class FeatureValueString : public FeatureValue
  263. {
  264. public:
  265. FeatureValueString(const char *value)
  266. : FeatureValue(string), f_value(value)
  267. {}
  268. FeatureValueString(const FeatureValueString &);
  269. ~FeatureValueString();
  270. virtual FeatureValue *clone() const ; /* deep copy */
  271. virtual unsigned int operator==(const FeatureValue &) const;
  272. virtual unsigned int operator==(const FeatureValueInt &) const;
  273. virtual unsigned int operator==(const FeatureValueString &) const;
  274. virtual unsigned int operator==(const FeatureValueReal &) const;
  275. virtual unsigned int operator==(const FeatureValueSymbol &) const;
  276. // ops for string concatenation
  277. // this -> operator+(const FeatureValueExpression&) evaluates
  278. // the argument and then call this -> operator+(const FeatureValue&).
  279. virtual FeatureValue *operator+(const FeatureValue&) const ;
  280. virtual FeatureValue *operator+(const FeatureValueExpression&) const ;
  281. // call FeatureValue::operator+ directly.
  282. virtual FeatureValue *operator+(const FeatureValueInt&) const ;
  283. virtual FeatureValue *operator+(const FeatureValueReal&) const ;
  284. virtual FeatureValue *operator+(const FeatureValueDimension&) const ;
  285. virtual FeatureValue *operator+(const int i) const ;
  286. virtual FeatureValue *operator+(const float f) const ;
  287. virtual operator float() const;
  288. virtual operator int() const;
  289. virtual operator const char *() const;
  290. virtual ostream& print(ostream&) const;
  291. private:
  292. #ifndef CDE_NEXT
  293. CC_String f_value ;
  294. #else
  295. CC_String f_value ;
  296. #endif
  297. };
  298. class FeatureValueSymbol : public FeatureValue
  299. {
  300. public:
  301. FeatureValueSymbol(const Symbol &value)
  302. : FeatureValue(symbol), f_value(value)
  303. {}
  304. FeatureValueSymbol(const FeatureValueSymbol&);
  305. virtual FeatureValue *clone() const ; /* deep copy */
  306. virtual unsigned int operator==(const FeatureValue &) const;
  307. virtual unsigned int operator==(const FeatureValueInt &) const;
  308. virtual unsigned int operator==(const FeatureValueString &) const;
  309. virtual unsigned int operator==(const FeatureValueReal &) const;
  310. virtual unsigned int operator==(const FeatureValueSymbol &) const;
  311. virtual operator float() const;
  312. virtual operator int() const;
  313. virtual operator const char *() const;
  314. virtual ostream& print(ostream&) const;
  315. private:
  316. Symbol f_value;
  317. };
  318. class FeatureValueExpression : public FeatureValue
  319. {
  320. public:
  321. FeatureValueExpression(Expression *);
  322. FeatureValueExpression(const FeatureValueExpression&);
  323. ~FeatureValueExpression();
  324. virtual FeatureValue *clone() const ; /* deep copy */
  325. virtual FeatureValue *evaluate() const;
  326. // operators
  327. virtual FeatureValue *operator+(const FeatureValue&) const ;
  328. virtual FeatureValue *operator-(const FeatureValue&) const ;
  329. virtual FeatureValue *operator*(const FeatureValue&) const ;
  330. virtual FeatureValue *operator/(const FeatureValue&) const ;
  331. virtual FeatureValue *operator+(const FeatureValueInt&) const ;
  332. virtual FeatureValue *operator-(const FeatureValueInt&) const ;
  333. virtual FeatureValue *operator*(const FeatureValueInt&) const ;
  334. virtual FeatureValue *operator/(const FeatureValueInt&) const ;
  335. virtual FeatureValue *operator+(const FeatureValueReal&) const ;
  336. virtual FeatureValue *operator-(const FeatureValueReal&) const ;
  337. virtual FeatureValue *operator*(const FeatureValueReal&) const ;
  338. virtual FeatureValue *operator/(const FeatureValueReal&) const ;
  339. virtual FeatureValue *operator+(const FeatureValueDimension&) const ;
  340. virtual FeatureValue *operator-(const FeatureValueDimension&) const ;
  341. virtual FeatureValue *operator*(const FeatureValueDimension&) const ;
  342. virtual FeatureValue *operator/(const FeatureValueDimension&) const ;
  343. virtual FeatureValue *operator+(const FeatureValueExpression&) const ;
  344. virtual FeatureValue *operator-(const FeatureValueExpression&) const ;
  345. virtual FeatureValue *operator*(const FeatureValueExpression&) const ;
  346. virtual FeatureValue *operator/(const FeatureValueExpression&) const ;
  347. virtual FeatureValue *operator+(const int i) const ; /* returns this + i */
  348. virtual FeatureValue *operator-(const int i) const ; /* returns this - i */
  349. virtual FeatureValue *operator*(const int i) const ; /* returns this * i */
  350. virtual FeatureValue *operator/(const int i) const ; /* returns this / i */
  351. virtual FeatureValue *operator+(const float f) const ; /* returns this + f */
  352. virtual FeatureValue *operator-(const float f) const ; /* returns this - f */
  353. virtual FeatureValue *operator*(const float f) const ; /* returns this * f */
  354. virtual FeatureValue *operator/(const float f) const ; /* returns this / f */
  355. virtual FeatureValue *rdiv(const FeatureValue &) const ;
  356. virtual FeatureValue *rsub(const FeatureValue &) const ;
  357. virtual FeatureValue *rdiv(const FeatureValueInt &) const ;
  358. virtual FeatureValue *rsub(const FeatureValueInt &) const ;
  359. virtual FeatureValue *rdiv(const FeatureValueReal &) const ;
  360. virtual FeatureValue *rsub(const FeatureValueReal &) const ;
  361. virtual FeatureValue *rdiv(const FeatureValueExpression &) const ;
  362. virtual FeatureValue *rsub(const FeatureValueExpression &) const ;
  363. virtual FeatureValue *rdiv(const FeatureValueDimension &) const ;
  364. virtual FeatureValue *rsub(const FeatureValueDimension &) const ;
  365. virtual FeatureValue *rdiv(const int) const ;
  366. virtual FeatureValue *rsub(const int) const ;
  367. virtual FeatureValue *rdiv(const float) const ;
  368. virtual FeatureValue *rsub(const float) const ;
  369. virtual operator float() const;
  370. virtual operator int() const;
  371. virtual operator const char *() const;
  372. virtual ostream& print(ostream&) const;
  373. private:
  374. Expression *f_value;
  375. };
  376. class FeatureValueFeatureSet : public FeatureValue
  377. {
  378. public:
  379. FeatureValueFeatureSet(FeatureSet *);
  380. FeatureValueFeatureSet(const FeatureValueFeatureSet&);
  381. ~FeatureValueFeatureSet();
  382. const FeatureSet *value() const { return f_value ; }
  383. virtual FeatureValue *evaluate() const;
  384. virtual FeatureValue *clone() const; /* deep copy */
  385. virtual FeatureValue *merge(const FeatureValue &f);
  386. virtual ostream& print(ostream&) const;
  387. virtual operator const FeatureSet *() const ;
  388. private:
  389. FeatureSet *f_value;
  390. };
  391. #ifndef CDE_NEXT
  392. typedef pointer_vector<FeatureValue> ArrayType;
  393. #else
  394. typedef pointer_vector<FeatureValue> ArrayType;
  395. #endif
  396. class FeatureValueArray: public FeatureValue, public ArrayType
  397. {
  398. public:
  399. FeatureValueArray(const char* array_name, int size);
  400. FeatureValueArray(const FeatureValueArray&);
  401. ~FeatureValueArray();
  402. virtual FeatureValue *evaluate() const;
  403. virtual FeatureValue *clone() const
  404. { return new FeatureValueArray(*this); }; /* deep copy */
  405. virtual ostream& print(ostream&) const;
  406. const char* name() { return f_name; };
  407. private:
  408. char* f_name;
  409. };
  410. class FeatureValueDimension : public FeatureValue
  411. {
  412. public:
  413. FeatureValueDimension(FeatureValue *value, const char* unit_string);
  414. FeatureValueDimension(FeatureValue *value, Unit unit);
  415. FeatureValueDimension(float value, const char* unit_string) ;
  416. FeatureValueDimension(float value, Unit unit) :
  417. FeatureValue(dimension), f_value(0),
  418. f_cachedValue(value), f_unit(unit) {};
  419. FeatureValueDimension(const FeatureValueDimension&);
  420. ~FeatureValueDimension();
  421. virtual FeatureValue *clone() const; /* deep copy */
  422. virtual FeatureValue *evaluate() const ;
  423. // operators
  424. virtual FeatureValue *operator+(const FeatureValue&) const ;
  425. virtual FeatureValue *operator-(const FeatureValue&) const ;
  426. virtual FeatureValue *operator*(const FeatureValue&) const ;
  427. virtual FeatureValue *operator/(const FeatureValue&) const ;
  428. virtual FeatureValue *operator+(const FeatureValueInt&) const ;
  429. virtual FeatureValue *operator-(const FeatureValueInt&) const ;
  430. virtual FeatureValue *operator*(const FeatureValueInt&) const ;
  431. virtual FeatureValue *operator/(const FeatureValueInt&) const ;
  432. virtual FeatureValue *operator+(const FeatureValueReal&) const ;
  433. virtual FeatureValue *operator-(const FeatureValueReal&) const ;
  434. virtual FeatureValue *operator*(const FeatureValueReal&) const ;
  435. virtual FeatureValue *operator/(const FeatureValueReal&) const ;
  436. virtual FeatureValue *operator+(const FeatureValueDimension&) const ;
  437. virtual FeatureValue *operator-(const FeatureValueDimension&) const ;
  438. virtual FeatureValue *operator*(const FeatureValueDimension&) const ;
  439. virtual FeatureValue *operator/(const FeatureValueDimension&) const ;
  440. virtual FeatureValue *operator+(const FeatureValueExpression&) const ;
  441. virtual FeatureValue *operator-(const FeatureValueExpression&) const ;
  442. virtual FeatureValue *operator*(const FeatureValueExpression&) const ;
  443. virtual FeatureValue *operator/(const FeatureValueExpression&) const ;
  444. virtual FeatureValue *operator+(const int i) const ; /* returns this + i */
  445. virtual FeatureValue *operator-(const int i) const ; /* returns this - i */
  446. virtual FeatureValue *operator*(const int i) const ; /* returns this * i */
  447. virtual FeatureValue *operator/(const int i) const ; /* returns this / i */
  448. virtual FeatureValue *operator+(const float f) const ; /* returns this + f */
  449. virtual FeatureValue *operator-(const float f) const ; /* returns this - f */
  450. virtual FeatureValue *operator*(const float f) const ; /* returns this * f */
  451. virtual FeatureValue *operator/(const float f) const ; /* returns this / f */
  452. virtual FeatureValue *rdiv(const FeatureValue &) const ;
  453. virtual FeatureValue *rsub(const FeatureValue &) const ;
  454. virtual FeatureValue *rdiv(const FeatureValueInt &) const ;
  455. virtual FeatureValue *rsub(const FeatureValueInt &) const ;
  456. virtual FeatureValue *rdiv(const FeatureValueReal &) const ;
  457. virtual FeatureValue *rsub(const FeatureValueReal &) const ;
  458. virtual FeatureValue *rdiv(const FeatureValueExpression &) const ;
  459. virtual FeatureValue *rsub(const FeatureValueExpression &) const ;
  460. virtual FeatureValue *rdiv(const FeatureValueDimension &) const ;
  461. virtual FeatureValue *rsub(const FeatureValueDimension &) const ;
  462. virtual FeatureValue *rdiv(const int) const ;
  463. virtual FeatureValue *rsub(const int) const ;
  464. virtual FeatureValue *rdiv(const float) const ;
  465. virtual FeatureValue *rsub(const float) const ;
  466. virtual FeatureValue *convertTo(Unit) const ;
  467. virtual FeatureValue *convertTo(Unit from, Unit to) const ;
  468. virtual FeatureValue *doConvert(Unit) const ;
  469. virtual operator float() const;
  470. virtual operator int() const;
  471. virtual operator const char *() const;
  472. float getValue(Unit);
  473. FeatureValue *value() { return f_value ; }
  474. Unit unit() { return f_unit ; }
  475. virtual ostream& print(ostream&) const;
  476. private:
  477. FeatureValue *f_value ;
  478. float f_cachedValue;
  479. Unit f_unit ;
  480. private:
  481. float convert(float y, Unit dimensionOfy, Unit dimensionOfReturn);
  482. Unit convertToUnit(const char*);
  483. };
  484. #endif /* _FeatureValue_h */
  485. /* DO NOT ADD ANY LINES AFTER THIS #endif */