laura is hosted by Hepforge, IPPP Durham
Laura++  3.6.0
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 
38  theString_( "" )
39 {
40 }
41 
42 LauString::LauString( const char* s ) :
43  theString_( s )
44 {
45 }
46 
47 LauString::LauString( const std::string& s ) :
48  theString_( s )
49 {
50 }
51 
52 LauString::LauString( const TString& s ) :
53  theString_( s.Data() )
54 {
55 }
56 
58  theString_( s.theString_ )
59 {
60 }
61 
63 {
64  if ( this != &s ) {
66  }
67  return *this;
68 }
69 
71 {
72 }
73 
74 void LauString::addInteger( int integer )
75 {
76  std::ostringstream o;
77  o << integer;
78  theString_ += o.str();
79 }
80 
82 {
83  std::ostringstream o;
84  o << value;
85  theString_ += o.str();
86 }
87 
89 {
90  this->addInteger( integer );
91  return ( *this );
92 }
93 
95 {
96  this->addDouble( value );
97  return ( *this );
98 }
99 
100 LauString LauString::operator+=( const char* text )
101 {
102  this->addText( text );
103  return ( *this );
104 }
105 
106 LauString LauString::operator+=( const std::string& text )
107 {
108  this->addText( text );
109  return ( *this );
110 }
111 
112 LauString LauString::operator+=( const TString& text )
113 {
114  this->addText( text.Data() );
115  return ( *this );
116 }
117 
118 std::vector<std::string> LauString::split( const LauString& splitter ) const
119 {
120  std::string splitString = splitter.getString();
121  std::vector<std::string> result = this->split( splitString );
122  return result;
123 }
124 
125 std::vector<std::string> LauString::split( const std::string& splitter ) const
126 {
127  // Code from STLplus
128  std::vector<std::string> result;
129 
130  if ( ! theString_.empty() && ! splitter.empty() ) {
131 
132  for ( std::string::size_type offset = 0;; ) {
133 
134  std::string::size_type found = theString_.find( splitter, offset );
135 
136  if ( found != std::string::npos ) {
137  std::string tmpString = theString_.substr( offset, found - offset );
138  if ( tmpString.size() > 0 ) {
139  result.push_back( tmpString );
140  }
141  offset = found + splitter.size();
142  } else {
143  std::string tmpString = theString_.substr( offset, theString_.size() - offset );
144  if ( tmpString.size() > 0 ) {
145  result.push_back( tmpString );
146  }
147  break;
148  }
149  }
150  }
151 
152  return result;
153 }
void addText(const char *text)
Add some text from a character array.
Definition: LauString.hh:92
Double_t value() const
The value of the parameter.
LauString()
Constructor for an empty string.
Definition: LauString.cc:37
std::string getString() const
Retrieve the string as an STL string.
Definition: LauString.hh:140
LauString operator+=(int integer)
Add an integer to the string.
Definition: LauString.cc:88
std::string theString_
The string.
Definition: LauString.hh:176
void addDouble(double value)
Add a double value to the string.
Definition: LauString.cc:81
LauString & operator=(const LauString &s)
Copy assignment operator.
Definition: LauString.cc:62
File containing declaration of LauString class.
Class for defining a string.
Definition: LauString.hh:43
void addInteger(int integer)
Add an integer value to the string.
Definition: LauString.cc:74
std::vector< std::string > split(const std::string &splitter) const
Split up a string according to a split string (e.g. ":" or " ")
Definition: LauString.cc:125
virtual ~LauString()
Destructor.
Definition: LauString.cc:70