a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models Logo
InterpreterTemplate.hpp
Go to the documentation of this file.
1/*
2 * InterpreterTemplate.hpp
3 *
4 * Created on: Feb 8, 2012
5 * Author: Ben O'Leary (benjamin.oleary@gmail.com)
6 * Copyright 2012 Ben O'Leary
7 *
8 * This file is part of LesHouchesParserClasses, released under the
9 * GNU General Public License. Please see the accompanying
10 * README.LHPC_CPP.txt file for a full list of files, brief documentation
11 * on how to use these classes, and further details on the license.
12 */
13
14#ifndef INTERPRETERTEMPLATE_HPP_
15#define INTERPRETERTEMPLATE_HPP_
16
18#include "BlockInterpreter.hpp"
19#include "../../../MEC/ExtendedMass.hpp"
20
21namespace LHPC
22{
23 namespace SLHA
24 {
25 namespace InterpreterClass
26 {
27 // this template class derives from SlhaBlock to provide a base class for
28 // blocks with values which are indexed in various ways.
29 template< class ValueType >
31 {
32 public:
34 virtual
36
37 virtual void
39 virtual void
40 setVerbosity( bool const isVerbose );
41
42
43 protected:
46 ValueType valueFromString;
47 std::string currentWord;
48 std::string lineRemainderA;
49 std::string lineRemainderB;
50 std::string stringFromValue;
52
53 ValueType const&
54 stringToValue( std::string const& stringToConvert );
55 // this sets valueFromString according to the interpretation of
56 // stringToConvert.
57 std::string const&
58 valueToString( ValueType const& valueToConvert );
59 // this sets stringFromValue according to the interpretation of
60 // valueToConvert.
61 std::string const&
62 valueToPrintingString( ValueType const& valueToPrint );
63 // this puts 3 spaces into valuePrintingString, then
64 // valueToString( valueToPrint ).
65 };
66
67
68
69
70
71 template< class ValueType >
72 inline
75 defaultUnsetValue(),
76 isVerbose( BlockInterpreter::defaultVerbosity ),
77 valueFromString(),
78 currentWord( "" ),
79 lineRemainderA( "" ),
80 lineRemainderB( "" ),
81 stringFromValue( "no_string_interpretation_given" ),
82 valuePrintingString( " no_string_interpretation_given" )
83 {
84 // just an initialization list.
85 }
86
87 template< class ValueType >
88 inline
90 {
91 // does nothing.
92 }
93
94 template< class ValueType >
95 inline void
97 ValueType const& defaultUnsetValue )
98 {
99 this->defaultUnsetValue = defaultUnsetValue;
100 }
101
102 template< class ValueType >
103 inline void
105 {
106 this->isVerbose = isVerbose;
107 }
108
109 template< class ValueType >
110 inline ValueType const&
112 std::string const& stringToConvert )
113 /* this sets valueFromString according to the interpretation of
114 * stringToConvert. this default version leaves stringFromValue as
115 * defaultUnsetValue.
116 */
117 {
118 //return defaultUnsetValue;
119 valueFromString.setFromString( stringToConvert );
120 return valueFromString;
121 }
122
123 template<>
124 inline int const&
126 std::string const& stringToConvert )
127 // this sets valueFromString according to the interpretation of
128 // stringToConvert.
129 {
130 valueFromString = BOL::StringParser::stringToInt( stringToConvert );
131 return valueFromString;
132 }
133
134 template<>
135 inline double const&
137 std::string const& stringToConvert )
138 // this sets valueFromString according to the interpretation of
139 // stringToConvert.
140 {
141 valueFromString = BOL::StringParser::stringToDouble( stringToConvert );
142 return valueFromString;
143 }
144
145 template<>
146 inline std::pair< double, double > const&
148 std::string const& stringToConvert )
149 // this sets valueFromString according to the interpretation of
150 // stringToConvert.
151 {
152 this->currentWord.assign( BOL::StringParser::firstWordOf(
153 stringToConvert,
154 &(this->lineRemainderA),
156 valueFromString.first
157 = BOL::StringParser::stringToDouble( this->currentWord );
158 valueFromString.second
159 = BOL::StringParser::stringToDouble( this->lineRemainderA );
160 return valueFromString;
161 }
162
163 template<>
164 inline std::string const&
166 std::string const& stringToConvert )
167 // this sets valueFromString according to the interpretation of
168 // stringToConvert.
169 {
170 valueFromString.assign( stringToConvert );
171 return valueFromString;
172 }
173
174 /*template<>
175 inline ExtendedMass const&
176 InterpreterTemplate< ExtendedMass >::stringToValue(
177 std::string const& stringToConvert )
178 // this sets valueFromString according to the interpretation of
179 // stringToConvert.
180 {
181 this->currentWord.assign( BOL::StringParser::firstWordOf(
182 stringToConvert,
183 &(this->lineRemainderA),
184 BOL::StringParser::whitespaceAndNewlineChars ) );
185 double
186 parsedDouble( BOL::StringParser::stringToDouble( currentWord ) );
187 this->currentWord.assign( BOL::StringParser::firstWordOf(
188 this->lineRemainderA,
189 &(this->lineRemainderB),
190 BOL::StringParser::whitespaceAndNewlineChars ) );
191 valueFromString.setValues( parsedDouble,
192 BOL::StringParser::stringToInt( this->currentWord ),
193 BOL::StringParser::stringToDouble( this->lineRemainderB ) );
194 return valueFromString;
195 }*/
196
197 template< class ValueType >
198 inline std::string const&
200 ValueType const& valueToConvert )
201 /* this sets stringFromValue according to the interpretation of
202 * valueToConvert. this default version leaves stringFromValue as a
203 * default error string.
204 */
205 {
206 stringFromValue.assign( valueToConvert.getAsString() );
207 return stringFromValue;
208 }
209
210 template<>
211 inline std::string const&
212 InterpreterTemplate< int >::valueToString( int const& valueToConvert )
213 // this sets stringFromValue according to the interpretation of
214 // valueToConvert.
215 {
216 stringFromValue.assign( BOL::StringParser::intToString( valueToConvert,
217 1,
218 "",
219 "-",
220 ' ' ) );
221 return stringFromValue;
222 }
223
224 template<>
225 inline std::string const&
227 double const& valueToConvert )
228 // this sets stringFromValue according to the interpretation of
229 // valueToConvert.
230 {
231 stringFromValue.assign( slhaDoubleMaker.doubleToString(
232 valueToConvert ) );
233 return stringFromValue;
234 }
235
236 template<>
237 inline std::string const&
239 std::pair< double, double > const& valueToConvert )
240 // this sets stringFromValue according to the interpretation of
241 // valueToConvert.
242 {
243 stringFromValue.assign( slhaDoubleMaker.doubleToString(
244 valueToConvert.first ) );
245 stringFromValue.append( " " );
246 stringFromValue.append( slhaDoubleMaker.doubleToString(
247 valueToConvert.second ) );
248 return stringFromValue;
249 }
250
251 template<>
252 inline std::string const&
254 std::string const& valueToConvert )
255 // this sets stringFromValue according to the interpretation of
256 // valueToConvert.
257 {
258 stringFromValue.assign( valueToConvert );
259 return stringFromValue;
260 }
261
262 /*template<>
263 inline std::string const&
264 InterpreterTemplate< ExtendedMass >::valueToString(
265 ExtendedMass const& valueToConvert )
266 // this sets stringFromValue according to the interpretation of
267 // valueToConvert.
268 {
269 stringFromValue.assign( slhaDoubleMaker.doubleToString(
270 valueToConvert.getValue() ) );
271 stringFromValue.append( " " );
272 stringFromValue.append( BOL::StringParser::intToString(
273 valueToConvert.getScheme(),
274 2,
275 "",
276 "-",
277 ' ' ) );
278 stringFromValue.append( " " );
279 stringFromValue.append( slhaDoubleMaker.doubleToString(
280 valueToConvert.getScale() ) );
281 return stringFromValue;
282 }*/
283
284 template< class ValueType >
285 inline std::string const&
287 ValueType const& valueToPrint )
288 // this puts 3 spaces into returnString, then
289 // valueToString( valueToPrint ).
290 {
291 valuePrintingString.assign( " " );
292 valuePrintingString.append( this->valueToString( valueToPrint ) );
293 return valuePrintingString;
294 }
295
296 }
297
298 }
299
300}
301
302#endif /* INTERPRETERTEMPLATE_HPP_ */
static std::string firstWordOf(std::string const &stringToParse, std::string *const remainderString=NULL, std::string const &separatorChars=whitespaceChars)
static std::string const whitespaceAndNewlineChars
static double stringToDouble(std::string const &stringToInterpret)
static std::string intToString(int inputInt, int const minimumNumberOfDigits, std::string const prefixForPositiveNumbers="+", std::string const prefixForNegativeNumbers="-", char const paddingChar='0')
static int stringToInt(std::string const &stringToInterpret)
ValueType const & stringToValue(std::string const &stringToConvert)
std::string const & valueToString(ValueType const &valueToConvert)
std::string const & valueToPrintingString(ValueType const &valueToPrint)
virtual void setDefaultUnsetValue(ValueType const &defaultUnsetValue)