C++ main module for gpm 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 #include "CORE_Pointers.h"
5 
6 #include "types.h"
7 
8 // std::cout with valgrind std::cout will cause "still reachable" error
9 //
10 #include <iostream>
11 
12 
13 #include <fstream>
14 #include <stdio.h>
15 #include <cxxabi.h>
16 #include <limits.h>
17 
18 #include <map>
19 #include <vector>
20 
30 class CORE_Object { // class Object
31 
32  // ATTRIBUTES
33 public:
39 
40 
41 private:
42  static map<tString,CORE_Object*> mObjects;
43  static map<tString,int> mObjectsNumber;
44 
45 
46 
47 
48 
49  static ostream *mOutput;
50 
51  // ASSOCIATIONS
52 private:
53  WP::CORE_Object mThis;
54 protected:
58  void setThis(SP::CORE_Object p) {
59  mThis=p;
61  };
62 public:
65  void getSharedPointer(SP::CORE_Object& p) {
66  p=mThis.lock();
67  };
70  void getSharedPointer(SPC::CORE_Object& p) const {
71  p=mThis.lock();
72  }
73 private:
76  SP::CORE_Object getThis() {
77  SP::CORE_Object ptr(mThis);
78  return ptr;
79  };
82  SPC::CORE_Object getThis() const {
83  SPC::CORE_Object ptr(mThis);
84  return ptr;
85  };
86 
87 
88 protected:
89  // CONSTRUCTORS
92  CORE_Object();
93 
94  // DESTRUCTORS
97  virtual ~CORE_Object();
98 
99 
100 
101  // for boost smart pointer using
102  class Delete;
103  friend class Delete;
106  class Delete {
107  public:
110  void operator()(const CORE_Object* p){delete p;}
111  };
112  // SET Methods
113 protected:
116  virtual void setType(tString type) {
117  }
118 
119  // GET
120 
121 
122 public:
123 
124 
128  static inline tString getClassName(const tString& identityString) {
129  return identityString.substr(0,identityString.find("@"));
130  };
131 
136  inline tString getIdentityString() const {
137  tString str(getClassName());
138  str.append("@");
139  str+=pointer2String(this);
140  return str;
141  };
142 
147  return pointer2String(this);
148  };
149 
153  tString getClassName() const;
154 
157  template<class T>
159  return (dynamic_cast<const T*>(this)!=null);
160  }
161 
164  template <class T>
165  inline static tString getTypeName() {
166  const char *name=typeid(T).name();
167  char *v=__cxxabiv1::__cxa_demangle(name,NULL,NULL,NULL);
168  tString type(v);
169  free(v);
170  return type;
171  };
172 
173  // METHODS
174 
177  static tBoolean is64Architecture();
180  inline static tBoolean is32Architecture() {
181  return !is64Architecture();
182  }
183 
184 protected:
188  virtual void toDoAfterThisSetting() {
189  };
190 
191 
192 public:
195  static tString pointer2String(const void *obj);
196 public:
197 
200  static inline void setOutput(ostream& out) {
201  mOutput=&out;
202  };
205  static inline ostream& getOutput() {
206  return *mOutput;
207  };
208 
211  static void printObjectsInMemory();
212 
216  virtual tString toString() const;
217 
218 
221  virtual void print() {
222  print(toString());
223  }
224 
225 
228  virtual ostream& print(ostream& out) const {
229  print(out,toString());
230  return out;
231  };
234  virtual void print(const tString& message);
235 
238  virtual void print(const tInteger& str);
241  virtual void print(const tRelativeInteger& str);
242 
245  virtual void print(const tReal& str);
246 
249  virtual void print(const int& str);
250 
253  inline static ostream& print(ostream& out,const tString& message) {
254  out << message;
255  return out;
256  };
257 
260  static void outputPrint(const tString& message );
261 
262 
265  friend ostream& operator << (ostream& out,const CORE_Object& obj) {
266  return obj.print(out);
267  };
268 
269 
270 
271 
272 
273 };
274 
275 #endif
static void setOutput(ostream &out)
set output
Definition: CORE_Object.h:200
static void printObjectsInMemory()
print object in memory
Definition: CORE_Object.cpp:45
static tString getClassName(const tString &identityString)
return the class name of the object using only the identity string
Definition: CORE_Object.h:128
void operator()(const CORE_Object *p)
operator to delete the class
Definition: CORE_Object.h:110
static tBoolean is32Architecture()
return true if the machine is a 32 bits machine
Definition: CORE_Object.h:180
static void outputPrint(const tString &message)
Definition: CORE_Object.cpp:89
static tBoolean is64Architecture()
return true if the machine is a 64 bits machine
Definition: CORE_Object.cpp:106
void setThis(SP::CORE_Object p)
set this weak shared pointer called toDoAfterThis setting method
Definition: CORE_Object.h:58
#define tRelativeInteger
Definition: types.h:33
#define tBoolean
Definition: types.h:35
tString getClassName() const
return the class name of the object
Definition: CORE_Object.cpp:95
virtual ostream & print(ostream &out) const
print the class
Definition: CORE_Object.h:228
#define null
Definition: types.h:13
CORE_Object()
build an object
Definition: CORE_Object.cpp:11
static tBoolean mIsMemoryTesting
indicator to store all classes created and deleted only for debuging version
Definition: CORE_Object.h:38
tString getIdentityString() const
return the identity string of the object of the form className_at_address
Definition: CORE_Object.h:136
static tString getTypeName()
get type name
Definition: CORE_Object.h:165
virtual ~CORE_Object()
destroy an object
Definition: CORE_Object.cpp:27
void getSharedPointer(SP::CORE_Object &p)
get the shared pointer of this class into p
Definition: CORE_Object.h:65
friend ostream & operator<<(ostream &out, const CORE_Object &obj)
print Operators
Definition: CORE_Object.h:265
void getSharedPointer(SPC::CORE_Object &p) const
get the shared pointer of this class into p
Definition: CORE_Object.h:70
static ostream & getOutput()
get output
Definition: CORE_Object.h:205
static ostream & print(ostream &out, const tString &message)
print the class
Definition: CORE_Object.h:253
abstract base class for most classes.
Definition: CORE_Object.h:30
#define tString
Definition: types.h:36
DEFINE_SPTR(CORE_Object)
static tString pointer2String(const void *obj)
return the string represantation of a pointer
Definition: CORE_Object.cpp:113
virtual void toDoAfterThisSetting()
method called after setThis() method this method can oly be called once.
Definition: CORE_Object.h:188
virtual void print()
print the class
Definition: CORE_Object.h:221
tBoolean isInstanceOf() const
return true if the object is an instance of T
Definition: CORE_Object.h:158
virtual void setType(tString type)
set the type of the object
Definition: CORE_Object.h:116
virtual tString toString() const
return the string representation of the object node
Definition: CORE_Object.cpp:101
tString getPointerAddress() const
return the identity string of the object
Definition: CORE_Object.h:146
#define tReal
Definition: types.h:18
#define tInteger
Definition: types.h:32
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:106