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 2001-2010 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 
00076 public:
00078     StringTokenizer() { }
00079 
00084     StringTokenizer(std::string tosplit);
00085 
00091     StringTokenizer(std::string tosplit, std::string token, bool splitAtAllChars=false);
00092 
00100     StringTokenizer(std::string tosplit, int special);
00101 
00103     ~StringTokenizer();
00104 
00106     void reinit();
00107 
00109     bool hasNext();
00110 
00113     std::string next();
00114 
00116     size_t size() const;
00117 
00119     std::string front();
00120 
00122     std::string get(size_t pos) const;
00123 
00124     std::vector<std::string> getVector();
00125 
00126 private:
00129     void prepare(const std::string &tosplit, const std::string &token,
00130                  bool splitAtAllChars);
00131 
00133     void prepareWhitechar(const std::string &tosplit);
00134 
00135 private:
00137     typedef std::vector<size_t> SizeVector;
00138 
00140     std::string   myTosplit;
00141 
00143     size_t        myPos;
00144 
00146     SizeVector    myStarts;
00147 
00149     SizeVector   myLengths;
00150 
00151 };
00152 
00153 
00154 #endif
00155 
00156 /****************************************************************************/
00157 

Generated on Wed May 5 00:06:36 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6