FairRoot/PandaRoot
PndStringVector.h
Go to the documentation of this file.
1 // -----------------------------------------------------------------
2 //
3 // TPndStringVector
4 //
5 // Version 1.0
6 // by
7 // Tobias Stockmanns
8 // Seperates an input string into substrings and stores them in a
9 // string vector. The seperation criteria is a string of characters.
10 // If no delimiters are given the default delimiter " " is used.
11 //
12 // Example:
13 // std::vector<std::string> Output
14 // TPndStringVector Input("Column:Row Type: Test ", ": ");
15 // Output = Input.GetStringVector();
16 //
17 // Output[0] = "Column"
18 // Output[1] = "Row"
19 // Output[2] = "Type"
20 // Output[3] = "Test"
21 //
22 #ifndef STRINGVECTOR_H
23 #define STRINGVECTOR_H
24 
25 #include <string>
26 #include <vector>
27 #include "Rtypes.h"
28 
29 
31 {
32  public :
33  PndStringVector():fFirstDel(false),fLastDel(false){};
35  PndStringVector(std::string AInput, std::string ADelimiter = " ");
36  void SetInput (std::string AInput) {fInput = AInput;};
37  void SetDelimiter (std::string ADelimiter) {fDelimiter = ADelimiter;};
38  void ResetVector(){fStrings.clear();};
39  std::vector<std::string> GetStringVector (void);
40  void TestFirst(){if(fInput.find_first_of(fDelimiter)==0) fFirstDel=true; else fFirstDel=false;}
41  void TestLast(){if(fInput.find_last_of(fDelimiter)==fInput.size()-1) fLastDel = true; else fLastDel = false;}
42  void Print();
43 
44  private :
45  std::string::size_type fStartPos;
46  std::vector<std::string> fStrings;
47  std::string fInput;
48  std::string fDelimiter;
49  std::string fOutput;
50  std::string GetString (void);
51  bool fFirstDel; //first element in the string was a delimiter
52  bool fLastDel; //last element in the string was a delimiter
53 };
54 
55 #endif
std::string fDelimiter
std::vector< std::string > GetStringVector(void)
std::string::size_type fStartPos
std::vector< std::string > fStrings
std::string GetString(void)
std::string fInput
void SetInput(std::string AInput)
void SetDelimiter(std::string ADelimiter)
std::string fOutput