SHOGUN
v3.2.0
|
00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 2008-2010 Soeren Sonnenburg 00008 * Written (W) 2011-2013 Heiko Strathmann 00009 * Written (W) 2013 Thoralf Klein 00010 * Copyright (C) 2008-2010 Fraunhofer Institute FIRST and Max Planck Society 00011 */ 00012 00013 #ifndef __SGREFOBJECT_H__ 00014 #define __SGREFOBJECT_H__ 00015 00016 #include <shogun/lib/config.h> 00017 #include <shogun/lib/common.h> 00018 #include <shogun/lib/DataType.h> 00019 #include <shogun/lib/RefCount.h> 00020 00024 namespace shogun 00025 { 00026 00027 // define reference counter macros 00028 // 00029 #ifdef USE_REFERENCE_COUNTING 00030 #define SG_REF(x) { if (x) (x)->ref(); } 00031 #define SG_UNREF(x) { if (x) { if ((x)->unref()==0) (x)=NULL; } } 00032 #define SG_UNREF_NO_NULL(x) { if (x) { (x)->unref(); } } 00033 #else 00034 #define SG_REF(x) 00035 #define SG_UNREF(x) 00036 #define SG_UNREF_NO_NULL(x) 00037 #endif 00038 00046 class SGRefObject 00047 { 00048 public: 00050 SGRefObject(); 00051 00053 SGRefObject(const SGRefObject& orig); 00054 00056 virtual ~SGRefObject(); 00057 00058 #ifdef USE_REFERENCE_COUNTING 00059 00063 int32_t ref(); 00064 00069 int32_t ref_count(); 00070 00076 int32_t unref(); 00077 #endif //USE_REFERENCE_COUNTING 00078 00084 virtual const char* get_name() const = 0; 00085 00086 #ifdef TRACE_MEMORY_ALLOCS 00087 static void list_memory_allocs() 00088 { 00089 shogun::list_memory_allocs(); 00090 } 00091 #endif 00092 00093 private: 00094 void init(); 00095 00096 private: 00097 00098 RefCount* m_refcount; 00099 }; 00100 } 00101 #endif // __SGREFOBJECT_H__