SUMO - Simulation of Urban MObility

StringTokenizer.h

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // A java-style StringTokenizer for c++ (stl)
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors
00011 /****************************************************************************/
00012 //
00013 //   This program is free software; you can redistribute it and/or modify
00014 //   it under the terms of the GNU General Public License as published by
00015 //   the Free Software Foundation; either version 2 of the License, or
00016 //   (at your option) any later version.
00017 //
00018 /****************************************************************************/
00019 #ifndef StringTokenizer_h
00020 #define StringTokenizer_h
00021 
00022 
00023 // ===========================================================================
00024 // included modules
00025 // ===========================================================================
00026 #ifdef _MSC_VER
00027 #include <windows_config.h>
00028 #else
00029 #include <config.h>
00030 #endif
00031 
00032 #include <string>
00033 #include <vector>
00034 
00061 // ===========================================================================
00062 // class definitions
00063 // ===========================================================================
00067 class StringTokenizer {
00068 public:
00070     static const int NEWLINE;
00071 
00074     static const int WHITECHARS;
00075 
00077     static const int SPACE;
00078 
00079 public:
00081     StringTokenizer() { }
00082 
00087     StringTokenizer(std::string tosplit);
00088 
00094     StringTokenizer(std::string tosplit, std::string token, bool splitAtAllChars=false);
00095 
00103     StringTokenizer(std::string tosplit, int special);
00104 
00106     ~StringTokenizer();
00107 
00109     void reinit();
00110 
00112     bool hasNext();
00113 
00116     std::string next();
00117 
00119     size_t size() const;
00120 
00122     std::string front();
00123 
00125     std::string get(size_t pos) const;
00126 
00127     std::vector<std::string> getVector();
00128 
00129 private:
00132     void prepare(const std::string& tosplit, const std::string& token,
00133                  bool splitAtAllChars);
00134 
00136     void prepareWhitechar(const std::string& tosplit);
00137 
00138 private:
00140     typedef std::vector<size_t> SizeVector;
00141 
00143     std::string   myTosplit;
00144 
00146     size_t        myPos;
00147 
00149     SizeVector    myStarts;
00150 
00152     SizeVector   myLengths;
00153 
00154 };
00155 
00156 
00157 #endif
00158 
00159 /****************************************************************************/
00160 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines