Minor corrections.
[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 builds a non-defined Mapping. Everything is illegal on such
41   // a Mapping except delete, = and <<. All other operations will
42   // *crash*
43   Mapping();
44
45   // Cast from float to allow operations with constant values
46   Mapping(float x);
47
48   // Standard copy constructor and destructor
49   Mapping(const Mapping &s);
50   ~Mapping();
51
52   // Assignment
53   Mapping &operator = (const Mapping &m);
54
55   // Evaluation
56   float operator () (float x) const;
57
58   // Derivation
59   Mapping derivative() const;
60
61   // Composition of Mappings
62   Mapping compose(const Mapping &m) const;
63
64   // Standard operations
65   Mapping pow(int k) const;
66   Mapping mul(const Mapping &m) const;
67   Mapping div(const Mapping &m) const;
68   Mapping add(const Mapping &m) const;
69   Mapping sub(const Mapping &m) const;
70   Mapping neg() const;
71   Mapping sin() const;
72   Mapping cos() const;
73   Mapping log() const;
74   Mapping exp() const;
75
76   // Print the expression
77   void print(ostream &s) const;
78 };
79
80 // I guess we have all the ones we need?
81 Mapping operator + (const Mapping &m);
82 Mapping operator + (const Mapping &ml, const Mapping &mr);
83 Mapping operator - (const Mapping &m);
84 Mapping operator - (const Mapping &ml, const Mapping &mr);
85 Mapping operator * (const Mapping &ml, const Mapping &mr);
86 Mapping operator / (const Mapping &ml, const Mapping &mr);
87
88 // Be very careful with this operator, it has a lower precedence than
89 // +-*/
90 Mapping operator ^ (const Mapping &ml, int k);
91
92 // stream stuff, I dont have the courage to do the >>
93 ostream &operator << (ostream &o, const Mapping &m);
94
95 Mapping sin(const Mapping &m);
96 Mapping cos(const Mapping &m);
97 Mapping log(const Mapping &m);
98 Mapping exp(const Mapping &m);
99
100 #endif