Psi4
libpsi4util.h
Go to the documentation of this file.
1 /*
2  * @BEGIN LICENSE
3  *
4  * Psi4: an open-source quantum chemistry software package
5  *
6  * Copyright (c) 2007-2017 The Psi4 Developers.
7  *
8  * The copyrights for code used from other parties are included in
9  * the corresponding files.
10  *
11  * This file is part of Psi4.
12  *
13  * Psi4 is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU Lesser General Public License as published by
15  * the Free Software Foundation, version 3.
16  *
17  * Psi4 is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License along
23  * with Psi4; if not, write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  *
26  * @END LICENSE
27  */
28 
29 #ifndef _psi_src_lib_libpsi4util_libpsi4util_h_
30 #define _psi_src_lib_libpsi4util_libpsi4util_h_
31 
32 #include <string>
33 #include <vector>
34 #include <algorithm>
35 #include <sys/time.h>
36 
37 namespace psi {
38 
39 typedef std::vector<std::string> strvec;
40 
41 std::string file_to_string(std::string const &name);
42 
43 bool space(char c);
44 
45 bool not_space(char c);
46 
47 std::vector<std::string> split(const std::string &str);
48 
49 std::vector<std::string> split_indices(const std::string &str);
50 
51 void to_lower(std::string &str);
52 std::string to_lower_copy(const std::string &str);
53 
54 void to_upper(std::string &str);
55 std::string to_upper_copy(const std::string &str);
56 
57 std::string to_string(const int val);
58 
59 std::string to_string(const double val);
60 
61 double to_double(const std::string str);
62 
63 int to_integer(const std::string inString);
64 
65 void append_reference(std::string &str, int reference);
66 
67 std::string add_reference(std::string &str, int reference);
68 
69 void append_reference(std::string &str, int reference);
70 
71 std::string find_and_replace(std::string &source, const std::string &target,
72  const std::string &replace);
73 
74 void trim_spaces(std::string &str);
75 
76 template <typename Range1T, typename Range2T>
77 bool iequals(const Range1T &Input, const Range2T &Test){
78  if (std::distance(std::begin(Input), std::end(Input)) !=
79  std::distance(std::begin(Test), std::end(Test)))
80  return false;
81 
82  return std::equal(
83  std::begin(Input), std::end(Input), std::begin(Test),
84  [](unsigned char a, unsigned char b) { return std::tolower(a) == std::tolower(b); });
85 }
86 
87 std::vector<std::string> split(const std::string &input, const std::string &regex);
88 
95 size_t edit_distance(const std::string &s1, const std::string &s2);
96 
97 class Timer {
98  public:
99  Timer();
100  double get();
101 
102  private:
103  struct timeval ___start, ___end;
104  struct timezone ___dummy;
108 };
109 
110 void generate_combinations(int n, int k, std::vector<std::vector<int>> &combinations);
111 }
112 
113 #endif // _psi_src_lib_libpsi4util_libpsi4util_h_
std::string to_string(const int val)
Definition: stl_string.cc:209
std::string find_and_replace(std::string &source, const std::string &target, const std::string &replace)
Definition: stl_string.cc:130
struct timeval ___start ___end
Definition: libpsi4util.h:103
std::string add_reference(std::string &str, int reference)
Definition: stl_string.cc:231
void to_lower(std::string &str)
Definition: stl_string.cc:180
void generate_combinations(int n, int k, std::vector< std::vector< int > > &combinations)
Definition: combinations.cc:42
std::vector< std::string > split(const std::string &str)
Definition: stl_string.cc:51
Timer()
Definition: stl_string.cc:237
size_t edit_distance(const std::string &s1, const std::string &s2)
Compute the Levenshtein distance between two strings.
Definition: stl_string.cc:159
std::vector< std::string > strvec
Definition: libpsi4util.h:39
int to_integer(const std::string inString)
Definition: stl_string.cc:223
void trim_spaces(std::string &str)
Definition: stl_string.cc:146
double combinations(int n, int k)
Definition: probabil.cc:51
void reference(void)
Definition: reference.cc:50
bool iequals(const Range1T &Input, const Range2T &Test)
Definition: libpsi4util.h:77
void to_upper(std::string &str)
Definition: stl_string.cc:192
std::string file_to_string(std::string const &name)
std::string to_lower_copy(const std::string &str)
Definition: stl_string.cc:185
double delta_time_days
Definition: libpsi4util.h:107
double delta_time_hours
Definition: libpsi4util.h:106
struct timezone ___dummy
Definition: libpsi4util.h:104
double delta_time_seconds
Definition: libpsi4util.h:105
bool not_space(char c)
Definition: stl_string.cc:124
double to_double(const std::string str)
Definition: stl_string.cc:204
std::string to_upper_copy(const std::string &str)
Definition: stl_string.cc:197
bool space(char c)
Definition: stl_string.cc:119
std::vector< std::string > split_indices(const std::string &str)
Definition: stl_string.cc:90
Definition: libpsi4util.h:97
void append_reference(std::string &str, int reference)
Definition: stl_string.cc:235