Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tempus_String_Utilities.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ****************************************************************************
3 // Tempus: Copyright (2017) Sandia Corporation
4 //
5 // Distributed under BSD 3-clause license (See accompanying file Copyright.txt)
6 // ****************************************************************************
7 // @HEADER
8 
9 #ifndef Tempus_String_Utilities_hpp
10 #define Tempus_String_Utilities_hpp
11 
12 #include <vector>
13 #include <string>
14 #include "Teuchos_RCP.hpp"
15 #include "Teuchos_ParameterList.hpp"
16 
17 namespace Tempus {
18 
19  //! Removes whitespace at beginning and end of string
20  void trim(std::string& str);
21 
22  //! Tokenize a string, put tokens in a vector
23  void StringTokenizer(std::vector<std::string>& tokens,
24  const std::string& str,
25  const std::string delimiter = ",",bool trim=false);
26 
27  //! Turn a vector of tokens into a vector of doubles
28  void TokensToDoubles(std::vector<double> & values,
29  const std::vector<std::string> & tokens);
30 
31  //! Turn a vector of tokens into a vector of ints
32  void TokensToInts(std::vector<int> & values,
33  const std::vector<std::string> & tokens);
34 
35  /** Read in a parameter field and return the correct scalar field. This parses
36  * scalar type data
37  */
38  template <typename ScalarT>
39  ScalarT getScalarParameter(const std::string & field,
40  const Teuchos::ParameterList & plist)
41  {
42  return plist.get<double>(field);
43  }
44 }
45 
46 #endif // Tempus_String_Utilities_hpp
ScalarT getScalarParameter(const std::string &field, const Teuchos::ParameterList &plist)
void TokensToDoubles(std::vector< double > &values, const std::vector< std::string > &tokens)
Turn a vector of tokens into a vector of doubles.
void trim(std::string &str)
Removes whitespace at beginning and end of string.
void StringTokenizer(std::vector< std::string > &tokens, const std::string &str, const std::string delimiters, bool trim)
Tokenize a string, put tokens in a vector.
void TokensToInts(std::vector< int > &values, const std::vector< std::string > &tokens)
Turn a vector of tokens into a vector of ints.