13 #ifndef __SGOBJECT_H__
14 #define __SGOBJECT_H__
37 class CSerializableFile;
39 template <
class T,
class K>
class CMap;
49 #ifdef USE_REFERENCE_COUNTING
50 #define SG_REF(x) { if (x) (x)->ref(); }
51 #define SG_UNREF(x) { if (x) { if ((x)->unref()==0) (x)=NULL; } }
52 #define SG_UNREF_NO_NULL(x) { if (x) { (x)->unref(); } }
56 #define SG_UNREF_NO_NULL(x)
63 #define VA_NARGS_IMPL(_1, _2, _3, _4, _5, N, ...) N
64 #define VA_NARGS(...) VA_NARGS_IMPL(__VA_ARGS__, 5, 4, 3, 2, 1)
66 #define VARARG_IMPL2(base, count, ...) base##count(__VA_ARGS__)
67 #define VARARG_IMPL(base, count, ...) VARARG_IMPL2(base, count, __VA_ARGS__)
68 #define VARARG(base, ...) VARARG_IMPL(base, VA_NARGS(__VA_ARGS__), __VA_ARGS__)
70 #define SG_ADD4(param, name, description, ms_available) {\
71 m_parameters->add(param, name, description);\
73 m_model_selection_parameters->add(param, name, description);\
76 #define SG_ADD5(param, name, description, ms_available, gradient_available) {\
77 m_parameters->add(param, name, description);\
79 m_model_selection_parameters->add(param, name, description);\
80 if (gradient_available)\
81 m_gradient_parameters->add(param, name, description);\
84 #define SG_ADD(...) VARARG(SG_ADD, __VA_ARGS__)
127 #ifdef USE_REFERENCE_COUNTING
146 #endif //USE_REFERENCE_COUNTING
148 #ifdef TRACE_MEMORY_ALLOCS
149 static void list_memory_allocs();
167 virtual const char*
get_name()
const = 0;
177 virtual bool is_generic(EPrimitiveType*
generic)
const;
203 const char* prefix=
"");
215 const char* prefix=
"");
289 bool has(
const std::string& name)
const
292 return has_with_base_tag(tag);
300 template <
typename T>
303 return has<T>(tag.
name());
311 template <
typename T,
typename U=
void>
312 bool has(
const std::string& name)
const
315 if(!has_with_base_tag(tag))
317 const Any value = get_with_base_tag(tag);
327 template <
typename T>
330 if(has_with_base_tag(_tag))
332 if(has<T>(_tag.
name()))
336 SG_ERROR(
"Type for parameter with name \"%s\" is not correct.\n",
337 _tag.
name().c_str());
342 SG_ERROR(
"\"%s\" does not have a parameter with name \"%s\".\n",
353 template <
typename T,
typename U=
void>
354 void set(
const std::string& name,
const T& value)
366 template <
typename T>
369 const Any value = get_with_base_tag(_tag);
372 return recall_type<T>(value);
374 catch(std::logic_error)
376 SG_ERROR(
"Type for parameter with name \"%s\" is not correct in \"%s\".\n",
387 template <
typename T,
typename U=
void>
388 T
get(
const std::string& name)
const
438 template <typename T>
451 template <
typename T>
492 void set_global_objects();
493 void unset_global_objects();
503 bool has_with_base_tag(
const BaseTag& _tag)
const;
511 void set_with_base_tag(
const BaseTag& _tag,
const Any& any);
519 Any get_with_base_tag(
const BaseTag& _tag)
const;
529 void get_parameter_incremental_hash(uint32_t& hash, uint32_t& carry,
530 uint32_t& total_length);
559 EPrimitiveType m_generic;
560 bool m_load_pre_called;
561 bool m_load_post_called;
562 bool m_save_pre_called;
563 bool m_save_post_called;
568 #endif // __SGOBJECT_H__
virtual const char * get_name() const =0
SGStringList< char > get_modelsel_names()
template class SGStringList
Parallel * get_global_parallel()
virtual void update_parameter_hash()
virtual CSGObject * clone()
Base class for all tags. This class stores name and not the type information for a shogun object...
Class ShogunException defines an exception which is thrown whenever an error inside of shogun occurs...
virtual CSGObject * shallow_copy() const
void register_param(const std::string &name, const T &value)
void register_param(Tag< T > &_tag, const T &value)
Version * get_global_version()
virtual void save_serializable_pre()
virtual bool is_generic(EPrimitiveType *generic) const
EModelSelectionAvailability
Allows to store objects of arbitrary types by using a BaseAnyPolicy and provides a type agnostic API...
virtual bool load_serializable(CSerializableFile *file, const char *prefix="")
bool has(const std::string &name) const
void set(const std::string &name, const T &value)
char * get_modsel_param_descr(const char *param_name)
void set(const Tag< T > &_tag, const T &value)
Class SGObject is the base class of all shogun objects.
void build_gradient_parameter_dictionary(CMap< TParameter *, CSGObject * > *dict)
Template Dynamic array class that creates an array that can be used like a list or an array...
virtual void save_serializable_post()
void print_modsel_params()
Acts as an identifier for a shogun object. It contains type information and name of the object...
Class Version provides version information.
Parameter * m_model_selection_parameters
virtual bool equals(CSGObject *other, float64_t accuracy=0.0, bool tolerant=false)
virtual CSGObject * deep_copy() const
void set_global_parallel(Parallel *parallel)
virtual void load_serializable_pre()
virtual void load_serializable_post()
Class Parallel provides helper functions for multithreading.
virtual bool save_serializable(CSerializableFile *file, const char *prefix="")
all of classes and functions are contained in the shogun namespace
bool has(const Tag< T > &tag) const
index_t get_modsel_param_index(const char *param_name)
void set_global_io(SGIO *io)
Class SGIO, used to do input output operations throughout shogun.
Parameter * m_gradient_parameters
virtual void print_serializable(const char *prefix="")
virtual bool parameter_hash_changed()
void set_global_version(Version *version)
Any erase_type(const T &v)
bool has(const std::string &name) const
the class CMap, a map based on the hash-table. w: http://en.wikipedia.org/wiki/Hash_table ...