C++ main module for emicrom Package  1.0
CORE_Object.h
Go to the documentation of this file.
1 #ifndef CORE_Object_H
2 #define CORE_Object_H
3 
4 
5 //include the shared pointer facilities
6 #include "CORE_Pointers.h"
7 
8 //include the types
9 #include "types.h"
10 
11 
12 // include the standart libraries
13 //this include is not valgrind safe !
14 #include <iostream>
15 #include <iomanip>
16 
17 #include <fstream>
18 #include <stdio.h>
19 #include <cxxabi.h>
20 #include <limits>
21 #include <map>
22 #include <vector>
23 
26 
53 class CORE_Object { // class Object
54 
55  // ATTRIBUTES
56 
57 
58 
59 
60 private:
61 
62  //output stream
63  static SP::CORE_Out OUT;
64 
65  //the profiler
66  static SP::CORE_Thread THREAD;
67 
73  //for registering the memory obejct created in memory
74  //list of object created
75  static map<tString,CORE_Object*> mObjects;
76 
77 
78  // ASSOCIATIONS
79 private:
80 
81  //pointer the the weak shared pointer to whih the object is in
82  WP::CORE_Object mThis;
83 
84 protected:
89  void setThis(SP::CORE_Object p) {
90  mThis=p;
92  };
93 public:
97  void getSharedPointer(SP::CORE_Object& p) {
98  p=mThis.lock();
99  };
103  void getSharedPointer(SPC::CORE_Object& p) const {
104  p=mThis.lock();
105  }
106 private:
110  SP::CORE_Object getThis() {
111  SP::CORE_Object ptr(mThis);
112  return ptr;
113  };
117  SPC::CORE_Object getThis() const {
118  SPC::CORE_Object ptr(mThis);
119  return ptr;
120  };
121 
122 
123 protected:
124  // CONSTRUCTORS
127  CORE_Object();
128 
129  // DESTRUCTORS
132  virtual ~CORE_Object();
133 
134 
135 
136  // for boost smart pointer using
137  class Delete;
138  friend class Delete;
141  class Delete {
142  public:
145  void operator()(const CORE_Object* p){delete p;}
146  };
147 
148 
149  //NEW Methods
150 
151  //used after New method
152  //=====================
153 protected:
157  virtual void toDoAfterThisSetting() {
158  };
159 
160  // SET Methods
161 public:
165  inline static void setIsMemoryChecked(const tBoolean& v) {
166  mIsMemoryTesting=v;
167  }
168 
172  inline static void setOut(SP::CORE_Out out) {
173  if (out.get()!=null) OUT=out;
174  }
177  inline static void resetOut() {
178  OUT.reset();
179  }
180 
184  inline static void setThread(SP::CORE_Thread thread) {
185  if (thread.get()!=null) THREAD=thread;
186  }
189  inline static void resetThread() {
190  THREAD.reset();
191  }
192 
193  // GET
194 public:
198  inline static CORE_Out& out() {
199  return *OUT.get();
200  }
204  inline static SP::CORE_Out getOut() {
205  return OUT;
206  }
207 
211  inline static CORE_Thread& getThread() {
212  return *THREAD.get();
213  }
214 
215 
219  inline static const tBoolean& isMemoryChecked() {
220  return mIsMemoryTesting;
221  }
222 
223 public:
227  tString getClassName() const;
228 
233  static inline tString getClassName(const tString& identityString) {
234  return identityString.substr(0,identityString.find("@"));
235  };
236 
241  inline tString getIdentityString() const {
242  tString str(getClassName());
243  str.append("@");
244  str+=pointer2String(this);
245  return str;
246  };
247 
252  return pointer2String(this);
253  };
254 
258  template<class T>
260  return (dynamic_cast<const T*>(this)!=null);
261  }
266  inline tBoolean isInstanceOf(const tString& name) const {
267  return (getIdentityString().find(name)!=tString::npos);
268  }
269 
273  template <class T>
274  inline static tString getTypeName() {
275  const char *name=typeid(T).name();
276  char *v=__cxxabiv1::__cxa_demangle(name,NULL,NULL,NULL);
277  tString type(v);
278  free(v);
279  return type;
280  };
281 
282 
286  inline static tBoolean is64Architecture() {
287  return (sizeof(long double)==16);
288  }
289 
293  inline static tBoolean is32Architecture() {
294  return (sizeof(long double)==8);
295  }
296 
297 
298 
299 
300 
301 public:
307  static tString pointer2String(const void *obj);
308 
309 public:
310 
311 
312 
316  static void printObjectsInMemory(ostream& f);
319  inline static void printObjectsInMemory() {
320  printObjectsInMemory(cout);
321  }
322 
326  virtual tString toString() const {
327  return getIdentityString();
328  }
329 
330  //get the max of types
331 
335  inline static tChar getMaxChar() {
336  return std::numeric_limits<tChar>::max();
337  }
341  inline static tChar getMinChar() {
342  return std::numeric_limits<tChar>::min();
343  }
344 
348  inline static tUChar getMaxUChar() {
349  return std::numeric_limits<tUChar>::max();
350  }
354  inline static tUChar getMinUChar() {
355  return std::numeric_limits<tUChar>::min();
356  }
357 
361  inline static tSInt getMaxSInt() {
362  return std::numeric_limits<tSInt>::max();
363  }
367  inline static tSInt getMinSInt() {
368  return std::numeric_limits<tSInt>::min();
369  }
373  inline static tUSInt getMaxUSInt() {
374  return std::numeric_limits<tUSInt>::max();
375  }
379  inline static tUSInt getMinUSInt() {
380  return std::numeric_limits<tUSInt>::min();
381  }
382 
386  inline static tInt getMaxInt() {
387  return std::numeric_limits<tInt>::max();
388  }
389 
393  inline static tInt getMinInt() {
394  return std::numeric_limits<tInt>::min();
395  }
399  inline static tUInt getMaxUInt() {
400  return std::numeric_limits<tUInt>::max();
401  }
405  inline static tUInt getMinUInt() {
406  return std::numeric_limits<tUInt>::min();
407  }
408 
412  inline static tLInt getMaxLInt() {
413  return std::numeric_limits<tLInt>::max();
414  }
418  inline static tLInt getMinLInt() {
419  return std::numeric_limits<tLInt>::min();
420  }
421 
425  inline static tULInt getMaxULInt() {
426  return std::numeric_limits<tULInt>::max();
427  }
431  inline static tULInt getMinULInt() {
432  return std::numeric_limits<tULInt>::min();
433  }
434 
438  inline static tLLInt getMaxLLInt() {
439  return std::numeric_limits<tLLInt>::max();
440  }
444  inline static tLLInt getMinLLInt() {
445  return std::numeric_limits<tLLInt>::min();
446  }
447 
451  inline static tULLInt getMaxULLInt() {
452  return std::numeric_limits<tULLInt>::max();
453  }
457  inline static tULLInt getMinULLInt() {
458  return std::numeric_limits<tULLInt>::min();
459  }
460 
464  inline static tFloat getMaxFloat() {
465  return std::numeric_limits<tFloat>::max();
466  }
470  inline static tFloat getMinFloat() {
471  return std::numeric_limits<tFloat>::min();
472  }
476  template<class T>
477  inline static T getEpsilon() {
478  return std::numeric_limits<T>::epsilon();
479  }
483  template<class T>
484  inline static T getInfinity() {
485  return std::numeric_limits<T>::infinity();
486  }
487 
491  inline static tFloat getFloatEpsilon() {
492  return getEpsilon<tFloat>();
493  }
497  inline static tFloat getFloatInfinity() {
498  return getInfinity<tFloat>();
499  }
503  inline static tDouble getMaxDouble() {
504  return std::numeric_limits<tDouble>::max();
505  }
509  inline static tDouble getMinDouble() {
510  return std::numeric_limits<tDouble>::min();
511  }
515  inline static tDouble getDoubleInfinity() {
516  return getInfinity<tFloat>();
517  }
521  inline static tDouble getDoubleEpsilon() {
522  return getEpsilon<tDouble>();
523  }
527  inline static tLDouble getMinLDouble() {
528  return std::numeric_limits<tLDouble>::min();
529  }
533  inline static tLDouble getMaxLDouble() {
534  return std::numeric_limits<tLDouble>::max();
535  }
539  inline static tLDouble getLDoubleEpsilon() {
540  return getEpsilon<tLDouble>();
541  }
545  inline static tDouble getLDoubleInfinity() {
546  return getInfinity<tLDouble>();
547  }
548 
549 
553  inline static tIndex getMaxIndex() {
554  return std::numeric_limits<tIndex>::max();
555  }
559  inline static tIndex getMinIndex() {
560  return std::numeric_limits<tIndex>::min();
561  }
565  inline static tUIndex getMaxUIndex() {
566  return std::numeric_limits<tUIndex>::max();
567  }
571  inline static tUIndex getMinUIndex() {
572  return std::numeric_limits<tUIndex>::min();
573  }
574 
578  static tFlag getMaxFlag() {
579  return std::numeric_limits<tFlag>::max();
580  }
584  inline static tFlag getMinFlag() {
585  return std::numeric_limits<tFlag>::min();
586  }
590  inline static tUInteger getMaxUInteger() {
591  return std::numeric_limits<tUInteger>::max();
592  }
596  inline static tUInteger getMinUInteger() {
597  return std::numeric_limits<tUInteger>::min();
598  }
602  inline static tInteger getMaxInteger() {
603  return std::numeric_limits<tInteger>::max();
604  }
608  inline static tInteger getMinInteger() {
609  return std::numeric_limits<tInteger>::min();
610  }
614  inline static tReal getMaxReal() {
615  return std::numeric_limits<tReal>::max();
616  }
620  inline static tReal getMinReal() {
621  return std::numeric_limits<tReal>::min();
622  }
626  inline static tReal getRealEpsilon() {
627  return getEpsilon<tReal>();
628  }
629 
633  inline static tReal getRealInfinity() {
634  return getInfinity<tReal>();
635  }
636 
640  template<class T>
641  inline static T computeEpsilon() {
642  T eps=getEpsilon<T>();
643  int exp=(int) -(log(eps)/(3.*log(10.)));
644  eps*=pow(10.,exp);
645  return eps;
646  }
647 
648  // print method for the defined type
649  // ==================================
650 
656  friend ostream& operator << (ostream& out,const CORE_Object& obj) {
657  out << obj.toString();
658  return out;
659  };
660 
661 
662 
663 
664 
665 };
666 
667 #endif
static tUSInt getMinUSInt()
get the min value for tUSInt type
Definition: CORE_Object.h:379
static SP::CORE_Out OUT
Definition: CORE_Object.h:63
This class describes a program routine analyser.
Definition: CORE_Thread.h:20
#define tLDouble
Definition: types.h:54
static tDouble getMinDouble()
get the min value for tDouble type
Definition: CORE_Object.h:509
#define tDouble
Definition: types.h:52
static void setIsMemoryChecked(const tBoolean &v)
set if the memory checking is used
Definition: CORE_Object.h:165
static tFloat getMaxFloat()
get the max value for tFloat type
Definition: CORE_Object.h:464
void getSharedPointer(SPC::CORE_Object &p) const
get the shared pointer of this class into p
Definition: CORE_Object.h:103
static tUChar getMinUChar()
get the min value for tUChar type
Definition: CORE_Object.h:354
static T getEpsilon()
get the epsilon value for T type
Definition: CORE_Object.h:477
static tString getClassName(const tString &identityString)
return the class name of the object
Definition: CORE_Object.h:233
static tReal getRealInfinity()
get the infinity value
Definition: CORE_Object.h:633
#define tUInteger
Definition: types.h:91
void operator()(const CORE_Object *p)
operator to delete the class
Definition: CORE_Object.h:145
static T getInfinity()
get the infinity for T type
Definition: CORE_Object.h:484
static tReal getMaxReal()
get the max value for the real type
Definition: CORE_Object.h:614
static tBoolean is32Architecture()
return true if the machine is a 32 bits machine
Definition: CORE_Object.h:293
#define tFloat
Definition: types.h:50
void setThis(SP::CORE_Object p)
set this weak shared pointer called toDoAfterThis setting method
Definition: CORE_Object.h:89
static SP::CORE_Thread THREAD
Definition: CORE_Object.h:66
static tDouble getMaxDouble()
get the max value for tDouble type
Definition: CORE_Object.h:503
static tInteger getMaxInteger()
get the max value for the integer type
Definition: CORE_Object.h:602
static tFlag getMaxFlag()
get the max value for the tFlag type
Definition: CORE_Object.h:578
static tFlag getMinFlag()
get the min value for the tFlag type
Definition: CORE_Object.h:584
static tUIndex getMinUIndex()
get the min value for difference the array/vector indexing type
Definition: CORE_Object.h:571
#define tUSInt
Definition: types.h:28
static tUChar getMaxUChar()
get the max value for tUChar type
Definition: CORE_Object.h:348
static T computeEpsilon()
compute epsilon
Definition: CORE_Object.h:641
#define tBoolean
Definition: types.h:139
static tLDouble getMinLDouble()
get the min value for tLDouble type
Definition: CORE_Object.h:527
static tFloat getFloatEpsilon()
get the epsilon value for tFloat type
Definition: CORE_Object.h:491
static SP::CORE_Out getOut()
get the output
Definition: CORE_Object.h:204
#define tLInt
Definition: types.h:42
static tIndex getMinIndex()
get the min value for the array/vector indexing type
Definition: CORE_Object.h:559
static tLDouble getLDoubleEpsilon()
get the epsilon value for tLDouble type
Definition: CORE_Object.h:539
static tSInt getMinSInt()
get the min value for tSInt type
Definition: CORE_Object.h:367
static tLLInt getMinLLInt()
get the min value for tLLInt type
Definition: CORE_Object.h:444
tString getClassName() const
return the class name of the object
Definition: CORE_Object.cpp:70
#define null
Definition: types.h:144
tBoolean isInstanceOf(const tString &name) const
test if the object is an instance of className
Definition: CORE_Object.h:266
static void setOut(SP::CORE_Out out)
set the output stream
Definition: CORE_Object.h:172
CORE_Object()
build an object
Definition: CORE_Object.cpp:18
static void resetThread()
reset the output stream
Definition: CORE_Object.h:189
static void setThread(SP::CORE_Thread thread)
set the thread
Definition: CORE_Object.h:184
static tLLInt getMaxLLInt()
get the max value for tULInt type
Definition: CORE_Object.h:438
SPC::CORE_Object getThis() const
get this shared pointer associated to this class
Definition: CORE_Object.h:117
static tFloat getMinFloat()
get the min value for tFloat type
Definition: CORE_Object.h:470
static tLInt getMaxLInt()
get the max value for tLInt type
Definition: CORE_Object.h:412
static tBoolean mIsMemoryTesting
indicator to store all classes created and deleted only for debuging version
Definition: CORE_Object.h:72
static tInt getMaxInt()
get the max value for tInt type
Definition: CORE_Object.h:386
static void printObjectsInMemory()
print object in memory in the standart output
Definition: CORE_Object.h:319
static tUInt getMinUInt()
get the min value for tUInt type
Definition: CORE_Object.h:405
static tChar getMinChar()
get the min value for tChar type
Definition: CORE_Object.h:341
#define tULInt
Definition: types.h:39
static tChar getMaxChar()
get the max value for tChar type
Definition: CORE_Object.h:335
#define tLLInt
Definition: types.h:47
#define tIndex
Definition: types.h:129
static tString getTypeName()
get type name
Definition: CORE_Object.h:274
tString getIdentityString() const
return the identity string of the object of the form className_at_address
Definition: CORE_Object.h:241
static tReal getRealEpsilon()
get the eps which is the difference between 1 and the least value greater than 1 that is representabl...
Definition: CORE_Object.h:626
#define tSInt
Definition: types.h:30
static tULInt getMinULInt()
get the min value for tULInt type
Definition: CORE_Object.h:431
static tDouble getDoubleEpsilon()
get the epsilon value for tDouble type
Definition: CORE_Object.h:521
static tIndex getMaxIndex()
get the max value for the array/vector indexing type
Definition: CORE_Object.h:553
WP::CORE_Object mThis
Definition: CORE_Object.h:82
#define tUChar
Definition: types.h:20
static tULInt getMaxULInt()
get the max value for tULInt type
Definition: CORE_Object.h:425
static tLDouble getMaxLDouble()
get the max value for tLDouble type
Definition: CORE_Object.h:533
virtual ~CORE_Object()
destroy an object
Definition: CORE_Object.cpp:30
tString getPointerAddress() const
return the identity string of the object
Definition: CORE_Object.h:251
#define tUInt
Definition: types.h:33
SP::CORE_Object getThis()
get this shared pointer associated to this class
Definition: CORE_Object.h:110
static tUInteger getMaxUInteger()
get the max value for the unsigned integer type
Definition: CORE_Object.h:590
void getSharedPointer(SP::CORE_Object &p)
get the shared pointer of this class into p
Definition: CORE_Object.h:97
friend ostream & operator<<(ostream &out, const CORE_Object &obj)
print the class object
Definition: CORE_Object.h:656
static const tBoolean & isMemoryChecked()
get if the memory checking is used
Definition: CORE_Object.h:219
DEFINE_SPTR(CORE_Out)
static tULLInt getMaxULLInt()
get the max value for tULLInt type
Definition: CORE_Object.h:451
#define tUIndex
Definition: types.h:126
static tUIndex getMaxUIndex()
get the max value for difference the array/vector indexing type
Definition: CORE_Object.h:565
abstract base class for most classes.
Definition: CORE_Object.h:53
static tInteger getMinInteger()
get the min value for the integer type
Definition: CORE_Object.h:608
#define tString
Definition: types.h:135
virtual tString toString() const
return the string representation of the object node
Definition: CORE_Object.h:326
static tDouble getLDoubleInfinity()
get the infinity value for tDouble type
Definition: CORE_Object.h:545
static tDouble getDoubleInfinity()
get the infinity value for tFloat type
Definition: CORE_Object.h:515
#define tChar
Definition: types.h:23
static tLInt getMinLInt()
get the min value for tLInt type
Definition: CORE_Object.h:418
tBoolean isInstanceOf() const
test if the clas T is an instance of this class
Definition: CORE_Object.h:259
static CORE_Out & out()
get the output
Definition: CORE_Object.h:198
this class describes the output by default write on standart output
Definition: CORE_Out.h:22
static tString pointer2String(const void *obj)
return the string representation of a pointer
Definition: CORE_Object.cpp:79
static tUInteger getMinUInteger()
get the min value for the unsigned integer type
Definition: CORE_Object.h:596
virtual void toDoAfterThisSetting()
method called after setThis() method this method can oly be called once.
Definition: CORE_Object.h:157
static tUSInt getMaxUSInt()
get the max value for tUSInt type
Definition: CORE_Object.h:373
static tReal getMinReal()
get the min value for the real type
Definition: CORE_Object.h:620
#define tULLInt
Definition: types.h:45
static tULLInt getMinULLInt()
get the min value for tULLInt type
Definition: CORE_Object.h:457
static map< tString, CORE_Object * > mObjects
Definition: CORE_Object.h:75
static tInt getMinInt()
get the min value for tInt type
Definition: CORE_Object.h:393
#define tInt
Definition: types.h:35
static void resetOut()
reset the output stream
Definition: CORE_Object.h:177
static CORE_Thread & getThread()
get the profilier
Definition: CORE_Object.h:211
#define tReal
Definition: types.h:118
static tSInt getMaxSInt()
get the max value for tSInt type
Definition: CORE_Object.h:361
static tFloat getFloatInfinity()
get the infinity value for tFloat type
Definition: CORE_Object.h:497
static tUInt getMaxUInt()
get the max value for tUInt type
Definition: CORE_Object.h:399
#define tInteger
Definition: types.h:90
static tBoolean is64Architecture()
return true if the machine is a 64 bits machine
Definition: CORE_Object.h:286
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:141
#define tFlag
Definition: types.h:74