a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models Logo
DenseTriplyIndexed.hpp
Go to the documentation of this file.
1/*
2 * DenseTriplyIndexed.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 DENSETRIPLYINDEXED_HPP_
15#define DENSETRIPLYINDEXED_HPP_
16
18
19namespace LHPC
20{
21 namespace SLHA
22 {
23 namespace InterpreterClass
24 {
25 /* this template class derives from InterpreterTemplate to interpret
26 * SLHA blocks that have a triple of int indices with a single ValueClass
27 * value.
28 */
29 template< class ValueClass >
30 class DenseTriplyIndexed : public IndexedInterpreter< ValueClass >
31 {
32 public:
34 virtual
36
37 ValueClass&
38 operator()( int firstIndex,
39 int secondIndex,
40 int thirdIndex );
41 /* this returns the ValueClass indexed by firstIndex, secondIndex, &
42 * thirdIndex. if there is no element at the sought indices,
43 * valueMatrixArray is extended with copies of defaultUnsetValue until
44 * there is an element at the sought indices.
45 */
46 ValueClass const&
47 operator()( int firstIndex,
48 int secondIndex,
49 int thirdIndex ) const;
50 /* const version of above, though it returns defaultUnsetValue rather
51 * than copying in a new element at the sought indices if there isn't
52 * an entry there already.
53 */
54 bool
55 hasEntry( int const firstIndex,
56 int const secondIndex,
57 int const thirdIndex ) const;
58 // this returns true if there is an entry at the sought indices.
59 virtual std::string const&
61 // see base version's description.
62 virtual void
64 // derived classes should clear their interpreted values.
65
66
67 protected:
68 typedef class
77
78 ValueClass&
79 findOrMakeEntry( int firstIndex,
80 int secondIndex,
81 int const thirdIndex );
82 // this ensures that the entry at the sought indices exists, filling
83 // out with copies of defaultUnsetValue, & returns it.
84 virtual void
86 };
87
88
89
90
91
92 template< class ValueClass >
93 inline
95 IndexedInterpreter< ValueClass >(),
96 valueMatrixArray(),
97 firstRecordingIndex( 0 ),
98 secondRecordingIndex( 0 ),
99 thirdRecordingIndex( 0 ),
100 largestFirstIndex( 0 ),
101 largestSecondIndex( 0 ),
102 largestThirdIndex( 0 )
103 {
104 // just an initialization list.
105 }
106
107 template< class ValueClass >
108 inline
110 {
111 // does nothing.
112 }
113
114
115 template< class ValueClass >
116 inline ValueClass&
118 int const secondIndex,
119 int const thirdIndex )
120 /* this returns the ValueClass indexed by firstIndex, secondIndex, &
121 * thirdIndex. if there is no element at the sought indices,
122 * valueMatrixArray is extended with copies of defaultUnsetValue until
123 * there is an element at the sought indices.
124 */
125 {
126 return findOrMakeEntry( firstIndex,
127 secondIndex,
128 thirdIndex );
129 }
130
131 template< class ValueClass >
132 inline ValueClass const&
134 int secondIndex,
135 int thirdIndex ) const
136 /* const version of above, though it returns defaultUnsetValue rather
137 * than copying in a new element at the sought indices if there isn't
138 * an entry there already.
139 */
140 {
141 if( hasEntry( firstIndex,
142 secondIndex,
143 thirdIndex ) )
144 {
145 return valueMatrixArray[ firstIndex - 1 ][ secondIndex
146 - 1 ][ thirdIndex - 1 ];
147 }
148 else
149 {
150 return this->defaultUnsetValue;
151 }
152 }
153
154 template< class ValueClass >
155 inline bool
157 int secondIndex,
158 int const thirdIndex ) const
159 {
160 if( ( 0 < firstIndex )
161 &&
162 ( 0 < secondIndex )
163 &&
164 ( 0 < thirdIndex )
165 &&
166 ( (--firstIndex) < valueMatrixArray.getSize() )
167 &&
168 ( (--secondIndex) < valueMatrixArray[ firstIndex ].getSize() )
169 &&
170 ( (size_t)thirdIndex
171 <= valueMatrixArray[ firstIndex ][ secondIndex ].size() ) )
172 {
173 return true;
174 }
175 else
176 {
177 return false;
178 }
179 }
180
181 template< class ValueClass >
182 inline std::string const&
184 // see base version's description.
185 {
186 this->stringInterpretation.clear();
187 for( int firstIndex( 1 );
188 largestFirstIndex >= firstIndex;
189 ++firstIndex )
190 {
191 for( int secondIndex( 1 );
192 largestSecondIndex >= secondIndex;
193 ++secondIndex )
194 {
195 for( size_t thirdIndex( 1 );
196 largestThirdIndex >= thirdIndex;
197 ++thirdIndex )
198 {
199 this->indexPrintingVector[ 0 ] = firstIndex;
200 this->indexPrintingVector[ 1 ] = secondIndex;
201 this->indexPrintingVector[ 2 ] = thirdIndex;
202 this->stringInterpretation.append(
203 this->indicesToPrintingString() );
204 // SLHA indices are in the sane starts-at-one format, while C++
205 // code uses the silly starts-at-zero format.
206 this->stringInterpretation.append( this->valueToPrintingString(
207 findOrMakeEntry( firstIndex,
208 secondIndex,
209 thirdIndex ) ) );
210 this->stringInterpretation.append( "\n" );
211 }
212 }
213 }
214 return this->stringInterpretation;
215 }
216
217 template< class ValueClass >
218 inline void
220 // this ensures that the entry at soughtIndex exists, filling out with
221 // copies of defaultUnsetValue, & returns it.
222 {
223 valueMatrixArray.clearEntries();
224 }
225
226 template< class ValueClass >
227 inline void
229 {
230 for( int whichLine( this->currentStringBlock->getNumberOfBodyLines() );
231 0 < whichLine;
232 --whichLine )
233 {
234 this->currentWord.assign( BOL::StringParser::firstWordOf(
235 (*(this->currentStringBlock))[ whichLine ].first,
236 &(this->lineRemainderA),
238 if( !(this->currentWord.empty()) )
239 {
240 firstRecordingIndex
241 = BOL::StringParser::stringToInt( this->currentWord );
242 this->currentWord.assign( BOL::StringParser::firstWordOf(
243 this->lineRemainderA,
244 &(this->lineRemainderB),
246 secondRecordingIndex
247 = BOL::StringParser::stringToInt( this->currentWord );
248 this->currentWord.assign( BOL::StringParser::firstWordOf(
249 this->lineRemainderB,
250 &(this->lineRemainderA),
252 thirdRecordingIndex
253 = BOL::StringParser::stringToInt( this->currentWord );
254 this->currentWord.assign( BOL::StringParser::trimFromFrontAndBack(
255 this->lineRemainderA,
257
258 if( ( 0 < firstRecordingIndex )
259 &&
260 ( 0 < secondRecordingIndex )
261 &&
262 ( 0 < thirdRecordingIndex )
263 &&
264 !(this->currentWord.empty()) )
265 {
266 findOrMakeEntry( firstRecordingIndex,
267 secondRecordingIndex,
268 thirdRecordingIndex )
269 = this->stringToValue( this->currentWord );
270 }
271 else if( this->isVerbose )
272 {
273 std::cout
274 << std::endl
275 << "LHPC::SLHA::error! expected to find 3 positive indices then"
276 << " a value, instead found \""
277 << (*(this->currentStringBlock))[ whichLine ].first << "\"";
278 std::cout << std::endl;
279 }
280 }
281 }
282 }
283
284 template< class ValueClass >
285 inline ValueClass&
287 int secondIndex,
288 int const thirdIndex )
289 // this ensures that the entry at the sought indices exists, filling
290 // out with copies of defaultUnsetValue, & returns it.
291 {
292 if( firstIndex > largestFirstIndex )
293 {
294 largestFirstIndex = firstIndex;
295 }
296 if( secondIndex > largestSecondIndex )
297 {
298 largestSecondIndex = secondIndex;
299 }
300 if( (size_t)thirdIndex > largestThirdIndex )
301 {
302 largestThirdIndex = thirdIndex;
303 }
304 while( valueMatrixArray.getSize() < firstIndex )
305 {
306 valueMatrixArray.newEnd().clearEntries();
307 // empty ValueRankTwoMatrixes are added as necessary.
308 }
309 --firstIndex;
310 while( valueMatrixArray[ firstIndex ].getSize() < secondIndex )
311 {
312 valueMatrixArray[ firstIndex ].newEnd().clear();
313 // empty std::vectors are added as necessary.
314 }
315 if( valueMatrixArray[ firstIndex ][ (--secondIndex) ].size()
316 < (size_t)thirdIndex )
317 // the conditional does the job of converting from sane starts-at-one
318 // format to silly starts-at-zero format.
319 {
320 valueMatrixArray[ firstIndex ][ secondIndex ].resize( thirdIndex,
321 this->defaultUnsetValue );
322 }
323 return valueMatrixArray[ firstIndex ][ secondIndex ][ thirdIndex - 1 ];
324 }
325
326 }
327
328 }
329
330}
331
332#endif /* DENSETRIPLYINDEXED_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 std::string trimFromFrontAndBack(std::string const &stringToTrim, std::string const &charsToTrim=whitespaceAndNewlineChars)
static int stringToInt(std::string const &stringToInterpret)
ValueClass & findOrMakeEntry(int firstIndex, int secondIndex, int const thirdIndex)
class BOL::VectorlikeArray< std::vector< ValueClass > > ValueRankTwoMatrix
bool hasEntry(int const firstIndex, int const secondIndex, int const thirdIndex) const
ValueClass & operator()(int firstIndex, int secondIndex, int thirdIndex)
BOL::VectorlikeArray< ValueRankTwoMatrix > valueMatrixArray