SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
WrappedObjectArray.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_OBJECT_ARRAY_H__
37 #define WRAPPED_OBJECT_ARRAY_H__
38 
43 
44 
45 namespace shogun
46 {
47 
53 {
54 public:
56 
63  template<class T> bool append_wrapped(T data, const char* data_name="")
64  {
65  return this->append_element(new CWrappedBasic<T>(data, data_name));
66  }
67 
74  template<class T> bool append_wrapped(SGVector<T> data, const char* data_name="")
75  {
76  return this->append_element(new CWrappedSGVector<T>(data,
77  data_name));
78  }
79 
86  template<class T> bool append_wrapped(SGMatrix<T> data, const char* data_name="")
87  {
88  return this->append_element(new CWrappedSGMatrix<T>(data,
89  data_name));
90  }
91 
93  virtual const char* get_name() const { return "WrappedObjectArray"; }
94 
95 #define APPEND_WRAPPED_TEMPLATE(META_TYPE, SG_TYPE) \
96  \
101  bool append_wrapped_##META_TYPE(SG_TYPE data, const char* data_name="") \
102 { \
103  return this->append_wrapped(data, data_name); \
104 }
105 
108  APPEND_WRAPPED_TEMPLATE(int, int32_t)
109  APPEND_WRAPPED_TEMPLATE(real_vector, SGVector<float64_t>)
110  APPEND_WRAPPED_TEMPLATE(float_vector, SGVector<float32_t>)
111  APPEND_WRAPPED_TEMPLATE(real_matrix, SGMatrix<float64_t>)
112  APPEND_WRAPPED_TEMPLATE(float_matrix, SGMatrix<float32_t>)
113 };
114 }
115 #endif // WRAPPED_OBJECT_ARRAY_H__
Specialization of CDynamicObjectArray that adds methods to append wrapped elements to make them seria...
#define APPEND_WRAPPED_TEMPLATE(META_TYPE, SG_TYPE)
bool append_wrapped(SGMatrix< T > data, const char *data_name="")
shogun matrix
virtual const char * get_name() const
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
shogun vector
double float64_t
Definition: common.h:50
Dynamic array class for CSGObject pointers that creates an array that can be used like a list or an a...
float float32_t
Definition: common.h:49
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
bool append_wrapped(T data, const char *data_name="")
Simple wrapper class that allows to store any Shogun SGMatrix in a CSGObject, and therefore to mak...
bool append_wrapped(SGVector< T > data, const char *data_name="")
bool append_element(CSGObject *e)
Simple wrapper class that allows to store any Shogun SGVector in a CSGObject, and therefore to mak...

SHOGUN Machine Learning Toolbox - Documentation