00001 #ifndef DCHAIN_NEUTRALVISIBLELIST_H
00002 #define DCHAIN_NEUTRALVISIBLELIST_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
00077
00078 #include "DecayChain/List/ConjugateList.h"
00079 #include "DecayChain/Element/MutableReferenceHolder.h"
00080
00081 #include "DecayChain/List/LabeledParticleList.h"
00082 #include "DecayChain/Element/MakerTrait.h"
00083 #include "DecayChain/Iterator/SelectiveInserter.h"
00084 #include "DecayChain/Function/SelectAll.h"
00085 #include "DecayChain/List/FillListWithSelection.h"
00086
00087 namespace dchain {
00088 template < class DecayClass > class MuteWholeItr ;
00089 template < class DecayClass > class WholeItr ;
00090 template < class DecayClass > class PartialItr ;
00091
00092
00093
00094
00095
00096
00097
00098
00099 template< class Neutral , class CandidateClass = typename Neutral::CandidateClass >
00100 class NeutralVisibleList : public dchain::ConjugateList< CandidateClass >
00101 {
00102
00103
00104 public:
00105
00106 typedef dchain::MuteWholeItr< Neutral > iterator ;
00107 typedef dchain::WholeItr< Neutral > const_iterator ;
00108
00109
00110 typedef Neutral value_type ;
00111
00112 typedef NeutralVisibleList<Neutral,CandidateClass> self_type;
00113
00114 NeutralVisibleList() ;
00115 NeutralVisibleList( const self_type& aOtherList);
00116 template<class TSelector>
00117 NeutralVisibleList( const self_type& aOtherList ,
00118 const TSelector& aSel) :
00119 ConjugateList< CandidateClass >( dchain::conjugation::kNone ),
00120 m_list(new LabeledParticleList<Neutral,CandidateClass>) {
00121 fill(*(aOtherList.m_list),
00122 typename MakerTrait<Neutral>::maker_type(),
00123 aSel);
00124 }
00125
00126 template <class WitnessIterator>
00127 NeutralVisibleList(WitnessIterator first, WitnessIterator last) :
00128 ConjugateList< CandidateClass >( dchain::conjugation::kNone ),
00129 m_list( new LabeledParticleList<Neutral,CandidateClass> ) {
00130 fill(first, last, typename MakerTrait<Neutral>::maker_type() ); }
00131
00132 template<class WitnessIterator, class TSelector>
00133 NeutralVisibleList(WitnessIterator first, WitnessIterator last,
00134 const TSelector& aFunctionalObject )
00135 :
00136 ConjugateList< CandidateClass >( dchain::conjugation::kNone ),
00137 m_list( new LabeledParticleList<Neutral,CandidateClass> )
00138 {
00139 fill(first, last,
00140 typename MakerTrait<Neutral>::maker_type(), aFunctionalObject); }
00141 virtual ~NeutralVisibleList() ;
00142
00143
00144 const self_type& operator=(const self_type& aOtherList );
00145
00146 template<class Witness>
00147 const self_type& operator=(const Witness& aWitnessList) {
00148 eraseContents();
00149 fill(aWitnessList.begin(), aWitnessList.end(),
00150 typename MakerTrait<Neutral>::maker_type(),
00151 SelectAll<Neutral>() );
00152 return ( *this ) ;
00153 }
00154
00155
00156 template<class TSelector>
00157 FillListWithSelection<self_type, TSelector> operator[](const TSelector& iSel) {
00158 return FillListWithSelection<self_type,TSelector>(*this, iSel);
00159 }
00160
00161 iterator particle_begin() ;
00162 iterator particle_end() ;
00163
00164
00165 const_iterator particle_begin() const ;
00166 const_iterator particle_end() const ;
00167
00168 using CandidateList< CandidateClass >::iterate;
00169 template<class TAnalyze>
00170 void iterate( const TAnalyze& analyze) const {
00171 const_iterator finished ( particle_end() ) ;
00172 for ( const_iterator entry ( particle_begin() ) ;
00173 entry != finished ;
00174 ++entry ) {
00175 analyze( (*entry)() ) ;
00176 }
00177 }
00178
00179 template<class TAnalyze>
00180 void iterate( TAnalyze& analyze) const {
00181 const_iterator finished ( particle_end() ) ;
00182 for ( const_iterator entry ( particle_begin() ) ;
00183 entry != finished ;
00184 ++entry ) {
00185 analyze( (*entry)() ) ;
00186 }
00187 }
00188
00190 template<class TSelect>
00191 SelectiveInserter<self_type,TSelect> selectiveInserter(const TSelect& iSelect) {
00192 return SelectiveInserter<self_type,TSelect>(*this,iSelect); }
00193
00194 template <class THolder, class TSelect>
00195 bool attempt_insert( THolder& pPossible,
00196 const TSelect& aSelect) {
00197 bool returnValue = (aSelect)(*pPossible);
00198 if (returnValue) {
00199 this->insert(pPossible);
00200 }
00201 return returnValue;
00202 }
00203 template <class THolder>
00204 void insert(THolder& pPossible) {
00205 m_list->push_back( LabeledParticle< Neutral >( pPossible ,
00206 conjugation::kNone ) ) ;
00207 }
00208 void eraseContents() ;
00209
00210 void erase() {
00211 eraseContents();
00212 }
00213
00214
00215 template<class TMaker, class TSelector>
00216 void fill( const LabeledParticleList< Neutral , CandidateClass >& aList,
00217 const TMaker& aMaker,
00218 const TSelector& aSel) {
00219
00220 for( const_iterator entry(aList.begin()); entry != aList.end(); ++entry){
00221
00222
00223 const Neutral& from((*entry)());
00224 typename ResultTypeTrait<TMaker>::type localCopy( aMaker(from) );
00225
00226 attempt_insert(localCopy,aSel);
00227 }
00228
00229 }
00230 template<class Iterator, class TMaker, class TSelector>
00231 void fill(Iterator first, Iterator last,
00232 const TMaker& aMaker,
00233 const TSelector& aSel = SelectAll<Neutral>() ) {
00234 std::transform(first,last,
00235 selectiveInserter(aSel),
00236 aMaker);
00237 }
00238 protected:
00239
00240 virtual dchain::LabeledParticleList< Neutral, CandidateClass >& labeledCandidateList() ;
00241
00242
00243 virtual const dchain::LabeledParticleList< Neutral, CandidateClass >& labeledCandidateList() const ;
00244
00245 private:
00246
00247
00248
00249
00250
00251
00252
00253 MutableReferenceHolder< dchain::LabeledParticleList< Neutral , CandidateClass > > m_list ;
00254
00255
00256
00257 } ;
00258
00259
00260 template<class TIList, class TSelector, class T, class U>
00261 void fill_using_selector(const TIList& iList,
00262 const TSelector& iSel,
00263 NeutralVisibleList<T,U>& oList) {
00264 oList.fill(iList.begin(), iList.end(),
00265 typename MakerTrait<T>::maker_type(),
00266 iSel);
00267 }
00268
00269 }
00270
00271
00272 #include "DecayChain/List/Template/NeutralVisibleList.cc"
00273
00274 #endif