a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models Logo
SparseSinglyIndexed.hpp
Go to the documentation of this file.
1/*
2 * SparseSinglyIndexed.hpp
3 *
4 * Created on: Feb 7, 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 SPARSESINGLYINDEXED_HPP_
15#define SPARSESINGLYINDEXED_HPP_
16
17#include <map>
19
20namespace LHPC
21{
22 namespace SLHA
23 {
24 namespace InterpreterClass
25 {
26 // this template class interprets SLHA blocks that have a single int
27 // index with a single ValueClass value.
28 template< class ValueClass >
29 class SparseSinglyIndexed : public IndexedInterpreter< ValueClass >
30 {
31 public:
33 virtual
35
36 ValueClass&
37 operator()( int const soughtIndex );
38 /* this returns the ValueClass mapped to by soughtIndex. if there is no
39 * element at soughtIndex, a new one is made & copied from
40 * defaultUnsetValue.
41 */
42 ValueClass const&
43 operator()( int const soughtIndex ) const;
44 /* const version of above, though it returns defaultUnsetValue rather
45 * than copying in a new element at soughtIndex if there isn't an entry
46 * there already.
47 */
48 ValueClass&
49 operator[]( int const soughtIndex )
50 { return (*this)( soughtIndex ); }
51 ValueClass const&
52 operator[]( int const soughtIndex ) const
53 { return (*this)( soughtIndex ); }
54 std::map< int, ValueClass >&
56 std::map< int, ValueClass > const&
57 getValueMap() const;
58 bool
59 hasEntry( int const soughtIndex ) const;
60 // this returns true if there is an entry at soughtIndex.
61 virtual std::string const&
63 // see base version's description.
64 virtual void
66 // derived classes should clear their interpreted values.
67
68
69 protected:
70 typedef typename
71 std::map< int, ValueClass >::const_iterator mapIterator;
72
73 std::map< int, ValueClass > valueMap;
74 std::pair< int, ValueClass > valueRecorder;
75
76 virtual void
78 };
79
80
81
82
83
84 template< class ValueClass >
85 inline
87 IndexedInterpreter< ValueClass >(),
88 valueMap(),
89 valueRecorder()
90 {
91 // just an initialization list.
92 }
93
94 template< class ValueClass >
95 inline
97 {
98 // does nothing.
99 }
100
101
102 template< class ValueClass >
103 inline ValueClass&
105 /* this returns the ValueClass mapped to by soughtIndex for the data
106 * with lowest energy scale. if there is no element at soughtIndex, a new
107 * one is made & copied from defaultUnsetValue.
108 */
109 {
110 if( 0 >= valueMap.count( soughtIndex ) )
111 {
112 valueMap[ soughtIndex ] = this->defaultUnsetValue;
113 }
114 return valueMap[ soughtIndex ];
115 }
116
117 template< class ValueClass >
118 inline ValueClass const&
120 int const soughtIndex ) const
121 /* const version of above, though it returns defaultUnsetValue rather
122 * than copying in a new element at soughtIndex if there isn't an entry
123 * there already.
124 */
125 {
126 mapIterator valueFinder( valueMap.find( soughtIndex ) );
127 if( valueMap.end() != valueFinder )
128 {
129 return valueFinder->second;
130 }
131 else
132 {
133 return this->defaultUnsetValue;
134 }
135 }
136
137 template< class ValueClass >
138 inline std::map< int, ValueClass >&
140 {
141 return valueMap;
142 }
143
144 template< class ValueClass >
145 inline std::map< int, ValueClass > const&
147 {
148 return valueMap;
149 }
150
151 template< class ValueClass >
152 inline bool
154 int const soughtIndex ) const
155 // this returns true if there is an entry at soughtIndex.
156 {
157 return ( 0 < valueMap.count( soughtIndex ) );
158 }
159
160 template< class ValueClass >
161 inline std::string const&
163 // see base version's description.
164 {
165 this->stringInterpretation.clear();
166 mapIterator valueFinder( valueMap.begin() );
167 while( valueFinder != valueMap.end() )
168 {
169 this->indexPrintingVector[ 0 ] = valueFinder->first;
170 this->stringInterpretation.append( this->indicesToPrintingString() );
171 this->stringInterpretation.append( this->valueToPrintingString(
172 valueFinder->second ) );
173 /* negative particle codes can be avoided in any block, I think.
174 * well, the exact format is only specified for the MASS block, &
175 * in that case, negative particle codes can be avoided, since the
176 * charge-conjugate just has the same mass. if the charge-conjugate
177 * pair has a mass splitting, I think they are defined with 2
178 * separate codes. if negative codes end up here, it's not my
179 * fault...
180 */
181 this->stringInterpretation.append( "\n" );
182 ++valueFinder;
183 }
184 return this->stringInterpretation;
185 }
186
187 template< class ValueClass >
188 inline void
190 {
191 valueMap.clear();
192 }
193
194 template< class ValueClass >
195 inline void
197 {
198 for( int whichLine( this->currentStringBlock->getNumberOfBodyLines() );
199 0 < whichLine;
200 --whichLine )
201 {
202 this->currentWord.assign( BOL::StringParser::firstWordOf(
203 (*(this->currentStringBlock))[ whichLine ].first,
204 &(this->lineRemainderA),
206 if( !(this->currentWord.empty()) )
207 {
208 valueRecorder.first
209 = BOL::StringParser::stringToInt( this->currentWord );
210 valueRecorder.second
211 = this->stringToValue( BOL::StringParser::trimFromFrontAndBack(
212 this->lineRemainderA,
214 valueMap.insert( valueRecorder );
215 }
216 }
217 }
218
219 }
220
221 }
222
223}
224
225#endif /* SPARSESINGLYINDEXED_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 & operator[](int const soughtIndex)
ValueClass const & operator[](int const soughtIndex) const
std::map< int, ValueClass >::const_iterator mapIterator