Initial commit.
[mappings.git] / mappings.h
1
2 ///////////////////////////////////////////////////////////////////////////
3 // This program is free software: you can redistribute it and/or modify  //
4 // it under the terms of the version 3 of the GNU General Public License //
5 // as published by the Free Software Foundation.                         //
6 //                                                                       //
7 // This program is distributed in the hope that it will be useful, but   //
8 // WITHOUT ANY WARRANTY; without even the implied warranty of            //
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      //
10 // General Public License for more details.                              //
11 //                                                                       //
12 // You should have received a copy of the GNU General Public License     //
13 // along with this program. If not, see <http://www.gnu.org/licenses/>.  //
14 //                                                                       //
15 // Written and (C) by Francois Fleuret                                   //
16 // Contact <francois.fleuret@idiap.ch> for comments & bug reports        //
17 ///////////////////////////////////////////////////////////////////////////
18
19 #ifndef MAPPINGS_H
20 #define MAPPINGS_H
21
22 #include <iostream>
23
24 using namespace std;
25
26 // We have a bunch of such classes inside
27 class Map;
28
29 class Mapping {
30   Map *f;
31
32   // We'll need this one from time to time, but nobody is supposed to
33   // use it from "outside"
34   Mapping(Map *g);
35
36 public:
37   // This is the variable
38   const static Mapping X;
39
40   // This build a non-defined Mapping. Everything is illegal on such a
41   // Mapping except delete, = and <<. All other operations will *crash*
42   Mapping();
43
44   // Cast from float to allow operations with constant values
45   Mapping(float x);
46
47   // Standard copy constructor and destructor
48   Mapping(const Mapping &s);
49   ~Mapping();
50
51   // Assignment
52   Mapping &operator = (const Mapping &m);
53
54   // Evaluation
55   float operator () (float x) const;
56
57   // Derivation
58   Mapping derivative() const;
59
60   // Composition of Mappings
61   Mapping compose(const Mapping &m) const;
62
63   // Standard operations
64   Mapping pow(int k) const;
65   Mapping mul(const Mapping &m) const;
66   Mapping div(const Mapping &m) const;
67   Mapping add(const Mapping &m) const;
68   Mapping sub(const Mapping &m) const;
69   Mapping neg() const;
70   Mapping sin() const;
71   Mapping cos() const;
72   Mapping log() const;
73   Mapping exp() const;
74
75   // Print the expression
76   void print(ostream &s) const;
77 };
78
79 // I guess we have all the ones we need?
80 Mapping operator + (const Mapping &m);
81 Mapping operator + (const Mapping &ml, const Mapping &mr);
82 Mapping operator - (const Mapping &m);
83 Mapping operator - (const Mapping &ml, const Mapping &mr);
84 Mapping operator * (const Mapping &ml, const Mapping &mr);
85 Mapping operator / (const Mapping &ml, const Mapping &mr);
86
87 // Be very careful with this operator, it has a lower precedence than
88 // +-*/
89 Mapping operator ^ (const Mapping &ml, int k);
90
91 // stream stuff, I dont have the courage to do the >>
92 ostream &operator << (ostream &o, const Mapping &m);
93
94 Mapping sin(const Mapping &m);
95 Mapping cos(const Mapping &m);
96 Mapping log(const Mapping &m);
97 Mapping exp(const Mapping &m);
98
99 #endif