SHOGUN
v1.1.0
Main Page
Related Pages
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
src
shogun
base
SGObject.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
* Copyright (C) 2008-2010 Fraunhofer Institute FIRST and Max Planck Society
9
*/
10
11
#ifndef __SGOBJECT_H__
12
#define __SGOBJECT_H__
13
14
#include <
shogun/lib/config.h
>
15
#include <
shogun/io/SGIO.h
>
16
#include <
shogun/lib/DataType.h
>
17
#include <
shogun/lib/ShogunException.h
>
18
#include <
shogun/lib/memory.h
>
19
#include <
shogun/base/Parallel.h
>
20
#include <
shogun/base/Version.h
>
21
22
#ifdef HAVE_PTHREAD
23
#include <pthread.h>
24
#endif //HAVE_PTHREAD
25
29
namespace
shogun
30
{
31
class
IO;
32
class
Parallel;
33
class
Version;
34
class
Parameter;
35
class
CSerializableFile;
36
37
// define reference counter macros
38
//
39
#ifdef USE_REFERENCE_COUNTING
40
#define SG_REF(x) { if (x) (x)->ref(); }
41
#define SG_UNREF(x) { if (x) { if ((x)->unref()==0) (x)=NULL; } }
42
#define SG_UNREF_NO_NULL(x) { if (x) { (x)->unref(); } }
43
#else
44
#define SG_REF(x)
45
#define SG_UNREF(x)
46
#define SG_UNREF_NO_NULL(x)
47
#endif
48
49
/*******************************************************************************
50
* Macros for registering parameters/model selection parameters
51
******************************************************************************/
52
#define SG_ADD(param, name, description, ms_available) {\
53
m_parameters->add(param, name, description);\
54
if (ms_available)\
55
m_model_selection_parameters->add(param, name, description);\
56
}
57
/*******************************************************************************
58
* End of macros for registering parameters/model selection parameters
59
******************************************************************************/
60
62
enum
EModelSelectionAvailability
{
63
MS_NOT_AVAILABLE
=0,
MS_AVAILABLE
64
};
65
76
class
CSGObject
77
{
78
public
:
80
CSGObject
();
81
83
CSGObject
(
const
CSGObject
& orig);
84
86
virtual
~CSGObject
();
87
88
#ifdef USE_REFERENCE_COUNTING
89
93
int32_t ref();
94
99
int32_t ref_count();
100
106
int32_t unref();
107
#endif //USE_REFERENCE_COUNTING
108
114
virtual
const
char
*
get_name
()
const
= 0;
115
124
virtual
bool
is_generic
(EPrimitiveType*
generic
)
const
;
125
128
template
<
class
T>
void
set_generic
();
129
134
void
unset_generic
();
135
140
virtual
void
print_serializable
(
const
char
* prefix=
""
);
141
150
virtual
bool
save_serializable
(
CSerializableFile
* file,
151
const
char
* prefix=
""
);
152
162
virtual
bool
load_serializable
(
CSerializableFile
* file,
163
const
char
* prefix=
""
);
164
169
void
set_global_io
(
SGIO
*
io
);
170
175
SGIO
*
get_global_io
();
176
181
void
set_global_parallel
(
Parallel
*
parallel
);
182
187
Parallel
*
get_global_parallel
();
188
193
void
set_global_version
(
Version
*
version
);
194
199
Version
*
get_global_version
();
200
203
SGVector<char*>
get_modelsel_names
();
204
211
char
*
get_modsel_param_descr
(
const
char
* param_name);
212
219
index_t
get_modsel_param_index
(
const
char
* param_name);
220
221
#ifdef TRACE_MEMORY_ALLOCS
222
static
void
list_memory_allocs()
223
{
224
::list_memory_allocs();
225
}
226
#endif
227
228
protected
:
229
238
virtual
void
load_serializable_pre
()
throw
(
ShogunException
);
239
248
virtual
void
load_serializable_post
()
throw
(
ShogunException
);
249
258
virtual
void
save_serializable_pre
()
throw
(
ShogunException
);
259
268
virtual
void
save_serializable_post
()
throw
(
ShogunException
);
269
270
private
:
271
void
set_global_objects();
272
void
unset_global_objects();
273
void
init();
274
278
bool
save_parameter_version(
CSerializableFile
* file,
const
char
* prefix=
""
);
279
283
int32_t load_parameter_version(
CSerializableFile
* file,
284
const
char
* prefix=
""
);
285
286
public
:
288
SGIO
*
io
;
289
291
Parallel
*
parallel
;
292
294
Version
*
version
;
295
297
Parameter
*
m_parameters
;
298
300
Parameter
*
m_model_selection_parameters
;
301
302
private
:
303
304
EPrimitiveType m_generic;
305
bool
m_load_pre_called;
306
bool
m_load_post_called;
307
bool
m_save_pre_called;
308
bool
m_save_post_called;
309
310
int32_t m_refcount;
311
312
#ifdef HAVE_PTHREAD
313
PTHREAD_LOCK_T m_ref_lock;
314
#endif //HAVE_PTHREAD
315
};
316
}
317
#endif // __SGOBJECT_H__
SHOGUN
Machine Learning Toolbox - Documentation