00001
00002
00003
00214 #ifndef ATHCONTAINERS_DATALIST_H
00215 #define ATHCONTAINERS_DATALIST_H
00216
00217
00218 #ifdef XAOD_STANDALONE
00219 #error "DataList is not supported outside of Athena!"
00220 #endif // XAOD_STANDALONE
00221
00222
00223
00224 #define HAVE_CONSTDATAVECTOR
00225
00226
00227
00228 #include <list>
00229 #include <typeinfo>
00230 #include <functional>
00231 #include <iostream>
00232 #include <algorithm>
00233 #include <iterator>
00234
00235
00236 #include <boost/static_assert.hpp>
00237 #include <boost/type_traits.hpp>
00238 #include <boost/iterator/iterator_adaptor.hpp>
00239
00240
00241 #include "SGTools/BaseInfo.h"
00242 #include "SGTools/DataBucketTraitFwd.h"
00243 #include "SGTools/ClassName.h"
00244
00245 #include "AthContainers/OwnershipPolicy.h"
00246 #include "AthContainers/exceptions.h"
00247 #include "AthContainers/tools/DVLNoBase.h"
00248 #include "AthContainers/tools/DVLInfo.h"
00249 #include "AthContainers/tools/DVLDataBucket.h"
00250 #include "AthContainers/tools/DVLCast.h"
00251 #include "AthContainers/tools/DVLIterator.h"
00252 #include "AthContainers/tools/DVL_iter_swap.h"
00253 #include "AthContainers/tools/DVL_algorithms.h"
00254 #include "AthContainers/tools/ElementProxy.h"
00255 #include "AthContainers/tools/IsMostDerivedFlag.h"
00256 #include "AthLinks/tools/selection_ns.h"
00257
00258
00259 ENTER_ROOT_SELECTION_NS
00260 template <class T, class BASE> class DataList;
00261 EXIT_ROOT_SELECTION_NS
00262
00263
00264 namespace DataList_detail {
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283 template <class B1,
00284 class B2=DataModel_detail::NoBase,
00285 class B3=DataModel_detail::NoBase> struct VirtBases;
00286
00287 }
00288
00297 template <class T>
00298 struct DataListBase
00299 {
00300 typedef DataModel_detail::NoBase Base;
00301 };
00302
00312 #define DATALIST_BASE(T, BASE) \
00313 template <> struct DataListBase<T> \
00314 { typedef DataList<BASE> Base; }; \
00315 SG_BASE(DataList<T>, DataList<BASE>); \
00316 template struct DataList_detail::DVLEltBaseInit<T>
00317
00318
00328 #define DATALIST_VIRTBASES1(T, B1) \
00329 template <> struct DataListBase<T> \
00330 { typedef DataList_detail::VirtBases<B1> Base; }; \
00331 SG_BASES1(DataList<T>, SG_VIRTUAL(DataList<B1>)); \
00332 template struct DataList_detail::DVLEltBaseInit<T>
00333
00334
00335
00345 #define DATALIST_VIRTBASES2(T, B1, B2) \
00346 template <> struct DataListBase<T> \
00347 { typedef DataList_detail::VirtBases<B1, B2> Base; }; \
00348 SG_BASES2(DataList<T>, SG_VIRTUAL(DataList<B1>), \
00349 SG_VIRTUAL(DataList<B2>)); \
00350 template struct DataList_detail::DVLEltBaseInit<T>
00351
00352
00362 #define DATALIST_VIRTBASES3(T, B1, B2, B3) \
00363 template <> struct DataListBase<T> \
00364 { typedef DataList_detail::VirtBases<B1, B2, B3> Base; }; \
00365 SG_BASES3(DataList<T>, SG_VIRTUAL(DataList<B1>), \
00366 SG_VIRTUAL(DataList<B2>), \
00367 SG_VIRTUAL(DataList<B3>)); \
00368 template struct DataList_detail::DVLEltBaseInit<T>
00369
00370
00371 template <class DL> class ConstDataList;
00372 template <class DL> void test2_assignelement1();
00373
00374
00384 template <class T, class BASE = typename DataListBase<T>::Base>
00385 class DataList : public BASE
00386 {
00387 public:
00388 typedef BASE DataList_BASE;
00389 typedef BASE DVL_BASE;
00390
00393 static const bool has_virtual = BASE::has_virtual;
00394
00397 typedef typename BASE::PtrList PtrList;
00398 typedef typename BASE::PtrList BaseContainer;
00399
00400
00401 public:
00402
00403 typedef T*& reference;
00404 typedef T* const & const_reference;
00405 typedef typename BASE::size_type size_type;
00406 typedef typename BASE::difference_type difference_type;
00407 typedef T* value_type;
00408 typedef typename BASE::allocator_type allocator_type;
00409 typedef T** pointer;
00410 typedef T* const * const_pointer;
00411
00412 typedef const T* const_value_type;
00413
00416 typedef T base_value_type;
00417
00420 typedef DataModel_detail::ElementProxy<DataList> ElementProxy;
00421
00422
00424 typedef typename DataModel_detail::const_iterator<DataList>
00425 const_iterator;
00426
00429 typedef typename DataModel_detail::iterator<DataList> iterator;
00430
00431
00433 typedef typename std::reverse_iterator<const_iterator>
00434 const_reverse_iterator;
00435
00438 typedef typename std::reverse_iterator<iterator>
00439 reverse_iterator;
00440
00441
00442
00445
00446
00454 explicit DataList( SG::OwnershipPolicy ownPolicy = SG::OWN_ELEMENTS );
00455
00456
00468 explicit DataList( size_type n,
00469 SG::OwnershipPolicy ownPolicy = SG::OWN_ELEMENTS );
00470
00471
00478
00479
00480
00481
00482
00483
00484
00485
00486
00497 template <class InputIterator>
00498 DataList( InputIterator first, InputIterator last,
00499 SG::OwnershipPolicy ownPolicy = SG::VIEW_ELEMENTS );
00500
00501
00514 DataList& operator=( const DataList& rhs );
00515
00516
00526 template <class InputIterator>
00527 void assign( InputIterator first, InputIterator last );
00528
00529
00530
00531
00532
00534
00537
00538
00543
00544
00545
00550
00551
00552
00564
00565
00566
00571
00572
00573
00575
00578
00586 const T* front() const;
00587
00588
00596 const T* back() const;
00597
00598
00607 ElementProxy front ();
00608
00609
00618 ElementProxy back ();
00619
00620
00622
00625
00626
00635 const_iterator begin() const;
00636
00637
00646 const_iterator end() const;
00647
00648
00658 iterator begin();
00659
00660
00670 iterator end();
00671
00672
00681 const_reverse_iterator rbegin() const;
00682
00683
00692 const_reverse_iterator rend() const;
00693
00694
00704 reverse_iterator rbegin();
00705
00706
00716 reverse_iterator rend();
00717
00718
00720
00723
00724
00735 void push_front( value_type pElem );
00736
00737
00748 void push_back( value_type pElem );
00749
00750
00763 iterator insert( iterator position, value_type pElem );
00764
00765
00778 template <class InputIterator>
00779 void insert( iterator position, InputIterator first, InputIterator last );
00780
00781
00783
00786
00787
00796 iterator erase(iterator position);
00797
00798
00810 iterator erase(iterator first, iterator last);
00811
00812
00820
00821
00822
00830
00831
00832
00841
00842
00843
00845
00848
00849
00860 void swap( DataList& rhs );
00861
00862
00868 static void iter_swap (iterator a, iterator b);
00869
00870
00876 void sort();
00877
00878
00883 template <class COMPARE>
00884 void sort(COMPARE comp);
00885
00886
00888
00891
00892
00902 void splice( iterator position, DataList& l );
00903
00913 void splice( iterator position, DataList& l, iterator i );
00914
00915
00928 void splice( iterator position, DataList& l,
00929 iterator first,
00930 iterator last );
00931
00932
00940 void remove( const value_type& value );
00941
00942
00950 template<typename PREDICATE>
00951 void remove_if( PREDICATE p );
00952
00953
00961 void unique();
00962
00963
00973 template<typename BINARY_PREDICATE>
00974 void unique( BINARY_PREDICATE p );
00975
00976
00986 void merge( DataList& l );
00987
00988
01001 template<typename COMPARE>
01002 void merge( DataList& l, COMPARE predicate );
01003
01004
01010 void reverse();
01011
01012
01014
01017
01018
01019 public:
01037 void swapElement(iterator pos, value_type newElem, reference oldElem);
01038
01039
01048
01049
01050
01055
01056
01057
01068
01069
01070
01076 static const DataModel_detail::DVLInfoBase& dvlinfo();
01077
01078
01084 virtual const DataModel_detail::DVLInfoBase& dvlinfo_v() const;
01085
01086
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098 #ifndef __cplusplus
01099 size_type size() const;
01100 size_type max_size() const;
01101 void resize(size_type sz);
01102 bool empty() const;
01103 void pop_back();
01104 void pop_front();
01105 void clear();
01106 const PtrList& stdcont() const;
01107 SG::OwnershipPolicy ownPolicy() const;
01108 void clear (SG::OwnershipPolicy ownPolicy);
01109 #endif // not __cplusplus
01110
01111
01114
01115
01116 public:
01124 void resortAux (iterator beg, iterator end);
01125
01126
01137 void testInsert (const char* op);
01138
01139
01150 void testInsertOol (const char* op);
01151
01152
01153 protected:
01159 void clearMostDerived();
01160
01161
01169 virtual void setMostDerived();
01170
01171
01172 private:
01173 friend class DataModel_detail::ElementProxy<DataList>;
01174 friend class ConstDataList<DataList>;
01175 friend void test2_assignelement1<DataList>();
01176
01177
01189 virtual const std::type_info& dl_typeid() const;
01190
01191
01199 void assignElement (typename BaseContainer::iterator pos, value_type newElem);
01200
01201
01209 void assignBaseElement (typename BaseContainer::iterator pos,
01210 typename BaseContainer::value_type newElem);
01211
01212
01221 static
01222 const T* do_cast (const typename PtrList::value_type p);
01224
01225
01229 SG::IsMostDerivedFlag m_isMostDerived;
01230
01231
01233 static DataModel_detail::DVLInfo<DataList<T> > s_info;
01234
01235
01236 typedef typename
01237 ROOT_SELECTION_NS::DataList<T, DataList_BASE>::self self;
01238 };
01239
01240
01241 template <class T, class BASE>
01242 const bool DataList<T, BASE>::has_virtual;
01243
01244
01254 template <class T>
01255 class DataList<T, DataModel_detail::NoBase>
01256 {
01257 public:
01258 typedef DataModel_detail::NoBase DataList_BASE;
01259 typedef DataModel_detail::NoBase DVL_BASE;
01260
01262 typedef boost::true_type isSequence;
01263
01266 typedef std::list<T*> PtrList;
01267 typedef std::list<T*> BaseContainer;
01268
01273 static const bool has_virtual = false;
01274
01275
01276 typedef T*& reference;
01277 typedef T* const & const_reference;
01278 typedef typename PtrList::size_type size_type;
01279 typedef typename PtrList::difference_type difference_type;
01280 typedef T* value_type;
01281 typedef typename PtrList::allocator_type allocator_type;
01282 typedef T** pointer;
01283 typedef T* const * const_pointer;
01284
01285 typedef const T* const_value_type;
01286
01289 typedef T base_value_type;
01290
01293 typedef DataModel_detail::ElementProxy<DataList> ElementProxy;
01294
01295
01298 typedef typename PtrList::const_iterator const_iterator;
01299
01302 typedef typename DataModel_detail::iterator<DataList> iterator;
01303
01308 typedef typename std::reverse_iterator<const_iterator>
01309 const_reverse_iterator;
01310
01313 typedef typename std::reverse_iterator<iterator>
01314 reverse_iterator;
01315
01316
01317
01320
01321
01329 explicit DataList( SG::OwnershipPolicy ownPolicy = SG::OWN_ELEMENTS );
01330
01331
01343 explicit DataList( size_type n,
01344 SG::OwnershipPolicy ownPolicy = SG::OWN_ELEMENTS );
01345
01346
01353 DataList( const DataList& rhs );
01354
01355
01366 template <class InputIterator>
01367 DataList( InputIterator first, InputIterator last,
01368 SG::OwnershipPolicy ownPolicy = SG::VIEW_ELEMENTS );
01369
01370
01383 DataList& operator=( const DataList& rhs );
01384
01385
01395 template <class InputIterator>
01396 void assign( InputIterator first, InputIterator last );
01397
01398
01408 virtual ~DataList();
01409
01410
01412
01415
01416
01420 size_type size() const;
01421
01422
01426 size_type max_size() const;
01427
01428
01439 void resize( size_type sz );
01440
01441
01445 bool empty() const;
01446
01447
01449
01452
01453
01461 const T* front() const;
01462
01463
01471 const T* back() const;
01472
01473
01482 ElementProxy front();
01483
01484
01493 ElementProxy back();
01494
01495
01497
01500
01501
01510 const_iterator begin() const;
01511
01512
01521 const_iterator end() const;
01522
01523
01533 iterator begin();
01534
01535
01545 iterator end();
01546
01547
01556 const_reverse_iterator rbegin() const;
01557
01558
01567 const_reverse_iterator rend() const;
01568
01569
01579 reverse_iterator rbegin();
01580
01581
01591 reverse_iterator rend();
01592
01594
01597
01598
01609 void push_front( value_type pElem );
01610
01611
01622 void push_back( value_type pElem );
01623
01624
01637 iterator insert( iterator position, value_type pElem );
01638
01639
01652 template <class InputIterator>
01653 void insert( iterator position, InputIterator first, InputIterator last );
01654
01655
01657
01660
01661
01670 iterator erase( iterator position );
01671
01672
01684 iterator erase( iterator first, iterator last );
01685
01686
01693 void pop_front();
01694
01695
01702 void pop_back();
01703
01704
01712 void clear();
01713
01714
01716
01719
01720
01731 void swap( DataList& rhs );
01732
01733
01739 static void iter_swap (iterator a, iterator b);
01740
01741
01747 void sort();
01748
01749
01755 template <class COMPARE>
01756 void sort( COMPARE comp );
01757
01758
01760
01763
01764
01774 void splice( iterator position, DataList& l );
01775
01785 void splice( iterator position, DataList& l, iterator i );
01786
01787
01800 void splice( iterator position, DataList& l,
01801 iterator first,
01802 iterator last );
01803
01804
01816 void remove( const value_type& value );
01817
01818
01830 template<typename PREDICATE>
01831 void remove_if( PREDICATE p );
01832
01840 void unique();
01841
01851 template<typename BinaryPredicate>
01852 void unique( BinaryPredicate pred );
01853
01863 void merge( DataList& l );
01864
01877 template<typename COMPARE>
01878 void merge( DataList& l, COMPARE predicate );
01879
01885 void reverse();
01886
01887
01888
01890
01893
01894
01895 public:
01913 void swapElement(iterator pos, value_type newElem, reference oldElem);
01914
01915
01923 const PtrList& stdcont() const;
01924
01925
01929 SG::OwnershipPolicy ownPolicy() const;
01930
01931
01941 void clear (SG::OwnershipPolicy ownPolicy);
01942
01943
01949 static const DataModel_detail::DVLInfoBase& dvlinfo();
01950
01951
01957 virtual const DataModel_detail::DVLInfoBase& dvlinfo_v() const;
01958
01959
01961
01964
01965
01966 public:
01974 void resortAux (iterator beg, iterator end);
01975
01976
01987 void testInsert (const char* op);
01988
01989
02000 void testInsertOol (const char* op);
02001
02002
02003 private:
02004 friend class DataModel_detail::ElementProxy<DataList>;
02005 friend class ConstDataList<DataList>;
02006 friend void test2_assignelement1<DataList>();
02007
02008
02017 void assignElement (typename BaseContainer::iterator pos, value_type newElem);
02018
02019
02028 void assignBaseElement (typename BaseContainer::iterator pos,
02029 typename BaseContainer::value_type newElem);
02030
02031
02032 protected:
02042 typename PtrList::iterator erase_base( typename PtrList::iterator position );
02043
02044
02056 typename PtrList::iterator
02057 erase_base( typename PtrList::iterator first,
02058 typename PtrList::iterator last );
02059
02060
02061 protected:
02064 SG::OwnershipPolicy m_ownPolicy;
02065
02067 PtrList m_pCont;
02068
02069
02075 void clearMostDerived();
02076
02077
02085 virtual void setMostDerived();
02086
02087
02088 private:
02100 virtual const std::type_info& dl_typeid() const;
02102
02103
02107 SG::IsMostDerivedFlag m_isMostDerived;
02108
02109
02111 static DataModel_detail::DVLInfo<DataList<T> > s_info;
02112
02113
02114 typedef typename
02115 ROOT_SELECTION_NS::DataList<T, DataList_BASE>::self self;
02116 };
02117
02118 template <class T>
02119 const bool DataList<T, DataModel_detail::NoBase>::has_virtual;
02120
02121
02132 template <class T>
02133 bool operator==( const DataList<T>& a, const DataList<T>& b );
02134
02135
02137 template <class T>
02138 bool operator!=( const DataList<T>& a, const DataList<T>& b );
02139
02140
02152 template <class T>
02153 bool operator< ( const DataList<T>& a, const DataList<T>& b );
02154
02155
02157 template <class T>
02158 bool operator> ( const DataList<T>& a, const DataList<T>& b );
02159
02160
02162 template <class T>
02163 bool operator<=( const DataList<T>& a, const DataList<T>& b );
02164
02165
02167 template <class T>
02168 bool operator>=( const DataList<T>& a, const DataList<T>& b );
02169
02170
02172 template <class T>
02173 void swap( DataList<T>& a, DataList<T>& b );
02174
02175
02182 template <class T>
02183 class ClassName<DataList<T> >
02184 {
02185 public:
02186 static std::string name();
02187 };
02188
02189
02190 ENTER_ROOT_SELECTION_NS
02191
02192 #if ROOT_VERSION_CODE < ROOT_VERSION( 5, 99, 0 )
02193
02194 template <class T, class BASE>
02195 class DataList
02196 {
02197 public:
02198 typedef DataList<T, BASE> self;
02199
02200 ROOT_SELECTION_NS::TEMPLATE_DEFAULTS<
02201 ROOT_SELECTION_NS::NODEFAULT,
02202 typename ::DataList<T>::DataList_BASE> dum1;
02203 ROOT_SELECTION_NS::NO_SELF_AUTOSELECT dum2;
02204 ROOT_SELECTION_NS::TRANSIENT m_isMostDerived;
02205 };
02206
02207 #else
02208
02209 template< class T, class BASE >
02210 class DataList : KeepFirstTemplateArguments< 1 >, SelectNoInstance {
02211
02212 public:
02214 typedef DataList< T, BASE > self;
02215
02217 ROOT_SELECTION_NS::MemberAttributes< kTransient > m_isMostDerived;
02218
02219 };
02220
02221 #endif // ROOT_VERSION
02222
02223 EXIT_ROOT_SELECTION_NS
02224
02225
02226 namespace SG {
02227
02228
02235 template <class T, class U>
02236 struct DataBucketTrait<DataList<T>, U>
02237 {
02238 typedef SG::DVLDataBucket<U> type;
02239 static void init() { DataList<T>::dvlinfo(); }
02240 };
02241
02242
02243 }
02244 #include "AthContainers/DataList.icc"
02245
02246
02247 #if 0
02248
02249
02250
02251
02252
02253
02254 #include "boost/mpl/if.hpp"
02255 #include "boost/mpl/and.hpp"
02256 #include "boost/mpl/equal_to.hpp"
02257 #define if_ boost::mpl::if_
02258 #define and_ boost::mpl::and_
02259 #define equal_to boost::mpl::equal_to
02260 #define true_ boost::mpl::true_
02261 #define false_ boost::mpl::false_
02262 template <class U> struct not_virtual { typedef true_ type; };
02263 template <class U> struct not_virtual<SG::Virtual<U> > { typedef false_ type; };
02264 template <class U> struct clean_type { typedef U type; };
02265 template <> struct clean_type<SG::NoBase>
02266 { typedef DataModel_detail::NoBase type; };
02267 template <class U> struct clean_type<SG::Virtual<U> >
02268 { typedef typename clean_type<U>::type type; };
02269 template <class T>
02270 struct bases_from_sg
02271 {
02272 typedef typename
02273 if_<equal_to<typename SG::Bases<T>::Base1, SG::NoBase>,
02274 DataModel_detail::NoBase,
02275 if_<and_<equal_to<typename SG::Bases<T>::Base1, SG::NoBase>,
02276 not_virtual<typename SG::Bases<T>::Base2> >,
02277 typename SG::Bases<T>::Base1,
02278 DataList_detail::VirtBases
02279 <clean_type<typename SG::Bases<T>::Base1>,
02280 clean_type<typename SG::Bases<T>::Base2>,
02281 clean_type<typename SG::Bases<T>::Base3> >
02282 > >::type type;
02283 };
02284 #undef if_
02285 #undef and_
02286 #undef equal_to
02287 #undef true_
02288 #undef false_
02289
02290 #define DATALIST_BASES_FROM_SG(T) \
02291 template <> struct DataListBase<T> \
02292 { typedef bases_from_sg<T>::type Base; };
02293
02294 #endif
02295
02296
02297
02298 #endif // ATHCONTAINERS_DATALIST_H