C++ main module for emicrom Package  1.0
CORE_Real.h
Go to the documentation of this file.
1 #ifndef CORE_REAL_H
2 #define CORE_REAL_H
3 
4 #include "CORE_Object.h"
5 #include "CORE_Pointers.h"
6 
7 #include <boost/lexical_cast.hpp>
8 
9 #include <boost/algorithm/string.hpp>
10 
24 
25 class CORE_Real : public CORE_Object {
26 
27  // ATTRIBUTES
28 private:
31 
32  //ASSOCIATIONS
33 
34 private:
35 
36 
37 
38  //CONSTRUCTOR
39 
40 public:
43  CORE_Real();
46  CORE_Real(const tReal& i);
47 
48  //DESTRUCTOR
49 protected:
52  virtual ~CORE_Real();
53 
54  // NEW METHODS
55 public:
59  static inline SP::CORE_Real New() {
60  SP::CORE_Real ret(new CORE_Real(),CORE_Real::Delete());
61  return ret;
62  };
67  static inline SP::CORE_Real New(const tReal& i) {
68  SP::CORE_Real ret(new CORE_Real(i),CORE_Real::Delete());
69  return ret;
70  };
71 
72  // SET METHODS
73 public:
77  inline void setReal(const tReal& r) {mReal=r;};
81  inline void setReal(const tString& r) {
82  setReal(parseReal(r));
83  };
84 
85  // GET METHODS
86 public:
90  tReal getReal() const {return mReal;};
91 
92  // OTHERS METHODS
93 public:
97  tString toString() const {return toString(mReal);};
98 
105  static tString toString(const tLDouble& i,const tFlag& n);
106 
113  static tString toString(const tDouble& i,const tFlag& n) {
114  return toString((tLDouble)i,n);
115  };
122  static tString toString(const tFloat& i,const tFlag& n) {
123  return toString((tLDouble)i,n);
124  };
125 
126 
127 
128 
133  inline static tString toString(const tFloat& r){
134  try {
135  return boost::lexical_cast<tString>(r);
136  } catch(std::exception& e) {
137  return "nan";
138  }
139  return "nan";
140  };
145  inline static tString toString(const tDouble& r){
146  try {
147  return boost::lexical_cast<tString>(r);
148  } catch(std::exception& e) {
149  return "nan";
150  }
151  return "nan";
152  };
157  inline static tString toString(const tLDouble& r) {
158  try {
159  return boost::lexical_cast<tString>(r);
160  } catch(std::exception& e) {
161  return "nan";
162  }
163  return "nan";
164  }
167  inline static tBoolean isReal(const tString& str) {
168  tString ret(str);
169  boost::trim(ret);
170  try {
171  boost::lexical_cast<tLDouble>(ret);
172  return true;
173  } catch(std::exception& e) {
174 
175  return false;
176  }
177  return false;
178 
179  }
186  static tString roundToString(const tReal& r,
187  const tReal& eps);
188 
195  static void shellSort(tReal a[],const tUIndex& N);
196 
201  inline static tLDouble parseReal(const tString& str) {
202  tString ret(str);
203  boost::trim(ret);
204  try {
205  return boost::lexical_cast<tLDouble>(ret);
206  } catch(std::exception& e) {
207 
208  return 0;
209  }
210  return 0;
211  }
212 
213 
221  static void solveEq2(const tReal& a,const tReal& b,const tReal& c,
222  vector<tReal>& x);
233  static void solveEq3(const tReal& a,const tReal& b,const tReal& c,const tReal& d,
234  vector<tReal>& x);
235 
236  // VIRTUAl METHODS
237 public:
238 
239  // PRIVATE METHODS
240 private:
241  inline static int sgn(const tReal& x) {
242  return ((x==0)?0:((x>0)?1:-1));
243  }
244  inline static tReal surround(const tReal& x) {
245  return sgn(x)*floor(0.5+fabs(x)/EPS)*EPS;
246  }
247 };
248 
249 #endif // end of ifndef
DEFINE_SPTR(CORE_Real)
#define tLDouble
Definition: types.h:54
#define tDouble
Definition: types.h:52
static SP::CORE_Real New(const tReal &i)
create a class Real
Definition: CORE_Real.h:67
tReal mReal
Definition: CORE_Real.h:29
static tString toString(const tFloat &r)
return the string associated to the real
Definition: CORE_Real.h:133
static tString roundToString(const tReal &r, const tReal &eps)
return the string associated to the real
Definition: CORE_Real.cpp:54
#define tFloat
Definition: types.h:50
static tString toString(const tDouble &r)
return the string associated to the real
Definition: CORE_Real.h:145
void setReal(const tString &r)
set the real to r
Definition: CORE_Real.h:81
static tLDouble parseReal(const tString &str)
return the real associated to the string
Definition: CORE_Real.h:201
static tReal surround(const tReal &x)
Definition: CORE_Real.h:244
#define tBoolean
Definition: types.h:139
static void solveEq3(const tReal &a, const tReal &b, const tReal &c, const tReal &d, vector< tReal > &x)
solve a 3nd order equation ax3+bx2+cx+d=0
Definition: CORE_Real.cpp:88
virtual ~CORE_Real()
delete class
Definition: CORE_Real.cpp:19
static void shellSort(tReal a[], const tUIndex &N)
sort the array tb a shell sorting method
Definition: CORE_Real.cpp:60
static SP::CORE_Real New()
create a class Real
Definition: CORE_Real.h:59
static tString toString(const tDouble &i, const tFlag &n)
return the string associated to the real
Definition: CORE_Real.h:113
void setReal(const tReal &r)
set the real to r
Definition: CORE_Real.h:77
#define tUIndex
Definition: types.h:126
static tString toString(const tFloat &i, const tFlag &n)
return the string associated to the real
Definition: CORE_Real.h:122
abstract base class for most classes.
Definition: CORE_Object.h:53
static tBoolean isReal(const tString &str)
return trie if the tsring is real
Definition: CORE_Real.h:167
#define tString
Definition: types.h:135
static tString toString(const tLDouble &r)
return the string associated to the real
Definition: CORE_Real.h:157
static void solveEq2(const tReal &a, const tReal &b, const tReal &c, vector< tReal > &x)
solve a 2nd order equation ax2+bx+c=0
Definition: CORE_Real.cpp:154
#define EPS
Definition: types.h:121
CORE_Real()
create a real
Definition: CORE_Real.cpp:13
tString toString() const
return the string associated to the real
Definition: CORE_Real.h:97
static int sgn(const tReal &x)
Definition: CORE_Real.h:241
#define tReal
Definition: types.h:118
tReal getReal() const
get the real
Definition: CORE_Real.h:90
static tString mSystemDigitalDot
Definition: CORE_Real.h:30
this class describes a real Attributes:
Definition: CORE_Real.h:25
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:141
#define tFlag
Definition: types.h:74