Documentation for OpenFLUID 2.2.0
DataHelpers.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30 */
31 
32 
33 /**
34  @file DataHelpers.hpp
35 
36  @author Jean-Christophe FABRE <jean-christophe.fabre@inra.fr>
37 
38  @deprecated Since version 2.2.0. Include openfluid/tools/StringHelpers.hpp file instead
39  */
40 
41 
42 #ifndef __OPENFLUID_TOOLS_DATAHELPERS_HPP__
43 #define __OPENFLUID_TOOLS_DATAHELPERS_HPP__
44 
45 
46 #include <string>
47 #include <list>
48 #include <sstream>
49 #include <vector>
50 
53 #include <openfluid/dllexport.hpp>
54 
55 
56 namespace openfluid { namespace tools {
57 
58 
59 /**
60  Converts a string to another type
61  @param[in] StrToConvert the string to convert
62  @param[out] Converted the result of the conversion
63  @return true if the conversion is correct
64  @deprecated Since version 2.2.0. Use openfluid::tools::toNumeric() instead
65 */
66 template<typename T>
67 [[deprecated]] inline bool convertString(const std::string& StrToConvert, T* Converted)
68 {
69  std::istringstream iss(StrToConvert);
70  char c;
71  return ((iss >> (*Converted)) && !iss.get(c));
72 }
73 
74 
75 // =====================================================================
76 // =====================================================================
77 
78 
79 /**
80  Converts a string to another type
81  @param[in] StrToConvert the string to convert
82  @return true the string converted
83  @throws openfluid::base::FrameworkException Error in string conversion
84  @deprecated Since version 2.2.0. Use openfluid::tools::toNumeric() instead
85 */
86 template<typename T>
87 [[deprecated]] inline T convertString(const std::string& StrToConvert)
88 {
89  T Converted;
90 
91  if (convertString(StrToConvert,&Converted))
92  {
93  return Converted;
94  }
95 
96  throw openfluid::base::FrameworkException(OPENFLUID_CODE_LOCATION,"Error in string conversion");
97 }
98 
99 
100 // =====================================================================
101 // =====================================================================
102 
103 
104 /**
105  Converts a value to a string
106  @param[in] ValueToConvert the value to convert
107  @param[out] StrConverted the result of the conversion
108  @return true if the conversion is correct
109  @deprecated Since version 2.2.0. Use std::to_string() instead
110 */
111 template<typename T>
112 [[deprecated]] inline bool convertValue(const T& ValueToConvert, std::string* StrConverted)
113 {
114  std::ostringstream oss;
115  bool IsOK = !(oss << ValueToConvert).fail();
116 
117  if (IsOK)
118  {
119  (*StrConverted) = oss.str();
120  }
121 
122  return IsOK;
123 }
124 
125 
126 // =====================================================================
127 // =====================================================================
128 
129 
130 /**
131  Converts a value to a string
132  @param[in] ValueToConvert the value to convert
133  @return the converted value
134  @throws openfluid::base::FrameworkException Error in value conversion
135  @deprecated Since version 2.2.0. Use std::to_string() instead
136 */
137 template<typename T>
138 [[deprecated]] inline std::string convertValue(const T& ValueToConvert)
139 {
140  std::string Converted;
141 
142  if (convertValue(ValueToConvert,&Converted))
143  {
144  return Converted;
145  }
146 
147  throw openfluid::base::FrameworkException(OPENFLUID_CODE_LOCATION,"Error in value conversion");
148 }
149 
150 
151 // =====================================================================
152 // =====================================================================
153 
154 
155 /**
156  Function for tokenizing string into a vector of tokens
157  @param[in] StrToTokenize the string to tokenize
158  @param[out] Tokens the resulting tokens
159  @param[in] Delimiters the string delimiter
160  @deprecated Since version 2.2.0. Use openfluid::tools::split() instead
161 */
162 [[deprecated]]void OPENFLUID_API tokenizeString(const std::string& StrToTokenize,
163  std::vector<std::string>& Tokens,
164  const std::string& Delimiters);
165 
166 
167 /**
168  Splits the given string into a std::string array, split using the given SepString
169  @param[in] StrToSplit the string to split
170  @param[in] Separators the string of separators used to split the string
171  @param[in] ReturnsEmpty if true, the empty strings are returned
172  @return a vector of strings
173  @deprecated Since version 2.2.0. Use openfluid::tools::split() instead
174 */
175 [[deprecated]] std::vector<std::string> OPENFLUID_API splitString(const std::string& StrToSplit,
176  const std::string& Separators,
177  bool ReturnsEmpty = false);
178 
179 
180 /**
181  Splits the given string into a std::string array, split using the given SepString
182  @param[in] StrToSplit the string to split
183  @param[in] Separator the separator character used to split the string
184  @param[in] ReturnsEmpty if true, the empty strings are returned
185  @return a vector of strings
186  @deprecated Since version 2.2.0. Use openfluid::tools::split() instead
187 */
188 [[deprecated]] std::vector<std::string> OPENFLUID_API splitString(const std::string& StrToSplit,
189  char Separator,
190  bool ReturnsEmpty = false);
191 
192 
193 /**
194  Replace every occurrence of a given substring (target) in a string by wanted replacement substring
195  @param[in] Data the string to work on
196  @param[in] ToSearch the target substring
197  @param[in] ReplaceStr the replacement substring
198  @deprecated Since version 2.2.0. Use openfluid::tools::replace() instead
199 */
200 [[deprecated]] void OPENFLUID_API stringReplace(std::string& Data,
201  const std::string& ToSearch, const std::string& ReplaceStr);
202 
203 
204 } } // namespaces
205 
206 
207 #endif /* __OPENFLUID_TOOLS_DATAHELPERS_HPP__ */
Definition: FrameworkException.hpp:51
#define OPENFLUID_API
Definition: dllexport.hpp:86
void OPENFLUID_API tokenizeString(const std::string &StrToTokenize, std::vector< std::string > &Tokens, const std::string &Delimiters)
bool convertValue(const T &ValueToConvert, std::string *StrConverted)
Definition: DataHelpers.hpp:112
bool convertString(const std::string &StrToConvert, T *Converted)
Definition: DataHelpers.hpp:67
void OPENFLUID_API stringReplace(std::string &Data, const std::string &ToSearch, const std::string &ReplaceStr)
std::vector< std::string > OPENFLUID_API splitString(const std::string &StrToSplit, const std::string &Separators, bool ReturnsEmpty=false)
Definition: ApplicationException.hpp:47