SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00009 // A java-style StringTokenizer for c++ (stl) 00010 /****************************************************************************/ 00011 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00012 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00013 /****************************************************************************/ 00014 // 00015 // This file is part of SUMO. 00016 // SUMO is free software: you can redistribute it and/or modify 00017 // it under the terms of the GNU General Public License as published by 00018 // the Free Software Foundation, either version 3 of the License, or 00019 // (at your option) any later version. 00020 // 00021 /****************************************************************************/ 00022 #ifndef StringTokenizer_h 00023 #define StringTokenizer_h 00024 00025 00026 // =========================================================================== 00027 // included modules 00028 // =========================================================================== 00029 #ifdef _MSC_VER 00030 #include <windows_config.h> 00031 #else 00032 #include <config.h> 00033 #endif 00034 00035 #include <string> 00036 #include <vector> 00037 00064 // =========================================================================== 00065 // class definitions 00066 // =========================================================================== 00070 class StringTokenizer { 00071 public: 00073 static const int NEWLINE; 00074 00077 static const int WHITECHARS; 00078 00080 static const int SPACE; 00081 00082 public: 00084 StringTokenizer() { } 00085 00090 StringTokenizer(std::string tosplit); 00091 00097 StringTokenizer(std::string tosplit, std::string token, bool splitAtAllChars = false); 00098 00106 StringTokenizer(std::string tosplit, int special); 00107 00109 ~StringTokenizer(); 00110 00112 void reinit(); 00113 00115 bool hasNext(); 00116 00119 std::string next(); 00120 00122 size_t size() const; 00123 00125 std::string front(); 00126 00128 std::string get(size_t pos) const; 00129 00130 std::vector<std::string> getVector(); 00131 00132 private: 00135 void prepare(const std::string& tosplit, const std::string& token, 00136 bool splitAtAllChars); 00137 00139 void prepareWhitechar(const std::string& tosplit); 00140 00141 private: 00143 typedef std::vector<size_t> SizeVector; 00144 00146 std::string myTosplit; 00147 00149 size_t myPos; 00150 00152 SizeVector myStarts; 00153 00155 SizeVector myLengths; 00156 00157 }; 00158 00159 00160 #endif 00161 00162 /****************************************************************************/ 00163