BALL  1.4.79
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
function.h
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 
5 #ifndef BALL_MATHS_FUNCTION_H
6 #define BALL_MATHS_FUNCTION_H
7 
8 #ifndef BALL_COMMON_H
9 # include <BALL/common.h>
10 #endif
11 
12 namespace BALL
13 {
14 
19  template <int constant_template>
21  {
22  public:
23 
25 
26 
29 
35  float operator () (float /* x */) const
36  {
37  return constant_template;
38  }
40 
41  };
42 
43 
48  template <typename DataType = float>
50  {
51  public:
52 
54 
55 
58 
62 
66 
69  MutableConstant(DataType constant);
70 
73  virtual ~MutableConstant();
74 
76 
79 
82  MutableConstant<DataType>& operator = (const MutableConstant<DataType>& constant);
83 
85 
88 
91  bool operator == (const MutableConstant<DataType>& constant) const;
92 
94 
97 
103  DataType operator () (const DataType& /* x */) const
104  {
105  return constant_;
106  }
107 
109 
112 
115  void setConstant(DataType constant)
116  {
117  constant_ = constant;
118  }
119 
123  const DataType& getConstant() const
124  {
125  return constant_;
126  }
127 
129 
130  protected:
131 
132  /*_ the constant
133  */
134  DataType constant_;
135 
136  };
137 
138 
142  template <typename First, typename Second, typename DataType = float>
143  class Addition
144  {
145  public:
146 
148 
149 
152 
155  Addition();
156 
160 
163  virtual ~Addition();
164 
166 
169 
173 
175 
178 
181  bool operator == (const Addition<First, Second, DataType>& addition) const;
182 
184 
187 
193  DataType operator () (const DataType& x) const
194  {
195  return (first_(x) + second_(x));
196  }
197 
199 
202 
205  void setFirst(const First& first)
206  {
207  first_ = first;
208  }
209 
213  First& getFirst()
214  {
215  return first_;
216  }
217 
220  const First& getFirst() const
221  {
222  return first_;
223  }
224 
227  void setSecond(const Second& second)
228  {
229  second_ = second;
230  }
231 
235  Second& getSecond()
236  {
237  return second_;
238  }
239 
242  const Second& getSecond() const
243  {
244  return second_;
245  }
246 
248 
249  protected:
250 
251  /*_ the first argument of the addition
252  */
253  First first_;
254 
255  /*_ the second argument of the addition
256  */
257  Second second_;
258 
259  };
260 
261 
264  template <typename First, typename Second, typename DataType = float>
266  {
267  public:
268 
270 
271 
274 
277  Subtraction();
278 
281  Subtraction(const Subtraction& subtraction);
282 
285  virtual ~Subtraction();
286 
288 
291 
295 
297 
300 
303  bool operator == (const Subtraction<First, Second, DataType>& subtraction) const;
304 
306 
309 
315  DataType operator () (const DataType& x) const
316  {
317  return (first_(x) - second_(x));
318  }
319 
321 
324 
327  void setFirst(const First& first)
328  {
329  first_ = first;
330  }
331 
335  First& getFirst()
336  {
337  return first_;
338  }
339 
342  void setSecond(const Second& second)
343  {
344  second_ = second;
345  }
346 
350  Second& getSecond()
351  {
352  return second_;
353  }
354 
356 
357  protected:
358 
359  /*_ the first argument of the subtraction
360  */
361  First first_;
362 
363  /*_ the second argument of the subtraction
364  */
365  Second second_;
366  };
367 
368 
371  template <typename First, typename Second, typename DataType = float>
372  class Product
373  {
374  public:
375 
377 
378 
381 
384  Product();
385 
388  Product(const Product& product);
389 
392  virtual ~Product();
393 
395 
398 
402 
404 
407 
410  bool operator == (const Product<First, Second, DataType>& product) const;
411 
413 
416 
422  DataType operator () (const DataType& x) const
423  {
424  return (first_(x) * second_(x));
425  }
426 
428 
431 
434  void setFirst(const First& first)
435  {
436  first_ = first;
437  }
438 
442  First& getFirst()
443  {
444  return first_;
445  }
446 
450  const First& getFirst() const
451  {
452  return first_;
453  }
454 
458  void setSecond(const Second& second)
459  {
460  second_ = second;
461  }
462 
466  Second& getSecond()
467  {
468  return second_;
469  }
470 
472 
473  protected:
474 
475  /*_ the first argument of the product
476  */
477  First first_;
478 
479  /*_ the second argument of the product
480  */
481  Second second_;
482 
483  };
484 
485 
488  template <typename First, typename Second, typename DataType = float>
489  class Division
490  {
491  public:
492 
494 
495 
498 
501  Division();
502 
505  Division(const Division& division);
506 
509  virtual ~Division();
510 
512 
515 
519 
521 
524 
527  bool operator == (const Division<First, Second, DataType>& division) const;
528 
530 
533 
540  DataType operator () (const DataType& x) const
541  {
542  DataType val = second_(x);
543  if (val != 0.0)
544  {
545  return (first_(x) / val);
546  }
547  else
548  {
549  throw Exception::DivisionByZero(__FILE__, __LINE__);
550  }
551  }
552 
554 
557 
560  void setFirst(const First& first)
561  {
562  first_ = first;
563  }
564 
568  First& getFirst()
569  {
570  return first_;
571  }
572 
575  void setSecond(const Second& second)
576  {
577  second_ = second;
578  }
579 
583  Second& getSecond()
584  {
585  return second_;
586  }
587 
589 
590  protected:
591 
592  /*_ the first argument of the division
593  */
594  First first_;
595 
596  /*_ the second argument of the division
597  */
598  Second second_;
599 
600  };
601 
602 
605  template <typename Function, typename DataType = float>
607  {
608  public:
609 
611 
612 
615 
618  Reciprocal();
619 
622  Reciprocal(const Reciprocal& reciprocal);
623 
626  virtual ~Reciprocal();
627 
629 
632 
635  Reciprocal<Function, DataType>& operator = (const Reciprocal<Function, DataType>& reciprocal);
636 
638 
641 
644  bool operator == (const Reciprocal<Function, DataType>& reciprocal) const;
645 
647 
650 
657  DataType operator () (const DataType& x) const
658  {
659  DataType val = function_(x);
660  if (val != 0)
661  {
662  return (1 / val);
663  }
664  else
665  {
666  throw Exception::DivisionByZero(__FILE__, __LINE__);
667  }
668  }
669 
671 
674 
677  void setFunction(const Function& function)
678  {
679  function_ = function;
680  }
681 
685  const Function& getFunction() const
686  {
687  return function_;
688  }
689 
691 
692  protected:
693 
694  /*_ the argument of the reciprocal
695  */
696  Function function_;
697 
698  };
699 
700 
703  template <typename Function, typename DataType = float>
705  {
706  public:
707 
709 
710 
713 
716  SquareFunction();
717 
720  SquareFunction(const SquareFunction& square);
721 
724  virtual ~SquareFunction();
725 
727 
730 
734 
736 
739 
742  bool operator == (const SquareFunction<Function, DataType>& square) const;
743 
745 
748 
754  DataType operator () (const DataType& x) const
755  {
756  DataType val = function_(x);
757  return val * val;
758  }
759 
761 
764 
767  void setFunction(const Function& function)
768  {
769  function_ = function;
770  }
771 
775  const Function& getFunction() const
776  {
777  return function_;
778  }
779 
781 
782  protected:
783 
784  /*_ the argument of the square
785  */
786  Function function_;
787 
788  };
789 
790 
793  template <typename Function, typename DataType = float>
795  {
796  public:
797 
799 
800 
803 
806  CubicFunction();
807 
810  CubicFunction(const CubicFunction& cubic);
811 
814  virtual ~CubicFunction();
815 
817 
820 
824 
826 
829 
832  bool operator == (const CubicFunction<Function, DataType>& cubic) const;
833 
835 
838 
844  DataType operator () (const DataType& x) const
845  {
846  DataType val = function_(x);
847  return val * val * val;
848  }
849 
851 
854 
857  void setFunction(const Function& function)
858  {
859  function_ = function;
860  }
861 
865  const Function& getFunction() const
866  {
867  return function_;
868  }
869 
871 
872  protected:
873 
874  /*_ the argument of the cubic
875  */
876  Function function_;
877 
878  };
879 
880 
883  template <typename Function, typename DataType = float>
885  {
886  public:
887 
889 
890 
893 
896  MutablePower();
897 
900  MutablePower(const MutablePower& power);
901 
904  virtual ~MutablePower();
905 
907 
910 
914 
916 
919 
922  bool operator == (const MutablePower<Function, DataType>& power) const;
923 
925 
928 
934  DataType operator () (const DataType& x) const
935  {
936  return pow(function_(x), exponent_);
937  }
938 
940 
943 
946  void setFunction(const Function& function)
947  {
948  function_ = function;
949  }
950 
954  const Function& getFunction() const
955  {
956  return function_;
957  }
958 
962  void setExponent(DataType exp);
963 
967  DataType getExponent() const;
968 
970 
971  protected:
972 
973  /*_ the argument of the power
974  */
975  Function function_;
976 
977  /*_ the exponent
978  */
979  DataType exponent_;
980  };
981 
982 
983  template <typename DataType>
986  : constant_(0)
987  {
988  }
989 
990  template <typename DataType>
993  (const MutableConstant<DataType>& constant)
994  : constant_(constant.constant_)
995  {
996  }
997 
998  template <typename DataType>
1001  : constant_(constant)
1002  {
1003  }
1004 
1005  template <typename DataType>
1006  BALL_INLINE
1008  {
1009  }
1010 
1011  template <typename DataType>
1012  BALL_INLINE
1014  (const MutableConstant<DataType>& constant)
1015  {
1016  constant_ = constant.constant_;
1017  return *this;
1018  }
1019 
1020  template <typename DataType>
1021  BALL_INLINE
1023  (const MutableConstant<DataType>& constant) const
1024  {
1025  return (constant_ == constant.constant_);
1026  }
1027 
1028 
1029  template <typename First, typename Second, typename DataType>
1030  BALL_INLINE
1032  : first_(),
1033  second_()
1034  {
1035  }
1036 
1037  template <typename First, typename Second, typename DataType>
1038  BALL_INLINE
1040  : first_(addition.first_),
1041  second_(addition.second_)
1042  {
1043  }
1044 
1045  template <typename First, typename Second, typename DataType>
1046  BALL_INLINE
1048  {
1049  }
1050 
1051  template <typename First, typename Second, typename DataType>
1052  BALL_INLINE
1054  {
1055  first_ = addition.first_;
1056  second_ = addition.second_;
1057  return *this;
1058  }
1059 
1060  template <typename First, typename Second, typename DataType>
1061  BALL_INLINE
1063  {
1064  return ((first_ == addition.first_) && (second_ == addition.second_));
1065  }
1066 
1067 
1068  template <typename First, typename Second, typename DataType>
1069  BALL_INLINE
1071  : first_(),
1072  second_()
1073  {
1074  }
1075 
1076  template <typename First, typename Second, typename DataType>
1077  BALL_INLINE
1079  : first_(subtraction.first_),
1080  second_(subtraction.second_)
1081  {
1082  }
1083 
1084  template <typename First, typename Second, typename DataType>
1085  BALL_INLINE
1087  {
1088  }
1089 
1090  template <typename First, typename Second, typename DataType>
1091  BALL_INLINE
1093  {
1094  first_ = subtraction.first_;
1095  second_ = subtraction.second_;
1096  return *this;
1097  }
1098 
1099  template <typename First, typename Second, typename DataType>
1100  BALL_INLINE
1102  {
1103  return ((first_ == subtraction.first_) && (second_ == subtraction.second_));
1104  }
1105 
1106 
1107  template <typename First, typename Second, typename DataType>
1108  BALL_INLINE
1110  : first_(),
1111  second_()
1112  {
1113  }
1114 
1115  template <typename First, typename Second, typename DataType>
1116  BALL_INLINE
1118  : first_(product.first_),
1119  second_(product.second_)
1120  {
1121  }
1122 
1123  template <typename First, typename Second, typename DataType>
1124  BALL_INLINE
1126  {
1127  }
1128 
1129  template <typename First, typename Second, typename DataType>
1130  BALL_INLINE
1132  {
1133  first_ = product.first_;
1134  second_ = product.second_;
1135  return *this;
1136  }
1137 
1138  template <typename First, typename Second, typename DataType>
1139  BALL_INLINE
1141  {
1142  return ((first_ == product.first_) && (second_ == product.second_));
1143  }
1144 
1145 
1146  template <typename First, typename Second, typename DataType>
1147  BALL_INLINE
1149  : first_(),
1150  second_()
1151  {
1152  }
1153 
1154  template <typename First, typename Second, typename DataType>
1155  BALL_INLINE
1157  : first_(division.first_),
1158  second_(division.second_)
1159  {
1160  }
1161 
1162  template <typename First, typename Second, typename DataType>
1163  BALL_INLINE
1165  {
1166  }
1167 
1168  template <typename First, typename Second, typename DataType>
1169  BALL_INLINE
1171  {
1172  first_ = division.first_;
1173  second_ = division.second_;
1174  return *this;
1175  }
1176 
1177  template <typename First, typename Second, typename DataType>
1178  BALL_INLINE
1180  {
1181  return ((first_ == division.first_) && (second_ == division.second_));
1182  }
1183 
1184 
1185  template <typename Function, typename DataType>
1186  BALL_INLINE
1188  : function_()
1189  {
1190  }
1191 
1192  template <typename Function, typename DataType>
1193  BALL_INLINE
1195  : function_(square.function_)
1196  {
1197  }
1198 
1199  template <typename Function, typename DataType>
1200  BALL_INLINE
1202  {
1203  }
1204 
1205  template <typename Function, typename DataType>
1206  BALL_INLINE
1208  {
1209  function_ = square.function_;
1210  return *this;
1211  }
1212 
1213  template <typename Function, typename DataType>
1214  BALL_INLINE
1216  {
1217  return (function_ == square.function_);
1218  }
1219 
1220 
1221  template <typename Function, typename DataType>
1222  BALL_INLINE
1224  : function_(0)
1225  {
1226  }
1227 
1228  template <typename Function, typename DataType>
1229  BALL_INLINE
1231  : function_(cubic.function_)
1232  {
1233  }
1234 
1235  template <typename Function, typename DataType>
1236  BALL_INLINE
1238  {
1239  }
1240 
1241  template <typename Function, typename DataType>
1242  BALL_INLINE
1244  {
1245  function_ = cubic.function_;
1246  return *this;
1247  }
1248 
1249  template <typename Function, typename DataType>
1250  BALL_INLINE
1252  {
1253  return (function_ == cubic.function_);
1254  }
1255 
1256 
1257  template <typename Function, typename DataType>
1258  BALL_INLINE
1260  : function_()
1261  {
1262  }
1263 
1264  template <typename Function, typename DataType>
1265  BALL_INLINE
1267  : function_(reciprocal.function_)
1268  {
1269  }
1270 
1271  template <typename Function, typename DataType>
1272  BALL_INLINE
1274  {
1275  }
1276 
1277  template <typename Function, typename DataType>
1278  BALL_INLINE
1280  {
1281  function_ = reciprocal.function_;
1282  return *this;
1283  }
1284 
1285  template <typename Function, typename DataType>
1286  BALL_INLINE
1288  {
1289  return (function_ == reciprocal.function_);
1290  }
1291 
1292 
1293  template <typename Function, typename DataType>
1294  BALL_INLINE
1296  : function_(0),
1297  exponent_(0)
1298  {
1299  }
1300 
1301  template <typename Function, typename DataType>
1302  BALL_INLINE
1304  : function_(power.function_),
1305  exponent_(power.exponent_)
1306  {
1307  }
1308 
1309  template <typename Function, typename DataType>
1310  BALL_INLINE
1312  {
1313  }
1314 
1315  template <typename Function, typename DataType>
1316  BALL_INLINE
1318  {
1319  function_ = power.function_;
1320  exponent_ = power.exponent_;
1321  return *this;
1322  }
1323 
1324  template <typename Function, typename DataType>
1325  BALL_INLINE
1327  {
1328  return ((exponent_ == power.exponent_)
1329  && (function_ == power.function_));
1330  }
1331 
1332  template <typename Function, typename DataType>
1333  BALL_INLINE
1335  {
1336  return exponent_;
1337  }
1338 
1339  template <typename Function, typename DataType>
1340  BALL_INLINE
1342  {
1343  exponent_ = exp;
1344  }
1345 } // namespace BALL
1346 
1347 #endif // BALL_MATHS_FUNCTION_H
Second & getSecond()
Definition: function.h:466
bool operator==(const SquareFunction< Function, DataType > &square) const
Definition: function.h:1215
void setFunction(const Function &function)
Definition: function.h:767
#define BALL_CREATE(name)
Definition: create.h:62
void setFirst(const First &first)
Definition: function.h:560
const Function & getFunction() const
Definition: function.h:865
Division< First, Second, DataType > & operator=(const Division< First, Second, DataType > &division)
Definition: function.h:1170
void setSecond(const Second &second)
Definition: function.h:342
Subtraction< First, Second, DataType > & operator=(const Subtraction< First, Second, DataType > &subtraction)
Definition: function.h:1092
bool operator==(const Addition< First, Second, DataType > &addition) const
Definition: function.h:1062
bool operator==(const Product< First, Second, DataType > &product) const
Definition: function.h:1140
virtual ~Reciprocal()
Definition: function.h:1273
Product< First, Second, DataType > & operator=(const Product< First, Second, DataType > &product)
Definition: function.h:1131
virtual ~Division()
Definition: function.h:1164
First first_
Definition: function.h:477
const Function & getFunction() const
Definition: function.h:685
bool operator==(const Subtraction< First, Second, DataType > &subtraction) const
Definition: function.h:1101
void setExponent(DataType exp)
Definition: function.h:1341
Second & getSecond()
Definition: function.h:235
const First & getFirst() const
Definition: function.h:450
void setFunction(const Function &function)
Definition: function.h:677
void setConstant(DataType constant)
Definition: function.h:115
Second second_
Definition: function.h:257
virtual ~MutableConstant()
Definition: function.h:1007
void setFirst(const First &first)
Definition: function.h:434
Second second_
Definition: function.h:598
const DataType & getConstant() const
Definition: function.h:123
virtual ~Addition()
Definition: function.h:1047
Second second_
Definition: function.h:481
void setSecond(const Second &second)
Definition: function.h:575
void setSecond(const Second &second)
Definition: function.h:458
virtual ~MutablePower()
Definition: function.h:1311
Function function_
Definition: function.h:975
const Second & getSecond() const
Definition: function.h:242
#define BALL_INLINE
Definition: debug.h:15
First & getFirst()
Definition: function.h:568
First first_
Definition: function.h:253
Second & getSecond()
Definition: function.h:583
bool operator==(const MutablePower< Function, DataType > &power) const
Definition: function.h:1326
virtual ~SquareFunction()
Definition: function.h:1201
void setFunction(const Function &function)
Definition: function.h:946
First first_
Definition: function.h:594
CubicFunction< Function, DataType > & operator=(const CubicFunction< Function, DataType > &cubic)
Definition: function.h:1243
SquareFunction< Function, DataType > & operator=(const SquareFunction< Function, DataType > &square)
Definition: function.h:1207
First & getFirst()
Definition: function.h:335
BALL_EXPORT bool operator==(const String &s1, const String &s2)
bool operator==(const CubicFunction< Function, DataType > &cubic) const
Definition: function.h:1251
bool operator==(const Division< First, Second, DataType > &division) const
Definition: function.h:1179
Second & getSecond()
Definition: function.h:350
First & getFirst()
Definition: function.h:213
void setSecond(const Second &second)
Definition: function.h:227
virtual ~Subtraction()
Definition: function.h:1086
const Function & getFunction() const
Definition: function.h:954
const Function & getFunction() const
Definition: function.h:775
void setFirst(const First &first)
Definition: function.h:327
First & getFirst()
Definition: function.h:442
virtual ~CubicFunction()
Definition: function.h:1237
void setFunction(const Function &function)
Definition: function.h:857
Addition< First, Second, DataType > & operator=(const Addition< First, Second, DataType > &addition)
Definition: function.h:1053
Reciprocal< Function, DataType > & operator=(const Reciprocal< Function, DataType > &reciprocal)
Definition: function.h:1279
Function function_
Definition: function.h:696
DataType exponent_
Definition: function.h:979
void setFirst(const First &first)
Definition: function.h:205
const First & getFirst() const
Definition: function.h:220
DataType getExponent() const
Definition: function.h:1334
Function function_
Definition: function.h:786
virtual ~Product()
Definition: function.h:1125
Function function_
Definition: function.h:876
bool operator==(const Reciprocal< Function, DataType > &reciprocal) const
Definition: function.h:1287
MutablePower< Function, DataType > & operator=(const MutablePower< Function, DataType > &power)
Definition: function.h:1317