SGObject.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef __SGOBJECT_H__
00012 #define __SGOBJECT_H__
00013
00014 #include "lib/io.h"
00015 #include "base/Parallel.h"
00016 #include "base/Version.h"
00017
00018 class CSGObject;
00019 class CIO;
00020
00021
00022 #if defined(HAVE_SWIG) && !defined(HAVE_R)
00023 #define SG_REF(x) { if (x) x->ref(); }
00024 #define SG_UNREF(x) { if (x) x->unref(); }
00025 #else
00026 #define SG_REF(x)
00027 #define SG_UNREF(x)
00028 #endif // HAVE_SWIG
00029 class CSGObject
00030 {
00031 public:
00032 virtual ~CSGObject()
00033 {
00034 }
00035
00036 #ifdef HAVE_SWIG
00037 #ifndef HAVE_R
00038 inline CSGObject() : refcount(0)
00039 {
00040 }
00041
00042 inline CSGObject(const CSGObject& orig)
00043 : refcount(0) , parallel(orig.parallel), io(orig.io)
00044 {
00045 }
00046
00047 inline INT ref()
00048 {
00049 ++refcount;
00050 SG_DEBUG("ref():%ld obj:%p\n", refcount, this);
00051 return refcount;
00052 }
00053
00054 inline INT ref_count() const
00055 {
00056 SG_DEBUG("ref_count(): refcount is: %d\n", refcount);
00057 return refcount;
00058 }
00059
00060 inline INT unref()
00061 {
00062 if (refcount==0 || --refcount==0)
00063 {
00064 SG_DEBUG("unref():%ld obj:%p destroying\n", refcount, this);
00065
00066
00067 delete this;
00068 return 0;
00069 }
00070 else
00071 {
00072 SG_DEBUG("unref():%ld obj:%p decreased\n", refcount, this);
00073 return refcount;
00074 }
00075 }
00076
00077 private:
00078 INT refcount;
00079 #else //HAVE_R
00080 inline CSGObject()
00081 {
00082 }
00083
00084 inline CSGObject(const CSGObject& orig)
00085 : parallel(orig.parallel), io(orig.io)
00086 {
00087 }
00088 #endif
00089
00090 public:
00091 CParallel parallel;
00092 CIO io;
00093 CVersion version;
00094 #else // HAVE_SWIG
00095 public:
00096 inline CSGObject()
00097 {
00098 }
00099
00100 inline CSGObject(const CSGObject& orig)
00101 {
00102 }
00103
00104 public:
00105 static CParallel parallel;
00106 static CIO io;
00107 static CVersion version;
00108 #endif // HAVE_SWIG
00109 };
00110 #endif // __SGOBJECT_H__