STK++ 0.9.13
STK_KernelHandler.cpp
Go to the documentation of this file.
1/*--------------------------------------------------------------------*/
2/* Copyright (C) 2004-2016 Serge Iovleff, Université Lille 1, Inria
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this program; if not, write to the
16 Free Software Foundation, Inc.,
17 59 Temple Place,
18 Suite 330,
19 Boston, MA 02111-1307
20 USA
21
22 Contact : S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
23*/
24
25/*
26 * Project: stkpp::DManager
27 * created on: 15 nov. 2013
28 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 **/
30
37
38namespace STK
39{
40/* default constructor */
42/* constructor with an instance of a kernel to handle*/
44 : Base()
45 , nbSample_(p_kernel->nbSample())
46{}
47/* destructor */
49{
51 {
52 if (it->first)
53 {
54 Kernel::IKernel* p = it->first;
55 it->first = 0;
56 if (!isHandled(p)) delete p;
57 }
58 }
59}
60
61/* add an instance of a kernel to the handler
62 * @param p_kernel an instance of a kernel
63 * @param idData can be any string given by the user for identifying data.
64 * @param idModel represent the idModel of a given model (can be defined
65 * inside or outside STK++).
66 * @return @c true if the pair (idData,idModel) has been successfully added
67 * to the handler
68 */
69bool KernelHandler::addKernel(Kernel::IKernel* p_kernel, String const& idData, String const& idModel)
70{
71 if (!p_kernel) return false;
72 if (!addInfo(idData, idModel)) return false; // there exists an idData with an other idModel
73
74 // check if idData already exists
77 { if (it->second == idData) { break;}}
78
79 // add kernel if it does not exist otherwise do nothing
81 {
82 v_kernel_.push_back(TaggedKernel(p_kernel, idData));
83 nbSample_ = p_kernel->nbSample();
84 }
85 return true;
86}
87/* get an instance of a kernel from the handler
88 * @param idData can be any string given by the user for identifying data.
89 * @return @c 0 if the idData has not been found, a pointer to the kernel
90 * otherwise
91 */
93{
94 // check if the idData already exists
97 { if (it->second == idData) { break;}}
98 // no data set found
99 if (it == v_kernel_.endConstIterator()) { return 0;}
100 return it->first;
101}
102/* remove an instance of a kernel to the handler
103 * @param idData can be any string given by the user for identifying data.
104 */
106{
107 // check if the idData exists
110 { if (it->second == idData) { break;}
111 }
112 // check if kernel has been found
113 if (it != v_kernel_.endIterator())
114 {
115 Kernel::IKernel* p = it->first;
116 it->first = 0;
117 if (!isHandled(p)) delete p;
118 v_kernel_.erase(it.pos(), 1);
119 }
120}
121
122/* utility lookup function allowing to know if some pointer on a kernel
123 * is handled.
124 * @return @c true if the pointed kernel is found, @c false otherwise
125 **/
126bool KernelHandler::isHandled(Kernel::IKernel* const p_kernel) const
127{
129 { if (it->first == p_kernel) return true;}
130 return false;
131}
132
133} // namespace STK
134
In this file we define the KernelHandler class.
bool addInfo(std::string const &idData, std::string const &idModel)
Add an info descriptor to the data handler.
Derived & erase(int pos, int n=1)
Delete n elements at the pos index to the container.
Derived & push_back(Type const &v)
STL compatibility: append an element v.
ConstIterator endConstIterator() const
ConstIterator beginConstIterator() const
Kernel::IKernel const * getKernel(String const &idData) const
get an instance of a kernel from the handler
Array1D< TaggedKernel > v_kernel_
Array of the kernels.
int nbSample_
Number of sample.
bool isHandled(Kernel::IKernel *const p_kernel) const
utility lookup function allowing to know if some pointer on a kernel is handled by the KernelHandler.
void removeKernel(String const &idData)
remove an instance of a kernel to the handler
bool addKernel(Kernel::IKernel *p_kernel, String const &idData, String const &idModel)
add an instance of a kernel to the handler
std::pair< Kernel::IKernel *, String > TaggedKernel
KernelHandler()
default constructor
Interface class for the kernels classes.
virtual int nbSample() const =0
pure virtual method.
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
std::basic_string< Char > String
STK fundamental type of a String.
The namespace STK is the main domain space of the Statistical ToolKit project.