STK++ 0.9.13
STK_IDataHandler.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_IDATAHANDLER_H
37#define STK_IDATAHANDLER_H
38
39#include <Sdk.h>
40
41
42namespace STK
43{
44namespace hidden
45{
50template<class DataHandler, typename Type>
52{};
53
54} // namespace hidden
55
66{
67 public:
68 typedef std::map<std::string, std::string> InfoMap;
70 inline IDataHandler() {}
72 inline virtual ~IDataHandler() {}
74 inline InfoMap const& info() const { return info_;}
87 bool addInfo(std::string const& idData, std::string const& idModel);
95 bool getIdModelName(std::string const& idData, std::string& idModel) const;
97 virtual int nbSample() const =0;
99 void writeInfo(ostream& os) const;
100
101 protected:
107};
108
110{
111 // show content
112 for (InfoMap::const_iterator it=info_.begin(); it!=info_.end(); ++it)
113 os << _T("IdData: ") << it->first << _T(", IdModel: ") << it->second << _T('\n');
114}
115
116inline bool IDataHandler::addInfo(std::string const& idData, std::string const& idModel)
117{
118 // parse descriptor file
119 std::pair<InfoMap::iterator,bool> ret;
120 // check if identifer is already present
121 ret = info_.insert(std::pair<std::string,std::string>(idData, idModel));
122 // if name already exists, check if there is incoherence
123 if (ret.second==false)
124 {
125 if (ret.first->second != idModel)
126 {
127#ifdef STK_DMANAGER_DEBUG
128 stk_cerr << _T("In IDataHandler::addInfo, There exists an idData with a different idModel.\n");
129#endif
130 return false;
131 }
132 }
133 return true;
134}
135
136/* @brief Giving a the Id of a dataset, find the Id of the model.
137 * @param idData can be any string given by the user.
138 * @param idModel The Id of the model associated with the data
139 * (not modified if idData is not present in the map).
140 * @return @c false if there exists already an idData matched with an other
141 * idModel, @c true otherwise.
142 **/
143inline bool IDataHandler::getIdModelName(std::string const& idData, std::string& idModel) const
144{
145 bool res = false;
146 // show content
147 for (InfoMap::const_iterator it=info_.begin(); it!=info_.end(); ++it)
148 { if (it->first == idData) { idModel = it->second; res = true; break;}}
149 return res;
150}
151
152} // namespace STK
153
154#endif /* STK_IDATAHANDLER_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 DataHandler class allow to store various data set identified with an idData (a string).
InfoMap info_
Store the informations of the mixtures in the form (idData, idModel) with.
InfoMap const & info() const
virtual int nbSample() const =0
std::map< std::string, std::string > InfoMap
bool addInfo(std::string const &idData, std::string const &idModel)
Add an info descriptor to the data handler.
IDataHandler()
default constructor
bool getIdModelName(std::string const &idData, std::string &idModel) const
Giving a the Id of a dataset, find the Id of the model.
virtual ~IDataHandler()
destructor
void writeInfo(ostream &os) const
write the info on os
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.
The DataHandlerTraits will give the type of container furnished by the concrete implementations of th...