laura is hosted by Hepforge, IPPP Durham
Laura++  v3r5
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauString.cc
Go to the documentation of this file.
1 
2 /*
3 Copyright 2008 University of Warwick
4 
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8 
9  http://www.apache.org/licenses/LICENSE-2.0
10 
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16 */
17 
18 /*
19 Laura++ package authors:
20 John Back
21 Paul Harrison
22 Thomas Latham
23 */
24 
29 #include "LauString.hh"
30 
31 #include <iostream>
32 #include <sstream>
33 
34 using std::cout;
35 using std::endl;
36 
37 LauString::LauString() : theString_("")
38 {
39 }
40 
41 LauString::LauString(const char* s) : theString_(s)
42 {
43 }
44 
45 LauString::LauString(const std::string& s) : theString_(s)
46 {
47 }
48 
49 LauString::LauString(const TString& s) : theString_(s.Data())
50 {
51 }
52 
53 LauString::LauString(const LauString& s) : theString_(s.theString_)
54 {
55 }
56 
58 {
59  if ( this != &s ) {
61  }
62  return *this;
63 }
64 
66 {
67 }
68 
69 void LauString::addInteger(int integer)
70 {
71  std::ostringstream o;
72  o << integer;
73  theString_ += o.str();
74 }
75 
77 {
78  std::ostringstream o;
79  o << value;
80  theString_ += o.str();
81 }
82 
84 {
85  this->addInteger(integer);
86  return (*this);
87 }
88 
90 {
91  this->addDouble(value);
92  return (*this);
93 }
94 
96 {
97  this->addText(text);
98  return (*this);
99 }
100 
101 LauString LauString::operator += (const std::string &text)
102 {
103  this->addText(text);
104  return (*this);
105 }
106 
107 LauString LauString::operator += (const TString &text)
108 {
109  this->addText(text.Data());
110  return (*this);
111 }
112 
113 std::vector<std::string> LauString::split(const LauString& splitter) const
114 {
115  std::string splitString = splitter.getString();
116  std::vector<std::string> result = this->split(splitString);
117  return result;
118 }
119 
120 std::vector<std::string> LauString::split(const std::string& splitter) const
121 {
122  // Code from STLplus
123  std::vector<std::string> result;
124 
125  if (!theString_.empty() && !splitter.empty()) {
126 
127  for (std::string::size_type offset = 0;;) {
128 
129  std::string::size_type found = theString_.find(splitter, offset);
130 
131  if (found != std::string::npos) {
132  std::string tmpString = theString_.substr(offset, found-offset);
133  if (tmpString.size() > 0) {result.push_back(tmpString);}
134  offset = found + splitter.size();
135  } else {
136  std::string tmpString = theString_.substr(offset, theString_.size()-offset);
137  if (tmpString.size() > 0) {result.push_back(tmpString);}
138  break;
139  }
140  }
141  }
142 
143  return result;
144 }
File containing declaration of LauString class.
Class for defining a string.
Definition: LauString.hh:43
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:120
LauString operator+=(int integer)
Add an integer to the string.
Definition: LauString.cc:83
void addText(const char *text)
Add some text from a character array.
Definition: LauString.hh:93
LauString & operator=(const LauString &s)
Copy assignment operator.
Definition: LauString.cc:57
std::string theString_
The string.
Definition: LauString.hh:177
void addInteger(int integer)
Add an integer value to the string.
Definition: LauString.cc:69
std::string getString() const
Retrieve the string as an STL string.
Definition: LauString.hh:141
void addDouble(double value)
Add a double value to the string.
Definition: LauString.cc:76
Double_t value() const
The value of the parameter.
virtual ~LauString()
Destructor.
Definition: LauString.cc:65
LauString()
Constructor for an empty string.
Definition: LauString.cc:37