laura is hosted by Hepforge, IPPP Durham
Laura++  v2r1
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauString.cc
Go to the documentation of this file.
1 
2 // Copyright University of Warwick 2008 - 2013.
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 // Authors:
7 // Thomas Latham
8 // John Back
9 // Paul Harrison
10 
15 #include "LauString.hh"
16 
17 #include <iostream>
18 #include <sstream>
19 
20 using std::cout;
21 using std::endl;
22 
23 LauString::LauString() : theString_("")
24 {
25 }
26 
27 LauString::LauString(const char* s) : theString_(s)
28 {
29 }
30 
31 LauString::LauString(const std::string& s) : theString_(s)
32 {
33 }
34 
35 LauString::LauString(const TString& s) : theString_(s.Data())
36 {
37 }
38 
40 {
41 }
42 
43 void LauString::addInteger(int integer)
44 {
45  std::ostringstream o;
46  o << integer;
47  theString_ += o.str();
48 }
49 
51 {
52  std::ostringstream o;
53  o << value;
54  theString_ += o.str();
55 }
56 
58 {
59  this->addInteger(integer);
60  return (*this);
61 }
62 
64 {
65  this->addDouble(value);
66  return (*this);
67 }
68 
70 {
71  this->addText(text);
72  return (*this);
73 }
74 
75 LauString LauString::operator += (const std::string &text)
76 {
77  this->addText(text);
78  return (*this);
79 }
80 
81 LauString LauString::operator += (const TString &text)
82 {
83  this->addText(text.Data());
84  return (*this);
85 }
86 
87 std::vector<std::string> LauString::split(const LauString& splitter) const
88 {
89  std::string splitString = splitter.getString();
90  std::vector<std::string> result = this->split(splitString);
91  return result;
92 }
93 
94 std::vector<std::string> LauString::split(const std::string& splitter) const
95 {
96  // Code from STLplus
97  std::vector<std::string> result;
98 
99  if (!theString_.empty() && !splitter.empty()) {
100 
101  for (std::string::size_type offset = 0;;) {
102 
103  std::string::size_type found = theString_.find(splitter, offset);
104 
105  if (found != std::string::npos) {
106  std::string tmpString = theString_.substr(offset, found-offset);
107  if (tmpString.size() > 0) {result.push_back(tmpString);}
108  offset = found + splitter.size();
109  } else {
110  std::string tmpString = theString_.substr(offset, theString_.size()-offset);
111  if (tmpString.size() > 0) {result.push_back(tmpString);}
112  break;
113  }
114  }
115  }
116 
117  return result;
118 }
File containing declaration of LauString class.
Class for defining a string.
Definition: LauString.hh:29
std::vector< std::string > split(const std::string &splitter) const
Split up a string according to a split string (e.g. &quot;:&quot; or &quot; &quot;)
Definition: LauString.cc:94
LauString operator+=(int integer)
Add an integer to the string.
Definition: LauString.cc:57
void addText(const char *text)
Add some text from a character array.
Definition: LauString.hh:73
std::string theString_
The string.
Definition: LauString.hh:157
void addInteger(int integer)
Add an integer value to the string.
Definition: LauString.cc:43
std::string getString() const
Retrieve the string as an STL string.
Definition: LauString.hh:121
void addDouble(double value)
Add a double value to the string.
Definition: LauString.cc:50
Double_t value() const
The value of the parameter.
virtual ~LauString()
Destructor.
Definition: LauString.cc:39
LauString()
Constructor for an empty string.
Definition: LauString.cc:23