laura is hosted by Hepforge, IPPP Durham
Laura++  v2r2
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 
39 LauString::LauString(const LauString& s) : theString_(s.theString_)
40 {
41 }
42 
44 {
45  if ( this != &s ) {
47  }
48  return *this;
49 }
50 
52 {
53 }
54 
55 void LauString::addInteger(int integer)
56 {
57  std::ostringstream o;
58  o << integer;
59  theString_ += o.str();
60 }
61 
63 {
64  std::ostringstream o;
65  o << value;
66  theString_ += o.str();
67 }
68 
70 {
71  this->addInteger(integer);
72  return (*this);
73 }
74 
76 {
77  this->addDouble(value);
78  return (*this);
79 }
80 
82 {
83  this->addText(text);
84  return (*this);
85 }
86 
87 LauString LauString::operator += (const std::string &text)
88 {
89  this->addText(text);
90  return (*this);
91 }
92 
93 LauString LauString::operator += (const TString &text)
94 {
95  this->addText(text.Data());
96  return (*this);
97 }
98 
99 std::vector<std::string> LauString::split(const LauString& splitter) const
100 {
101  std::string splitString = splitter.getString();
102  std::vector<std::string> result = this->split(splitString);
103  return result;
104 }
105 
106 std::vector<std::string> LauString::split(const std::string& splitter) const
107 {
108  // Code from STLplus
109  std::vector<std::string> result;
110 
111  if (!theString_.empty() && !splitter.empty()) {
112 
113  for (std::string::size_type offset = 0;;) {
114 
115  std::string::size_type found = theString_.find(splitter, offset);
116 
117  if (found != std::string::npos) {
118  std::string tmpString = theString_.substr(offset, found-offset);
119  if (tmpString.size() > 0) {result.push_back(tmpString);}
120  offset = found + splitter.size();
121  } else {
122  std::string tmpString = theString_.substr(offset, theString_.size()-offset);
123  if (tmpString.size() > 0) {result.push_back(tmpString);}
124  break;
125  }
126  }
127  }
128 
129  return result;
130 }
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:106
LauString operator+=(int integer)
Add an integer to the string.
Definition: LauString.cc:69
void addText(const char *text)
Add some text from a character array.
Definition: LauString.hh:79
LauString & operator=(const LauString &s)
Copy assignment operator.
Definition: LauString.cc:43
std::string theString_
The string.
Definition: LauString.hh:163
void addInteger(int integer)
Add an integer value to the string.
Definition: LauString.cc:55
std::string getString() const
Retrieve the string as an STL string.
Definition: LauString.hh:127
void addDouble(double value)
Add a double value to the string.
Definition: LauString.cc:62
Double_t value() const
The value of the parameter.
virtual ~LauString()
Destructor.
Definition: LauString.cc:51
LauString()
Constructor for an empty string.
Definition: LauString.cc:23