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:
127  virtual int algDimension() const { return 0; }
128 
144  virtual double algCoord(const int i) const {
145  // doxygen needs a name for the parameter,
146  // the compiler will complain (warning)
147 #ifdef ISEEML_CHECK_OBJECT_PRECOND
148  cerr << ClassName << "::algCoord: empty algebraic vector,"
149  << endl << " returning zero for " << i << "th element..."
150  << endl;
151 #endif
152  return 0; }
153 
166  virtual void algWriteTo(ostream& O) const {
167  int i; O << '('; for(i = 1; i <= algDimension(); i++)
168  O << algCoord(i) << (i == algDimension() ? ")" : ", "); }
169 
170  // === Modification Methods =====================================
171 
172  // === Operators ================================================
173 
174 public:
175  // === Various Methods ==========================================
176 
186  bool sameClass(const iSeeML::Object& other)
187  { return( className() == other.className() ); }
188 
189 
200  template <class T>
201  static const T& min(const T& a, const T& b)
202  { return( a < b ? a : b ); }
203 
214  template <class T>
215  static const T& max(const T& a, const T& b)
216  { return( a > b ? a : b ); }
217 
229  template <class T>
230  static const T& between(const T& min, const T& value, const T& max)
231  { return( value > min ? (value < max ? value : max) : min ); }
232 
233 
240  static double sqr(const double& x) { return( x * x ); }
241 
242 
252  static double mod2pi(const double& theta) {
253  double res = theta; const double PIx2 = 2 * M_PI;
254  while (res > M_PI)
255  res -= PIx2;
256  while (res <= - M_PI)
257  res += PIx2;
258  return res;
259  } // end of static double mod2pi(const double&)
260 
267  static double rad2deg(const double& theta)
268  { return theta * 180 / M_PI; }
269 
276  static double deg2rad(const double& theta)
277  { return theta * M_PI / 180; }
278 
279 
288  static bool isPositive(const double& x)
289  { return( x > smallDouble ); }
290 
302  static bool isNegative(const double& x)
303  { return( isPositive(- x) ); }
304 
312  static bool isZero(const double& x)
313  { return( fabs(x) < smallDouble ); }
314 
315 
325  static int sign(const double& x)
326  { return( isZero(x) ? 0 : ( x < 0 ? -1 : 1) ); }
327 
328 }; // end of class iSeeML::Object
329 
330 
343 inline ostream& operator<<(ostream& O, const iSeeML::Object& o)
344 { o.writeTo(O); return O; }
345 
346 
347 #endif // end of definition
348 
iSeeML::Object::algWriteTo
virtual void algWriteTo(ostream &O) const
Description method for algebraic vectors, writing this vector in a given output stream: coordinates f...
Definition: Object.hpp:166
iSeeML::Object::algCoord
virtual double algCoord(const int i) const
Description method for algebraic vectors, giving coordinate of given index for this vector.
Definition: Object.hpp:144
iSeeML::Object::rad2deg
static double rad2deg(const double &theta)
Method transforming an angle in radian, with between -1 (excluded) and 1 (included),...
Definition: Object.hpp:267
iSeeML::Object::deg2rad
static double deg2rad(const double &theta)
Method transforming an angle in degree, with between -1 (excluded) and 1 (included),...
Definition: Object.hpp:276
iSeeML::Object::sqr
static double sqr(const double &x)
Method giving the square of a double.
Definition: Object.hpp:240
iSeeML::Object::sameClass
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:186
iSeeML::Object::operator<<
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:343
iSeeML::Object::~Object
virtual ~Object()
This virtual class needs a virtual destructor.
Definition: Object.hpp:67
iSeeML::Object::mod2pi
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:252
iSeeML::Object::max
static const T & max(const T &a, const T &b)
Method giving the maximum of two elements.
Definition: Object.hpp:215
iSeeML::Object::isZero
static bool isZero(const double &x)
Method comparing a double to zero.
Definition: Object.hpp:312
iSeeML::Object::min
static const T & min(const T &a, const T &b)
Method giving the minimum of two elements.
Definition: Object.hpp:201
iSeeML::Object
This class is the base class of ISeeML: every class of ISeeML inherits this one.
Definition: Object.hpp:47
CompilerFlags.h
iSeeML::Object::sign
static int sign(const double &x)
Method giving the sign of a double.
Definition: Object.hpp:325
iSeeML::Object::algDimension
virtual int algDimension() const
Description method for algebraic vectors, giving the dimension of the containing space (default is ze...
Definition: Object.hpp:127
iSeeML::Object::between
static const T & between(const T &min, const T &value, const T &max)
Method filtering a value wrt bounds.
Definition: Object.hpp:230
iSeeML::Object::isPositive
static bool isPositive(const double &x)
Method telling whether a double is strictly positive.
Definition: Object.hpp:288
iSeeML::Object::isNegative
static bool isNegative(const double &x)
Method telling whether a double is strictly negative.
Definition: Object.hpp:302
iSeeML::Object::writeTo
virtual void writeTo(ostream &O) const =0
Description method, writing a description of the object into a given output stream.
iSeeML::Object::className
virtual const string className() const
Description method, giving the object's class name.
Definition: Object.hpp:85