a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models Logo
MultipleSinglyIndexed.hpp
Go to the documentation of this file.
1/*
2 * MultipleSinglyIndexed.hpp
3 *
4 * Created on: Apr 1, 2012 (really!)
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 MULTIPLESINGLYINDEXED_HPP_
15#define MULTIPLESINGLYINDEXED_HPP_
16
17#include <map>
18#include <list>
20
21namespace LHPC
22{
23 namespace SLHA
24 {
25 namespace InterpreterClass
26 {
27 // this template class interprets SLHA blocks that have a single int
28 // index with a single ValueClass value.
29 template< class ValueClass >
30 class MultipleSinglyIndexed : public IndexedInterpreter< ValueClass >
31 {
32 public:
34 virtual
36
37 std::list< ValueClass* >
38 operator()( int const soughtIndex );
39 /* this returns a std::list of pointers to the ValueClass instances
40 * mapped to by soughtIndex. if there is no element at soughtIndex, an
41 * empty std::list is returned.
42 */
43 std::list< ValueClass const* >
44 operator()( int const soughtIndex ) const;
45 // const version of above.
46 std::list< ValueClass* >
47 operator[]( int const soughtIndex )
48 { return (*this)( soughtIndex ); }
49 std::list< ValueClass* > const
50 operator[]( int const soughtIndex ) const
51 { return (*this)( soughtIndex ); }
52 std::multimap< int, ValueClass >&
54 std::multimap< int, ValueClass > const&
55 getValueMap() const;
56 bool
57 hasEntry( int const soughtIndex ) const;
58 // this returns true if there is an entry at soughtIndex.
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 typename
69 std::multimap< int, ValueClass >::const_iterator mapIterator;
70
71 std::multimap< int, ValueClass > valueMap;
72 std::pair< int, ValueClass > valueRecorder;
73
74 virtual void
76 };
77
78
79
80
81
82 template< class ValueClass >
83 inline
85 IndexedInterpreter< ValueClass >(),
86 valueMap(),
87 valueRecorder()
88 {
89 // just an initialization list.
90 }
91
92 template< class ValueClass >
93 inline
95 {
96 // does nothing.
97 }
98
99 template< class ValueClass >
100 inline std::list< ValueClass* >
102 /* this returns a std::list of pointers to the ValueClass instances
103 * mapped to by soughtIndex. if there is no element at soughtIndex, an
104 * empty std::list is returned.
105 */
106 {
107 std::list< ValueClass* > returnList;
108 std::pair< mapIterator, mapIterator >
109 rangeIterators( valueMap.equal_range( soughtIndex ) );
110 while( rangeIterators.first != rangeIterators.second )
111 {
112 returnList.push_back( &(rangeIterators.first->second) );
113 ++(rangeIterators.first);
114 }
115 return returnList;
116 }
117
118 template< class ValueClass >
119 inline std::list< ValueClass const* >
121 int const soughtIndex ) const
122 // const version of above.
123 {
124 std::list< ValueClass const* > returnList;
125 std::pair< mapIterator, mapIterator >
126 rangeIterators( valueMap.equal_range( soughtIndex ) );
127 while( rangeIterators.first != rangeIterators.second )
128 {
129 returnList.push_back( &(rangeIterators.first->second) );
130 ++(rangeIterators.first);
131 }
132 return returnList;
133 }
134
135 template< class ValueClass >
136 inline std::multimap< int, ValueClass >&
138 {
139 return valueMap;
140 }
141
142 template< class ValueClass >
143 inline std::multimap< int, ValueClass > const&
145 {
146 return valueMap;
147 }
148
149 template< class ValueClass >
150 inline bool
152 int const soughtIndex ) const
153 // this returns true if there is an entry at soughtIndex.
154 {
155 return ( 0 < valueMap.count( soughtIndex ) );
156 }
157
158 template< class ValueClass >
159 inline std::string const&
161 // see base version's description.
162 {
163 this->stringInterpretation.clear();
164 mapIterator valueFinder( valueMap.begin() );
165 while( valueFinder != valueMap.end() )
166 {
167 this->indexPrintingVector[ 0 ] = valueFinder->first;
168 this->stringInterpretation.append( this->indicesToPrintingString() );
169 this->stringInterpretation.append( this->valueToPrintingString(
170 valueFinder->second ) );
171 /* negative particle codes can be avoided in any block, I think.
172 * well, the exact format is only specified for the MASS block, &
173 * in that case, negative particle codes can be avoided, since the
174 * charge-conjugate just has the same mass. if the charge-conjugate
175 * pair has a mass splitting, I think they are defined with 2
176 * separate codes. if negative codes end up here, it's not my
177 * fault...
178 */
179 this->stringInterpretation.append( "\n" );
180 ++valueFinder;
181 }
182 return this->stringInterpretation;
183 }
184
185 template< class ValueClass >
186 inline void
188 {
189 valueMap.clear();
190 }
191
192 template< class ValueClass >
193 inline void
195 {
196 for( int whichLine( this->currentStringBlock->getNumberOfBodyLines() );
197 0 < whichLine;
198 --whichLine )
199 {
200 this->currentWord.assign( BOL::StringParser::firstWordOf(
201 (*(this->currentStringBlock))[ whichLine ].first,
202 &(this->lineRemainderA),
204 if( !(this->currentWord.empty()) )
205 {
206 valueRecorder.first
207 = BOL::StringParser::stringToInt( this->currentWord );
208 valueRecorder.second
209 = this->stringToValue( BOL::StringParser::trimFromFrontAndBack(
210 this->lineRemainderA,
212 valueMap.insert( valueRecorder );
213 }
214 }
215 }
216
217 }
218
219 }
220
221}
222
223#endif /* MULTIPLESINGLYINDEXED_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)
std::multimap< int, ValueClass >::const_iterator mapIterator
std::list< ValueClass * > operator()(int const soughtIndex)
std::list< ValueClass * > const operator[](int const soughtIndex) const
std::list< ValueClass * > operator[](int const soughtIndex)