PGROUTING  2.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bd_astar/tester/utils.h
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 
3 Copyright (c) 2015 pgRouting developers
4 Mail: project@pgrouting.org
5 
6 ------
7 
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12 
13 This program 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
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 
22 ********************************************************************PGR-GNU*/
23 
24 #ifndef UTILS_H
25 #define UTILS_H
26 
27 #include <string>
28 #include <map>
29 #include <vector>
30 #include <queue>
31 #include <iostream>
32 
33 
34 
35 
36 typedef std::vector<long> LongVector;
37 typedef std::vector<int> IntVector;
38 typedef std::vector<double> DoubleVector;
39 typedef std::vector<std::string> StringVector;
40 
41 
43 {
44 
45 public:
46 
47  static std::string TRIMWHITESPACE(std::string strInput)
48  {
49  std::string strOut = strInput;
50  std::string strWht = " \f\n\r\t\v";
51 
52  strOut.erase(0,strOut.find_first_not_of(strWht));
53  strOut.erase(strOut.find_last_not_of(strWht) + 1);
54  return strOut;
55  };
56 };
57 
59 {
60 public:
62  {
63  reset();
64  }
65 
66  void reset()
67  {
68  vecTokens.clear();
69  strInput = "";
70  }
71 
72  bool parse(std::string strInput, std::string chDelim)
73  {
74  size_t iStartPos = 0;
75  while(true)
76  {
77  size_t iPos = strInput.find(chDelim[0],iStartPos);
78  if(iPos != std::string::npos)
79  {
80  std::string strToken;
81  strToken = strInput.substr(iStartPos,iPos - iStartPos);
82  vecTokens.push_back(strToken);
83  iStartPos = iPos + 1;
84  }
85  else if(iPos == std::string::npos && strInput.length() > 0 )
86  {
87  std::string strToken;
88  strToken = strInput.substr(iStartPos, strInput.length() - iStartPos);
89  if(strToken.length() > 0)
90  vecTokens.push_back(strToken);
91  break;
92  }
93  else
94  break;
95 
96  }
97  return true;
98  }
99 
100  size_t getTokenCount()
101  {
102  return vecTokens.size();
103  }
104 
105  bool getToken(std::string& strToken, size_t iTokenIndex)
106  {
107  long lTokenCount = vecTokens.size();
108  if(iTokenIndex < 0 || iTokenIndex < lTokenCount)
109  {
110  strToken = vecTokens[iTokenIndex];
111  return true;
112  }
113  return false;
114  }
115 
116  bool getTokens(StringVector& vecTokensRef)
117  {
118  vecTokensRef = vecTokens;
119  return true;
120  }
121 
122 private:
123  std::string strInput;
125 
126 };
127 
128 #endif
bool parse(std::string strInput, std::string chDelim)
std::vector< int > IntVector
bool getTokens(StringVector &vecTokensRef)
std::vector< std::string > StringVector
bool getToken(std::string &strToken, size_t iTokenIndex)
std::vector< long > LongVector
std::vector< double > DoubleVector
static std::string TRIMWHITESPACE(std::string strInput)