STK++ 0.9.13
STK_DManager_Util.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: 12 juil. 2011
28 * Purpose: useful methods for processing dta, strings and i/o streams.
29 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
30 *
31 **/
32
38#ifndef STK_DMANAGER_UTIL_H
39#define STK_DMANAGER_UTIL_H
40
41#include <list>
42#include <STKernel.h>
43
44namespace STK
45{
46
49static const String STRING_VAR = _T("Var");
50
53static const Char CHAR_NL = _T('\n');
57static const Char CHAR_COMMENT = _T('#');
60static const Char CHAR_EQUAL = _T('=');
63static const Char CHAR_BLANK = _T(' ');
66static const Char CHAR_TAB = _T('\t');
69static const Char CHAR_SEP = _T(',');
72static const Char CHAR_OPENBRACKET = _T('[');
75static const Char CHAR_CLOSEBRACKET = _T(']');
76
77namespace DManager
78{
83{
85 unknown_ =0
88};
89
97
104
113bool checkStringToBoolean( String const& str);
114
123bool StringToBoolean( String const& str);
124
132
145
152template<class TYPE>
153void readList(String const& strBuffer, std::list<TYPE>& lst, Char sep = CHAR_SEP)
154{
155 // Declare an input string stream
157 // Use strBuffer as source of input.
158 instream.str(strBuffer);
159 // read the line
160 do
161 {
162 // get field
165 // check if it is a blank field
166 if (strbuff.empty()) { break;}
167 // append Data to the list
168 TYPE value;
169 if (stringToType(value, strbuff))
170 lst.push_back(value);
171 // TODO: else emit warning or Exception
172 }
173 while(1);
174}
175
182template<class TYPE>
183void writeList( ostream& os, std::list<TYPE> const& lst, Char sep = CHAR_SEP)
184{
185 if (lst.empty()) return;
186 typename std::list<TYPE>::const_iterator it = lst.begin();
187 os << *it;
188 it++;
189 for ( ; it != lst.end(); it++)
190 { os << sep << CHAR_BLANK << *it;}
191}
192
197int nbEndOfLine( istream& is);
198
199} // namespace DManager
200
201} // namespace STK
202
203#endif /* STK_DMANAGER_UTIL_H */
#define _T(x)
Let x unmodified.
This file include all the header files of the project STKernel.
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
bool stringToType(Type &t, String const &s, std::ios_base &(*f)(std::ios_base &)=std::dec)
convert a String to Type
Definition STK_String.h:195
void readList(String const &strBuffer, std::list< TYPE > &lst, Char sep=CHAR_SEP)
Read a list of value of type TYPE stored in a line.
void writeList(ostream &os, std::list< TYPE > const &lst, Char sep=CHAR_SEP)
Write a list of value of type TYPE stored in a line.
bool StringToBoolean(String const &str)
convert a string to a boolean.
TypeDataFile stringToTypeDataFile(String const &type)
convert a String to a TypeDataFile.
TypeDataFile
type of the data file we handle.
bool checkStringToBoolean(String const &str)
check if a string represent a boolean.
int nbEndOfLine(istream &is)
String TypeDataFileToString(TypeDataFile const &type)
convert a TypeDataFile to a String.
void removeCharBeforeAndAfter(String &str, Char c)
remove all occurrences of the char c at the beginning and the end of the string str.
istream & getField(istream &is, String &value, Char delimiter)
Get the current field from the input stream.
@ unknown_
unknown reduction
char Char
STK fundamental type of a Char.
std::basic_string< Char > String
STK fundamental type of a String.
std::basic_ostream< Char > ostream
ostream for Char
Definition STK_Stream.h:57
std::basic_istringstream< Char > istringstream
istringstream for Char
Definition STK_Stream.h:63
std::basic_istream< Char > istream
istream for Char
Definition STK_Stream.h:55
The namespace STK is the main domain space of the Statistical ToolKit project.