STK++ 0.9.13
STK_DataHandlerBase.h
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
36#ifndef STK_DATAHANDLERBASE_H
37#define STK_DATAHANDLERBASE_H
38
39#include <map>
40#include <Sdk.h>
41
42namespace STK
43{
44namespace hidden
45{
52template<class DataHandler, typename Type> struct DataHandlerTraits;
53
54} // namespace hidden
55
68template<class Derived>
69class DataHandlerBase: public IRecursiveTemplate<Derived>
70{
71 protected:
74
75 public:
76 typedef std::map<std::string, std::string> InfoMap;
78 inline ~DataHandlerBase() {}
80 inline InfoMap const& info() const { return info_;}
93 bool addInfo(std::string const& idData, std::string const& idModel);
101 bool getIdModelName(std::string const& idData, std::string& idModel) const;
103 void writeInfo(ostream& os) const;
104
105 protected:
111};
112
113
114/* @brief Add an info descriptor to the data handler.
115 * An info descriptor is a pair that allow to say that all columns of
116 * the data set(s) handled by the data handler and having the name "idData"
117 * are modeled by the model with model "idModel".
118 * @param idData can be any string given by the user for identifying data.
119 * @param idModel represent the idModel of a given model (can be defined
120 * inside or outside STK++).
121 *
122 * @note If the pair (idData, idModel) already exists then addInfo will do nothing.
123 * @return @c false if there exists already an idData matched with an other
124 * idModel, @c true otherwise.
125 **/
126template<class Derived>
127bool DataHandlerBase<Derived>::addInfo(std::string const& idData, std::string const& idModel)
128{
129 // parse descriptor file
130 std::pair<InfoMap::iterator,bool> ret;
131 // check if identifer is already present
132 ret = info_.insert(std::pair<std::string,std::string>(idData, idModel));
133 // if name already exists, check if there is incoherence
134 if (ret.second==false)
135 {
136 if (ret.first->second != idModel)
137 {
138#ifdef STK_DMANAGER_DEBUG
139 stk_cerr << _T("In DataHandlerBase::addInfo, There exists an idData with a different idModel.\n");
140#endif
141 return false;
142 }
143 }
144 return true;
145}
146
147/* @brief Giving a the Id of a dataset, find the Id of the model.
148 * @param idData can be any string given by the user.
149 * @param idModel The Id of the model associated with the data
150 * (not modified if idData is not present in the map).
151 * @return @c false if there exists already an idData matched with an other
152 * idModel, @c true otherwise.
153 **/
154template<class Derived>
155bool DataHandlerBase<Derived>::getIdModelName(std::string const& idData, std::string& idModel) const
156{
157 bool res = false;
158 // find idData
159 InfoMap::const_iterator it = info_.find(idData);
160 if (it != info_.end()) { idModel = it->second; res = true;}
161 return res;
162}
163
164/* write info on os */
165template<class Derived>
167{
168 // show content
169 for (InfoMap::const_iterator it=info_.begin(); it!=info_.end(); ++it)
170 os << _T("IdData: ") << it->first << _T(", IdModel: ") << it->second << _T('\n');
171}
172
173
174} // namespace STK
175
176#endif /* STK_DATAHANDLERBASE_H */
#define stk_cerr
Standard stk error stream.
#define _T(x)
Let x unmodified.
This file include all the other header files of the project Sdk.
A class derived from a DataHandlerBase allows to store various data sets identified by an idData and ...
void writeInfo(ostream &os) const
write infoMap on os
InfoMap info_
Store the informations of the mixtures in the form (idData, idModel) with.
DataHandlerBase()
default constructor
bool getIdModelName(std::string const &idData, std::string &idModel) const
Giving the Id of a data set, find the Id of the model.
std::map< std::string, std::string > InfoMap
InfoMap const & info() const
bool addInfo(std::string const &idData, std::string const &idModel)
Add an info descriptor to the data handler.
Interface base class for all classes implementing the curious recursive template paradigm.
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
std::basic_ostream< Char > ostream
ostream for Char
Definition STK_Stream.h:57
The namespace STK is the main domain space of the Statistical ToolKit project.