ISeeML  1.0
Object.hpp
1 //
2 // Definition of iSeeML::Object, superclass of every other ISeeML
3 // objects' class.
4 //
5 
6 
7 // To only include this definition once
8 #ifndef ISEEML_OBJECT_HH
9 #define ISEEML_OBJECT_HH
10 
11 
12 // === Inclusion of standart definitions ===
13 // Some classes need the definition of input/output streams.
14 #include <iostream>
15 using namespace std; // to avoid writing std::...
16 // Some classes need the definition of strings.
17 #include <string>
18 // Some classes need the definition of mathematical functions.
19 #define _USE_MATH_DEFINES
20 #include <math.h>
21 // === Inclusion of iSeeML' definitions ===
22 // Definition of relations between ISeeML compilation flags.
23 #include <iSeeML/CompilerFlags.h>
24 // Definition of ISeeML' namespaces.
25 #include <iSeeML/NameSpaces.hpp>
26 
27 
48  // === Object's Fields ==========================================
49 
55  static const double smallDouble;
56 
61  static const string ClassName;
62 
63 public:
64  // === Constructors and Destructors =============================
65 
67  virtual ~Object() {}
68 
69 
70  // === Description Methods ======================================
71 
85  virtual const string className() const { return ClassName; }
86 
87 
100  virtual iSeeML::Object& clone() const = 0;
101 
102 
111  virtual void writeTo(ostream& O) const = 0;
112 
113 protected:
125  virtual int algDimension() const { return 0; }
126 
142  virtual double algCoord(const int) const {
143 #ifdef ISEEML_CHECK_OBJECT_PRECOND
144  cerr << ClassName << "::algCoord: empty algebraic vector,"
145  << endl << " returning zero..." << endl;
146 #endif
147  return 0; }
148 
161  virtual void algWriteTo(ostream& O) const {
162  int i; O << '('; for(i = 1; i <= algDimension(); i++)
163  O << algCoord(i) << (i == algDimension() ? ")" : ", "); }
164 
165  // === Modification Methods =====================================
166 
167  // === Operators ================================================
168 
169 public:
170  // === Various Methods ==========================================
171 
181  bool sameClass(const iSeeML::Object& other)
182  { return( className() == other.className() ); }
183 
184 
195  template <class T>
196  static const T& min(const T& a, const T& b)
197  { return( a < b ? a : b ); }
198 
209  template <class T>
210  static const T& max(const T& a, const T& b)
211  { return( a > b ? a : b ); }
212 
213 
220  static double sqr(const double& x) { return( x * x ); }
221 
222 
232  static double mod2pi(const double& theta)
233  { double res = theta; const double PIx2 = 2 * M_PI;
234  while (res > M_PI) res -= PIx2;
235  while (res <= - M_PI) res += PIx2; return res; }
236 
243  static double rad2deg(const double& theta)
244  { return theta * 180 / M_PI; }
245 
252  static double deg2rad(const double& theta)
253  { return theta * M_PI / 180; }
254 
255 
264  static bool isPositive(const double& x)
265  { return( x > smallDouble ); }
266 
278  static bool isNegative(const double& x)
279  { return( isPositive(- x) ); }
280 
288  static bool isZero(const double& x)
289  { return( fabs(x) < smallDouble ); }
290 
291 
301  static int sign(const double& x)
302  { return( isZero(x) ? 0 : ( x < 0 ? -1 : 1) ); }
303 
304 }; // end of class iSeeML::Object
305 
306 
319 inline ostream& operator<<(ostream& O, const iSeeML::Object& o)
320 { o.writeTo(O); return O; }
321 
322 
323 #endif // end of definition
324 
Definition of relations between ISeeML compilation flags.
This class is the base class of ISeeML: every class of ISeeML inherits this one.
Definition: Object.hpp:47
static int sign(const double &x)
Method giving the sign of a double.
Definition: Object.hpp:301
STL namespace.
virtual void writeTo(ostream &O) const =0
Description method, writing a description of the object into a given output stream.
static const T & min(const T &a, const T &b)
Method giving the minimum of two elements.
Definition: Object.hpp:196
virtual void algWriteTo(ostream &O) const
Description method for algebraic vectors, writing this vector in a given output stream: coordinates f...
Definition: Object.hpp:161
virtual const string className() const
Description method, giving the object&#39;s class name.
Definition: Object.hpp:85
static bool isPositive(const double &x)
Method telling whether a double is strictly positive.
Definition: Object.hpp:264
static double rad2deg(const double &theta)
Method transforming an angle in radian, with between -1 (excluded) and 1 (included), into its equivalent in degree, i.e.
Definition: Object.hpp:243
static bool isNegative(const double &x)
Method telling whether a double is strictly negative.
Definition: Object.hpp:278
virtual int algDimension() const
Description method for algebraic vectors, giving the dimension of the containing space (default is ze...
Definition: Object.hpp:125
static double deg2rad(const double &theta)
Method transforming an angle in degree, with between -1 (excluded) and 1 (included), into its equivalent in radian, i.e.
Definition: Object.hpp:252
static double sqr(const double &x)
Method giving the square of a double.
Definition: Object.hpp:220
bool sameClass(const iSeeML::Object &other)
Method verifying that a given object has the same type (same class name) than the current one...
Definition: Object.hpp:181
ostream & operator<<(ostream &O, const iSeeML::Object &o)
Modification method, writing a description of a ISeeML object in a given output stream.
Definition: Object.hpp:319
static bool isZero(const double &x)
Method comparing a double to zero.
Definition: Object.hpp:288
static const T & max(const T &a, const T &b)
Method giving the maximum of two elements.
Definition: Object.hpp:210
virtual ~Object()
This virtual class needs a virtual destructor.
Definition: Object.hpp:67
virtual double algCoord(const int) const
Description method for algebraic vectors, giving coordinate of given index for this vector...
Definition: Object.hpp:142
static double mod2pi(const double &theta)
Method giving the angle between - (excluded) and (included), which is equal to a given angle modulo...
Definition: Object.hpp:232