GRINS-0.8.0
string_utils.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // GRINS - General Reacting Incompressible Navier-Stokes
5 //
6 // Copyright (C) 2014-2017 Paul T. Bauman, Roy H. Stogner
7 // Copyright (C) 2010-2013 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 
26 #ifndef GRINS_STRING_UTILS_H
27 #define GRINS_STRING_UTILS_H
28 
29 // libMesh
30 #include "libmesh/libmesh_common.h"
31 
32 // C++
33 #include <sstream>
34 #include <string>
35 #include <vector>
36 
37 namespace GRINS
38 {
39  namespace StringUtilities
40  {
41  template <typename T>
42  inline
43  T string_to_T(const std::string& input)
44  {
45  std::istringstream converter(input);
46  T returnval;
47  converter >> returnval;
48  if (converter.fail())
49  libmesh_error();
50  return returnval;
51  }
52 
53  template <typename T>
54  inline
55  std::string T_to_string(const T input)
56  {
57  std::stringstream converter;
58  converter << input;
59  if (converter.fail())
60  libmesh_error();
61  return converter.str();
62  }
63 
68  inline
69  std::pair<std::string, int> split_string_int_on_colon(const std::string &token)
70  {
71  std::pair<std::string, int> ret = std::make_pair(std::string(), 0);
72  std::string::size_type colon_position = token.find(":");
73  libmesh_assert (colon_position != std::string::npos);
74  ret.first = token.substr(0, colon_position);
75  ret.second = std::atoi(token.substr(colon_position + 1).c_str());
76  return ret;
77  }
78 
79 
84  inline
85  std::pair<std::string, double> split_string_double_on_colon(const std::string &token)
86  {
87  std::pair<std::string, double> ret = std::make_pair(std::string(), 0.0);
88  std::string::size_type colon_position = token.find(":");
89  libmesh_assert (colon_position != std::string::npos);
90  ret.first = token.substr(0, colon_position);
91  ret.second = std::atof(token.substr(colon_position + 1).c_str());
92  return ret;
93  }
94 
95  void split_string( const std::string& input,
96  const std::string& delimiter,
97  std::vector<std::string>& results );
98 
99  void split_string_real( const std::string& input,
100  const std::string& delimiter,
101  std::vector<libMesh::Real>& results );
102  } // end namespace StringUtilities
103 } // end namespace GRINS
104 
105 #endif // GRINS_STRING_UTILS_H
GRINS namespace.
T string_to_T(const std::string &input)
Definition: string_utils.h:43
std::string T_to_string(const T input)
Definition: string_utils.h:55
void split_string_real(const std::string &input, const std::string &delimiter, std::vector< libMesh::Real > &results)
Definition: string_utils.C:53
std::pair< std::string, int > split_string_int_on_colon(const std::string &token)
Split on colon, and return name, int value pair.
Definition: string_utils.h:69
void split_string(const std::string &input, const std::string &delimiter, std::vector< std::string > &results)
Definition: string_utils.C:31
std::pair< std::string, double > split_string_double_on_colon(const std::string &token)
Split on colon, and return name, double value pair.
Definition: string_utils.h:85

Generated on Tue Dec 19 2017 12:47:28 for GRINS-0.8.0 by  doxygen 1.8.9.1