SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SGRefObject.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2008-2010 Soeren Sonnenburg
8  * Written (W) 2011-2013 Heiko Strathmann
9  * Written (W) 2013 Thoralf Klein
10  * Copyright (C) 2008-2010 Fraunhofer Institute FIRST and Max Planck Society
11  */
12 
13 #ifndef __SGREFOBJECT_H__
14 #define __SGREFOBJECT_H__
15 
16 #include <shogun/lib/config.h>
17 
21 namespace shogun
22 {
23 
24 class RefCount;
25 class SGRefObject;
26 
27 // define reference counter macros
28 //
29 #ifdef USE_REFERENCE_COUNTING
30 #define SG_REF(x) { if (x) (x)->ref(); }
31 #define SG_UNREF(x) { if (x) { if ((x)->unref()==0) (x)=NULL; } }
32 #define SG_UNREF_NO_NULL(x) { if (x) { (x)->unref(); } }
33 #else
34 #define SG_REF(x)
35 #define SG_UNREF(x)
36 #define SG_UNREF_NO_NULL(x)
37 #endif
38 
47 {
48 public:
50  SGRefObject();
51 
53  SGRefObject(const SGRefObject& orig);
54 
56  virtual ~SGRefObject();
57 
58 #ifdef USE_REFERENCE_COUNTING
59 
63  int32_t ref();
64 
69  int32_t ref_count();
70 
76  int32_t unref();
77 #endif //USE_REFERENCE_COUNTING
78 
84  virtual const char* get_name() const = 0;
85 
86 #ifdef TRACE_MEMORY_ALLOCS
87  static void list_memory_allocs();
88 #endif
89 
90 private:
91  void init();
92 
93 private:
94 
95  RefCount* m_refcount;
96 };
97 }
98 #endif // __SGREFOBJECT_H__

SHOGUN Machine Learning Toolbox - Documentation