PGROUTING  2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
utils.h
Go to the documentation of this file.
1 /*
2  * Shortest path with turn restrictions algorithm for PostgreSQL
3  *
4  * Copyright (c) 2011 Stephen Woodbridge
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  *
20  */
21 
22 #ifndef SRC_TRSP_SRC_UTILS_H_
23 #define SRC_TRSP_SRC_UTILS_H_
24 
25 #include <string>
26 #include <map>
27 #include <vector>
28 #include <queue>
29 #include <iostream>
30 
31 
32 
33 
34 typedef std::vector<long> LongVector;
35 typedef std::vector<int> IntVector;
36 typedef std::vector<double> DoubleVector;
37 typedef std::vector<std::string> StringVector;
38 
39 
41  public:
42  static std::string TRIMWHITESPACE(std::string strInput) {
43  std::string strOut = strInput;
44  std::string strWht = " \f\n\r\t\v";
45  strOut.erase(0, strOut.find_first_not_of(strWht));
46  strOut.erase(strOut.find_last_not_of(strWht) + 1);
47  return strOut;
48  };
49 };
50 
52  public:
54  reset();
55  }
56  void reset() {
57  vecTokens.clear();
58  strInput = "";
59  }
60  bool parse(std::string strInput, std::string chDelim) {
61  size_t iStartPos = 0;
62  while (true) {
63  size_t iPos = strInput.find(chDelim[0], iStartPos);
64  if (iPos != std::string::npos) {
65  std::string strToken;
66  strToken = strInput.substr(iStartPos, iPos - iStartPos);
67  vecTokens.push_back(strToken);
68  iStartPos = iPos + 1;
69  } else if (iPos == std::string::npos && strInput.length() > 0) {
70  std::string strToken;
71  strToken = strInput.substr(iStartPos,
72  strInput.length() - iStartPos);
73  if (strToken.length() > 0)
74  vecTokens.push_back(strToken);
75  break;
76  } else {
77  break;
78  }
79  }
80  return true;
81  }
82  size_t getTokenCount() {
83  return vecTokens.size();
84  }
85 
86  bool getToken(std::string& strToken, long iTokenIndex) {
87  long lTokenCount = vecTokens.size();
88  if (iTokenIndex < 0 || iTokenIndex < lTokenCount) {
89  strToken = vecTokens[iTokenIndex];
90  return true;
91  }
92  return false;
93  }
94 
95  bool getTokens(StringVector& vecTokensRef) {
96  vecTokensRef = vecTokens;
97  return true;
98  }
99 
100  private:
101  std::string strInput;
103 };
104 
105 #endif // SRC_TRSP_SRC_UTILS_H_
bool getToken(std::string &strToken, long iTokenIndex)
Definition: utils.h:86
bool parse(std::string strInput, std::string chDelim)
Definition: utils.h:60
std::vector< double > DoubleVector
Definition: utils.h:36
std::vector< int > IntVector
Definition: utils.h:35
StringTokenizer()
Definition: utils.h:53
std::vector< std::string > StringVector
Definition: utils.h:37
StringVector vecTokens
Definition: utils.h:102
void reset()
Definition: utils.h:56
bool getTokens(StringVector &vecTokensRef)
Definition: utils.h:95
std::vector< long > LongVector
Definition: utils.h:34
static std::string TRIMWHITESPACE(std::string strInput)
Definition: utils.h:42
std::string strInput
Definition: utils.h:101
size_t getTokenCount()
Definition: utils.h:82