/usr/include/shogun/base/SGObject.h is in libshogun-dev 1.1.0-4ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | /*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Written (W) 2008-2010 Soeren Sonnenburg
* Copyright (C) 2008-2010 Fraunhofer Institute FIRST and Max Planck Society
*/
#ifndef __SGOBJECT_H__
#define __SGOBJECT_H__
#include <shogun/lib/config.h>
#include <shogun/io/SGIO.h>
#include <shogun/lib/DataType.h>
#include <shogun/lib/ShogunException.h>
#include <shogun/lib/memory.h>
#include <shogun/base/Parallel.h>
#include <shogun/base/Version.h>
#ifdef HAVE_PTHREAD
#include <pthread.h>
#endif //HAVE_PTHREAD
/** \namespace shogun
* @brief all of classes and functions are contained in the shogun namespace
*/
namespace shogun
{
class IO;
class Parallel;
class Version;
class Parameter;
class CSerializableFile;
// define reference counter macros
//
#ifdef USE_REFERENCE_COUNTING
#define SG_REF(x) { if (x) (x)->ref(); }
#define SG_UNREF(x) { if (x) { if ((x)->unref()==0) (x)=NULL; } }
#define SG_UNREF_NO_NULL(x) { if (x) { (x)->unref(); } }
#else
#define SG_REF(x)
#define SG_UNREF(x)
#define SG_UNREF_NO_NULL(x)
#endif
/*******************************************************************************
* Macros for registering parameters/model selection parameters
******************************************************************************/
#define SG_ADD(param, name, description, ms_available) {\
m_parameters->add(param, name, description);\
if (ms_available)\
m_model_selection_parameters->add(param, name, description);\
}
/*******************************************************************************
* End of macros for registering parameters/model selection parameters
******************************************************************************/
/** model selection availability */
enum EModelSelectionAvailability {
MS_NOT_AVAILABLE=0, MS_AVAILABLE
};
/** @brief Class SGObject is the base class of all shogun objects.
*
* Apart from dealing with reference counting that is used to manage shogung
* objects in memory (erase unused object, avoid cleaning objects when they are
* still in use), it provides interfaces for:
*
* -# parallel - to determine the number of used CPUs for a method (cf. Parallel)
* -# io - to output messages and general i/o (cf. IO)
* -# version - to provide version information of the shogun version used (cf. Version)
*/
class CSGObject
{
public:
/** default constructor */
CSGObject();
/** copy constructor */
CSGObject(const CSGObject& orig);
/** destructor */
virtual ~CSGObject();
#ifdef USE_REFERENCE_COUNTING
/** increase reference counter
*
* @return reference count
*/
int32_t ref();
/** display reference counter
*
* @return reference count
*/
int32_t ref_count();
/** decrement reference counter and deallocate object if refcount is zero
* before or after decrementing it
*
* @return reference count
*/
int32_t unref();
#endif //USE_REFERENCE_COUNTING
/** Returns the name of the SGSerializable instance. It MUST BE
* the CLASS NAME without the prefixed `C'.
*
* @return name of the SGSerializable
*/
virtual const char* get_name() const = 0;
/** If the SGSerializable is a class template then TRUE will be
* returned and GENERIC is set to the type of the generic.
*
* @param generic set to the type of the generic if returning
* TRUE
*
* @return TRUE if a class template.
*/
virtual bool is_generic(EPrimitiveType* generic) const;
/** set generic type to T
*/
template<class T> void set_generic();
/** unset generic type
*
* this has to be called in classes specializing a template class
*/
void unset_generic();
/** prints registered parameters out
*
* @param prefix prefix for members
*/
virtual void print_serializable(const char* prefix="");
/** Save this object to file.
*
* @param file where to save the object; will be closed during
* returning if PREFIX is an empty string.
* @param prefix prefix for members
*
* @return TRUE if done, otherwise FALSE
*/
virtual bool save_serializable(CSerializableFile* file,
const char* prefix="");
/** Load this object from file. If it will fail (returning FALSE)
* then this object will contain inconsistent data and should not
* be used!
*
* @param file where to load from
* @param prefix prefix for members
*
* @return TRUE if done, otherwise FALSE
*/
virtual bool load_serializable(CSerializableFile* file,
const char* prefix="");
/** set the io object
*
* @param io io object to use
*/
void set_global_io(SGIO* io);
/** get the io object
*
* @return io object
*/
SGIO* get_global_io();
/** set the parallel object
*
* @param parallel parallel object to use
*/
void set_global_parallel(Parallel* parallel);
/** get the parallel object
*
* @return parallel object
*/
Parallel* get_global_parallel();
/** set the version object
*
* @param version version object to use
*/
void set_global_version(Version* version);
/** get the version object
*
* @return version object
*/
Version* get_global_version();
/** @return vector of names of all parameters which are registered for model
* selection */
SGVector<char*> get_modelsel_names();
/** Returns description of a given parameter string, if it exists. SG_ERROR
* otherwise
*
* @param param_name name of the parameter
* @return description of the parameter
*/
char* get_modsel_param_descr(const char* param_name);
/** Returns index of model selection parameter with provided index
*
* @param param_name name of model selection parameter
* @return index of model selection parameter with provided name,
* -1 if there is no such
*/
index_t get_modsel_param_index(const char* param_name);
#ifdef TRACE_MEMORY_ALLOCS
static void list_memory_allocs()
{
::list_memory_allocs();
}
#endif
protected:
/** Can (optionally) be overridden to pre-initialize some member
* variables which are not PARAMETER::ADD'ed. Make sure that at
* first the overridden method BASE_CLASS::LOAD_SERIALIZABLE_PRE
* is called.
*
* @exception ShogunException Will be thrown if an error
* occurres.
*/
virtual void load_serializable_pre() throw (ShogunException);
/** Can (optionally) be overridden to post-initialize some member
* variables which are not PARAMETER::ADD'ed. Make sure that at
* first the overridden method BASE_CLASS::LOAD_SERIALIZABLE_POST
* is called.
*
* @exception ShogunException Will be thrown if an error
* occurres.
*/
virtual void load_serializable_post() throw (ShogunException);
/** Can (optionally) be overridden to pre-initialize some member
* variables which are not PARAMETER::ADD'ed. Make sure that at
* first the overridden method BASE_CLASS::SAVE_SERIALIZABLE_PRE
* is called.
*
* @exception ShogunException Will be thrown if an error
* occurres.
*/
virtual void save_serializable_pre() throw (ShogunException);
/** Can (optionally) be overridden to post-initialize some member
* variables which are not PARAMETER::ADD'ed. Make sure that at
* first the overridden method BASE_CLASS::SAVE_SERIALIZABLE_POST
* is called.
*
* @exception ShogunException Will be thrown if an error
* occurres.
*/
virtual void save_serializable_post() throw (ShogunException);
private:
void set_global_objects();
void unset_global_objects();
void init();
/** stores the current parameter version in the provided file
* @return true iff successful
*/
bool save_parameter_version(CSerializableFile* file, const char* prefix="");
/** loads the parameter version of the provided file.
* @return parameter version of file, -1 if there is no such
*/
int32_t load_parameter_version(CSerializableFile* file,
const char* prefix="");
public:
/** io */
SGIO* io;
/** parallel */
Parallel* parallel;
/** version */
Version* version;
/** parameters */
Parameter* m_parameters;
/** model selection parameters */
Parameter* m_model_selection_parameters;
private:
EPrimitiveType m_generic;
bool m_load_pre_called;
bool m_load_post_called;
bool m_save_pre_called;
bool m_save_post_called;
int32_t m_refcount;
#ifdef HAVE_PTHREAD
PTHREAD_LOCK_T m_ref_lock;
#endif //HAVE_PTHREAD
};
}
#endif // __SGOBJECT_H__
|