a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models Logo
JustSingleValue.hpp
Go to the documentation of this file.
1/*
2 * JustSingleValue.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 JUSTSINGLEVALUE_HPP_
15#define JUSTSINGLEVALUE_HPP_
16
18
19namespace LHPC
20{
21 namespace SLHA
22 {
23 namespace InterpreterClass
24 {
25 // this template class interprets SLHA blocks that have a single
26 // ValueClass value.
27 template< class ValueClass >
28 class JustSingleValue : public InterpreterTemplate< ValueClass >
29 {
30 public:
32 virtual
34
35 ValueClass&
36 operator()();
37 // this returns the stored ValueType.
38 ValueClass const&
39 operator()() const;
40 // const version of above.
41 bool
42 hasEntry() const;
43 // this returns true if there is an entry.
44 virtual std::string const&
46 // see base version's description.
47 virtual void
49 // derived classes should clear their interpreted values.
50
51
52 protected:
53 ValueClass storedValue;
55
56 virtual void
58 };
59
60
61
62 template< class ValueClass >
63 inline
65 InterpreterTemplate< ValueClass >(),
66 storedValue(),
67 entryRecorded( false )
68 {
69 // just an initialization list.
70 }
71
72 template< class ValueClass >
73 inline
75 {
76 // does nothing.
77 }
78
79
80 template< class ValueClass >
81 inline ValueClass&
83 // this returns the stored ValueType.
84 {
85 return storedValue;
86 }
87
88 template< class ValueClass >
89 inline ValueClass const&
91 // const version of above.
92 {
93 return storedValue;
94 }
95
96 template< class ValueClass >
97 inline bool
99 // this returns true if there is an entry.
100 {
101 return entryRecorded;
102 }
103
104 template< class ValueClass >
105 inline std::string const&
107 // see base version's description.
108 {
109 if( hasEntry() )
110 {
111 this->stringInterpretation.assign( " " );
112 // 6 spaces.
113 this->stringInterpretation.append( this->valueToPrintingString(
114 storedValue ) );
115 this->stringInterpretation.append( "\n" );
116 }
117 else
118 {
119 this->stringInterpretation.clear();
120 }
121 return this->stringInterpretation;
122 }
123
124 template< class ValueClass >
125 inline void
127 // this ensures that the entry at soughtIndex exists, filling out with
128 // copies of defaultUnsetValue, & returns it.
129 {
130 entryRecorded = false;
131 storedValue = this->defaultUnsetValue;
132 }
133
134 template< class ValueClass >
135 inline void
137 {
138 entryRecorded = false;
139 // first it is assumed that this update is on an empty block.
140 for( int whichLine( 1 );
141 ( !entryRecorded
142 &&
143 ( this->currentStringBlock->getNumberOfBodyLines()
144 >= whichLine ) );
145 ++whichLine )
146 // each line after the header (if any) is looked at.
147 {
148 this->currentWord.assign( BOL::StringParser::trimFromFrontAndBack(
149 (*(this->currentStringBlock))[ whichLine ].first,
150 " \t\r\n" ) );
151 if( !(this->currentWord.empty()) )
152 // if there is a non-empty line...
153 {
154 storedValue = this->stringToValue( this->currentWord );
155 entryRecorded = true;
156 }
157 }
158 }
159
160 }
161
162 }
163
164}
165
166#endif /* JUSTSINGLEVALUE_HPP_ */
static std::string trimFromFrontAndBack(std::string const &stringToTrim, std::string const &charsToTrim=whitespaceAndNewlineChars)