PandaRoot
PndStringVector.h
Go to the documentation of this file.
1 //****************************************************************************
2 //* This file is part of PandaRoot. *
3 //* *
4 //* PandaRoot is distributed under the terms of the *
5 //* GNU General Public License (GPL) version 3, *
6 //* copied verbatim in the file "LICENSE". *
7 //* *
8 //* Copyright (C) 2006 - 2024 FAIR GmbH and copyright holders of PandaRoot *
9 //* The copyright holders are listed in the file "COPYRIGHTHOLDERS". *
10 //* The authors are listed in the file "AUTHORS". *
11 //****************************************************************************
12 
13 // -----------------------------------------------------------------
14 //
15 // TPndStringVector
16 //
17 // Version 1.0
18 // by
19 // Tobias Stockmanns
20 // Seperates an input string into substrings and stores them in a
21 // string vector. The seperation criteria is a string of characters.
22 // If no delimiters are given the default delimiter " " is used.
23 //
24 // Example:
25 // std::vector<std::string> Output
26 // TPndStringVector Input("Column:Row Type: Test ", ": ");
27 // Output = Input.GetStringVector();
28 //
29 // Output[0] = "Column"
30 // Output[1] = "Row"
31 // Output[2] = "Type"
32 // Output[3] = "Test"
33 //
34 #ifndef STRINGVECTOR_H
35 #define STRINGVECTOR_H
36 
37 #include <string>
38 #include <vector>
39 #include "Rtypes.h"
40 
42  public:
43  PndStringVector() : fFirstDel(false), fLastDel(false){};
45  PndStringVector(std::string AInput, std::string ADelimiter = " ");
46  void SetInput(std::string AInput) { fInput = AInput; };
47  void SetDelimiter(std::string ADelimiter) { fDelimiter = ADelimiter; };
48  void ResetVector() { fStrings.clear(); };
49  std::vector<std::string> GetStringVector(void);
50  void TestFirst()
51  {
52  if (fInput.find_first_of(fDelimiter) == 0)
53  fFirstDel = true;
54  else
55  fFirstDel = false;
56  }
57  void TestLast()
58  {
59  if (fInput.find_last_of(fDelimiter) == fInput.size() - 1)
60  fLastDel = true;
61  else
62  fLastDel = false;
63  }
64  void Print();
65 
66  private:
67  std::string::size_type fStartPos;
68  std::vector<std::string> fStrings;
69  std::string fInput;
70  std::string fDelimiter;
71  std::string fOutput;
72  std::string GetString(void);
73  bool fFirstDel; // first element in the string was a delimiter
74  bool fLastDel; // last element in the string was a delimiter
75 };
76 
77 #endif
void SetInput(std::string AInput)
void SetDelimiter(std::string ADelimiter)
std::vector< std::string > GetStringVector(void)