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 
30  public:
31  PndStringVector() : fFirstDel(false), fLastDel(false){};
33  PndStringVector(std::string AInput, std::string ADelimiter = " ");
34  void SetInput(std::string AInput) { fInput = AInput; };
35  void SetDelimiter(std::string ADelimiter) { fDelimiter = ADelimiter; };
36  void ResetVector() { fStrings.clear(); };
37  std::vector<std::string> GetStringVector(void);
38  void TestFirst()
39  {
40  if (fInput.find_first_of(fDelimiter) == 0)
41  fFirstDel = true;
42  else
43  fFirstDel = false;
44  }
45  void TestLast()
46  {
47  if (fInput.find_last_of(fDelimiter) == fInput.size() - 1)
48  fLastDel = true;
49  else
50  fLastDel = false;
51  }
52  void Print();
53 
54  private:
55  std::string::size_type fStartPos;
56  std::vector<std::string> fStrings;
57  std::string fInput;
58  std::string fDelimiter;
59  std::string fOutput;
60  std::string GetString(void);
61  bool fFirstDel; // first element in the string was a delimiter
62  bool fLastDel; // last element in the string was a delimiter
63 };
64 
65 #endif
void SetInput(std::string AInput)
void SetDelimiter(std::string ADelimiter)
std::vector< std::string > GetStringVector(void)