00001 #ifndef DCHAIN_CHARGEDVISIBLELIST_H
00002 #define DCHAIN_CHARGEDVISIBLELIST_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 #include <memory>
00077 #include <iostream>
00078
00079
00080
00081
00082 #include "DecayChain/List/CandidateList.h"
00083 #include "DecayChain/List/ChosenChargeList.h"
00084 #include "DecayChain/Element/MutableReferenceHolder.h"
00085
00086
00087
00088 #include "DecayChain/Iterator/PartialItr.h"
00089 #include "DecayChain/Iterator/WholeItr.h"
00090
00091 #include "DecayChain/Element/MakerTrait.h"
00092 #include "DecayChain/Iterator/SelectiveInserter.h"
00093 #include "DecayChain/Function/SelectAll.h"
00094 #include "DecayChain/List/FillListWithSelection.h"
00095
00096
00097 #include "DecayChain/List/LabeledParticleList.h"
00098
00099
00100
00101
00102
00103
00104
00105
00106 namespace dchain {
00107 template < class T > class MuteWholeItr ;
00108
00109
00110 template<class T>
00111 int charge_sign(const T& iCharged) {
00112 return static_cast<int>(iCharged.charge());
00113 }
00114
00115 template<class T>
00116 int charge_sign(const T* iCharged) {
00117 return static_cast<int>(iCharged->charge());
00118 }
00119
00120 template<class T>
00121 int charge_sign(T* iCharged) {
00122 return static_cast<int>(iCharged->charge());
00123 }
00124
00125 template<class T>
00126 int charge_sign(const std::auto_ptr<T>& iCharged) {
00127 return static_cast<int>(iCharged->charge());
00128 }
00129
00130 template<class TPtr,class TRef>
00131 int charge_sign(const ReferenceHolderBase<TPtr,TRef>& iHolder) {
00132 return charge_sign(*iHolder);
00133 }
00134
00135
00136 template < class Charged , class CandidateClass = typename Charged::CandidateClass >
00137 class ChargedVisibleList : public CandidateList< CandidateClass >
00138 {
00139
00140
00141 public:
00142
00143 typedef MuteWholeItr< Charged > iterator ;
00144 typedef WholeItr< Charged > const_iterator ;
00145 typedef PartialItr< Charged > const_partial_iterator ;
00146
00147 typedef Charged value_type ;
00148
00149 typedef ChargedVisibleList<Charged,CandidateClass> self_type;
00150
00154
00155 ChargedVisibleList();
00156 ChargedVisibleList( const self_type& aOtherList);
00157 template<class TSelector>
00158 ChargedVisibleList( const self_type& aOtherList,
00159 const TSelector& aSel) :
00160 m_list( new LabeledParticleList<Charged,CandidateClass> ),
00161 m_plusList(0),
00162 m_minusList(0)
00163 {
00164 fill(*(aOtherList.m_list),
00165 typename MakerTrait<Charged>::maker_type(),
00166 aSel);
00167 }
00168
00169 template <class WitnessIterator>
00170 ChargedVisibleList(WitnessIterator first, WitnessIterator last) :
00171 m_list( new LabeledParticleList<Charged,CandidateClass> ),
00172 m_plusList(0),
00173 m_minusList(0)
00174 {
00175 fill(first, last, typename MakerTrait<Charged>::maker_type() ); }
00176
00177 template<class WitnessIterator, class TSelector>
00178 ChargedVisibleList(WitnessIterator first, WitnessIterator last,
00179 const TSelector& aFunctionalObject ) :
00180 m_list( new LabeledParticleList<Charged,CandidateClass> ),
00181 m_plusList(0),
00182 m_minusList(0)
00183 {
00184 fill(first, last,
00185 typename MakerTrait<Charged>::maker_type(), aFunctionalObject); }
00186
00187 virtual ~ChargedVisibleList() ;
00188
00189
00190 const self_type& operator=( const self_type& aOtherList ) ;
00191 template<class Witness>
00192 const self_type& operator=(const Witness& aWitnessList) {
00193 eraseContents();
00194 fill(aWitnessList.begin(), aWitnessList.end(),
00195 typename MakerTrait<Charged>::maker_type(),
00196 SelectAll<Charged>() );
00197 return ( *this ) ;
00198 }
00199
00200
00201 template<class TSelector>
00202 FillListWithSelection<self_type, TSelector> operator[](const TSelector& iSel) {
00203 return FillListWithSelection<self_type,TSelector>(*this, iSel);
00204 }
00205
00206 iterator particle_begin() ;
00207 iterator particle_end() ;
00208 ChosenChargeList< Charged , CandidateClass >& plus() const;
00209 ChosenChargeList< Charged , CandidateClass >& minus() const;
00210
00211
00212 const_iterator particle_begin() const ;
00213 const_iterator particle_end() const ;
00214
00215
00216 using CandidateList< CandidateClass >::iterate;
00217 template<class TAnalyze>
00218 void iterate( const TAnalyze& analyze) const {
00219 const_iterator finished ( particle_end() ) ;
00220 for ( const_iterator entry ( particle_begin() ) ;
00221 entry != finished ;
00222 ++entry ) {
00223 analyze( (*entry)() ) ;
00224 }
00225 }
00226
00227 template<class TAnalyze>
00228 void iterate( TAnalyze& analyze) const {
00229 const_iterator finished ( particle_end() ) ;
00230 for ( const_iterator entry ( particle_begin() ) ;
00231 entry != finished ;
00232 ++entry ) {
00233 analyze( (*entry)() ) ;
00234 }
00235 }
00236
00238 template<class TSelect>
00239 SelectiveInserter<self_type,TSelect> selectiveInserter(const TSelect& iSelect) {
00240 return SelectiveInserter<self_type,TSelect>(*this,iSelect); }
00241
00242 template <class THolder, class TSelect>
00243 bool attempt_insert( THolder& pPossible,
00244 const TSelect& aSelect) {
00245
00246 bool returnValue = (aSelect)(*pPossible);
00247 if (returnValue) {
00248 this->insert(pPossible);
00249 }
00250 return returnValue;
00251 }
00252
00253 template <class THolder>
00254 void insert(THolder& pPossible) {
00255 if (0 < charge_sign(pPossible)) {
00256 m_list->push_back( LabeledParticle< Charged >( pPossible ,
00257 kPlus ) ) ;
00258 }
00259 else {
00260 m_list->push_back( LabeledParticle< Charged >( pPossible ,
00261 kMinus ) ) ;
00262 }
00263 }
00264
00265 void eraseContents() ;
00266 void erase() {
00267 eraseContents();
00268 }
00269
00270 template<class TMaker, class TSelector>
00271 void fill( const LabeledParticleList< Charged , CandidateClass >& aList,
00272 const TMaker& aMaker,
00273 const TSelector& aSel) {
00274
00275 for( const_iterator entry(aList.begin()); entry != aList.end(); ++entry){
00276
00277
00278 const Charged& from((*entry)());
00279 typename ResultTypeTrait<TMaker>::type localCopy( aMaker(from) );
00280
00281 attempt_insert(localCopy,aSel);
00282 }
00283
00284 }
00285 template<class Iterator, class TMaker, class TSelector>
00286 void fill(Iterator first, Iterator last,
00287 const TMaker& aMaker,
00288 const TSelector& aSel = SelectAll<Charged>() ) {
00289
00290
00291 std::transform(first,last,
00292 selectiveInserter(aSel),
00293 aMaker);
00294
00295 }
00296
00297
00298 protected:
00299
00300 virtual LabeledParticleList< Charged , CandidateClass >& labeledCandidateList();
00301
00302
00303
00304 virtual const LabeledParticleList< Charged , CandidateClass >& labeledCandidateList() const ;
00305
00306 private:
00307
00308
00309
00310
00311
00312
00313
00314 MutableReferenceHolder<LabeledParticleList< Charged , CandidateClass > > m_list ;
00315
00316 mutable ChosenChargeList< Charged, CandidateClass >* m_plusList;
00317 mutable ChosenChargeList< Charged, CandidateClass >* m_minusList;
00318
00319
00320 static const conjugation::Label kPlus = conjugation::kHeads;
00321 static const conjugation::Label kMinus = conjugation::kTails;
00322
00323 } ;
00324
00325
00326
00327 template<class TIList, class TSelector, class T, class U>
00328 void fill_using_selector(const TIList& iList,
00329 const TSelector& iSel,
00330 ChargedVisibleList<T,U>& oList) {
00331 oList.fill(iList.begin(), iList.end(),
00332 typename MakerTrait<T>::maker_type(),
00333 iSel);
00334 }
00335 }
00336
00337
00338 #include "DecayChain/List/Template/ChargedVisibleList.cc"
00339
00340 #endif
00341