GRINS-0.6.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-2015 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 
57  inline
58  std::pair<std::string, int> split_string_int_on_colon(const std::string &token)
59  {
60  std::pair<std::string, int> ret = std::make_pair(std::string(), 0);
61  std::string::size_type colon_position = token.find(":");
62  libmesh_assert (colon_position != std::string::npos);
63  ret.first = token.substr(0, colon_position);
64  ret.second = std::atoi(token.substr(colon_position + 1).c_str());
65  return ret;
66  }
67 
68 
73  inline
74  std::pair<std::string, double> split_string_double_on_colon(const std::string &token)
75  {
76  std::pair<std::string, double> ret = std::make_pair(std::string(), 0.0);
77  std::string::size_type colon_position = token.find(":");
78  libmesh_assert (colon_position != std::string::npos);
79  ret.first = token.substr(0, colon_position);
80  ret.second = std::atof(token.substr(colon_position + 1).c_str());
81  return ret;
82  }
83 
84  void split_string( const std::string& input,
85  const std::string& delimiter,
86  std::vector<std::string>& results );
87  } // end namespace StringUtilities
88 } // end namespace GRINS
89 
90 #endif // GRINS_STRING_UTILS_H
GRINS namespace.
T string_to_T(const std::string &input)
Definition: string_utils.h:43
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:58
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:74

Generated on Mon Jun 22 2015 21:32:20 for GRINS-0.6.0 by  doxygen 1.8.9.1