SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
WrappedBasic.h
Go to the documentation of this file.
1 /*
2  * -*- coding: utf-8 -*-
3  * vim: set fileencoding=utf-8
4  *
5  * Copyright (c) 2016, Shogun-Toolbox e.V. <shogun-team@shogun-toolbox.org>
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the distribution.
17  *
18  * 3. Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  * Authors: Heiko Strathmann
35  */
36 #ifndef WRAPPED_BASIC_H__
37 #define WRAPPED_BASIC_H__
38 
39 #include <shogun/base/SGObject.h>
40 #include <shogun/lib/SGString.h>
41 
42 namespace
43 {
44  template <typename T>
45  T default_value()
46  {
47  return T();
48  }
49 
50  template <>
51  char default_value()
52  {
53  return '0';
54  }
55 }
56 
57 namespace shogun
58 {
59 
66 template<class T> class CWrappedBasic: public CSGObject
67 {
68 public:
71  {
72  set_generic<T>();
73  register_params();
74  }
75 
80  CWrappedBasic(T value, const char* value_name="")
81  {
82  set_generic<T>();
83  register_params();
84  m_value = value;
85  m_value_name = value_name;
86  }
87 
89  virtual const char* get_name() const { return "WrappedBasic"; }
90 
91 private:
92  void register_params()
93  {
94  m_value_name = "Unnamed";
95  m_value = ::default_value<T>();
96 
97  SG_ADD(&m_value, "value", "Wrapped value", MS_NOT_AVAILABLE);
98  }
99 
100 protected:
103 
105  const char* m_value_name;
106 };
107 
108 template class CWrappedBasic<bool>;
109 template class CWrappedBasic<char>;
110 template class CWrappedBasic<int8_t>;
111 template class CWrappedBasic<uint8_t>;
112 template class CWrappedBasic<int16_t>;
113 template class CWrappedBasic<uint16_t>;
114 template class CWrappedBasic<int32_t>;
115 template class CWrappedBasic<uint32_t>;
116 template class CWrappedBasic<int64_t>;
117 template class CWrappedBasic<uint64_t>;
118 template class CWrappedBasic<float32_t>;
119 template class CWrappedBasic<float64_t>;
120 template class CWrappedBasic<floatmax_t>;
121 
122 };
123 #endif // WRAPPED_BASIC_H__
virtual const char * get_name() const
Definition: WrappedBasic.h:89
CWrappedBasic(T value, const char *value_name="")
Definition: WrappedBasic.h:80
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:115
Simple wrapper class that allows to store any Shogun basic parameter (i.e. float64_t, int64_t, char, etc) in a CSGObject, and therefore to make it serializable. Using a template argument that is not a Shogun parameter will cause a compile error when trying to register the passed value as a parameter in the constructors.
Definition: WrappedBasic.h:66
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
const char * m_value_name
Definition: WrappedBasic.h:105
#define SG_ADD(...)
Definition: SGObject.h:84

SHOGUN Machine Learning Toolbox - Documentation