ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RooLinkedListIter.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * File: $Id: RooLinkedListIter.h,v 1.11 2007/05/11 09:11:30 verkerke Exp $
5  * Authors: *
6  * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7  * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8  * *
9  * Copyright (c) 2000-2005, Regents of the University of California *
10  * and Stanford University. All rights reserved. *
11  * *
12  * Redistribution and use in source and binary forms, *
13  * with or without modification, are permitted according to the terms *
14  * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15  *****************************************************************************/
16 #ifndef ROO_LINKED_LIST_ITER
17 #define ROO_LINKED_LIST_ITER
18 
19 #include "Rtypes.h"
20 #include "TIterator.h"
21 #include "RooLinkedList.h"
22 
23 #if ROOT_VERSION_CODE <= 332546
24 #ifndef nullptr
25 #define nullptr 0
26 #endif
27 #endif
28 
29 class RooFIter
30 {
31  public:
32  inline RooFIter() : _ptr (0) {}
33  inline RooFIter(const RooLinkedList* list) : _ptr (list->_first) {}
34 
35  inline RooAbsArg *next() {
36  // Return next element in collection
37  if (!_ptr) return 0 ;
38  TObject* arg = _ptr->_arg ;
39  _ptr = _ptr->_next;
40  return (RooAbsArg*) arg ;
41  }
42 
43  private:
44  const RooLinkedListElem* _ptr ; //! Next link element
45 };
46 
47 
48 
49 class RooLinkedListIter : public TIterator {
50 public:
51 
53  // coverity[UNINIT_CTOR]
54  } ;
55 
56 
57  RooLinkedListIter(const RooLinkedList* list, Bool_t forward) :
58  TIterator(), _list(list), _ptr(forward ? _list->_first : _list->_last),
59  _forward(forward)
60  { }
61 
63  TIterator(other), _list(other._list), _ptr(other._ptr),
64  _forward(other._forward)
65  {
66  // Copy constructor
67  }
68 
69  virtual ~RooLinkedListIter() { ; }
70 
71  TIterator& operator=(const TIterator& other) {
72 
73  // Iterator assignment operator
74 
75  if (&other==this) return *this ;
76  const RooLinkedListIter* iter = dynamic_cast<const RooLinkedListIter*>(&other) ;
77  if (iter) {
78  _list = iter->_list ;
79  _ptr = iter->_ptr ;
80  _forward = iter->_forward ;
81  }
82  return *this ;
83  }
84 
85  virtual const TCollection *GetCollection() const {
86  // Dummy
87  return 0 ;
88  }
89 
90  virtual TObject *Next() {
91  // Return next element in collection
92  if (!_ptr) return 0 ;
93  TObject* arg = _ptr->_arg ;
94  _ptr = _forward ? _ptr->_next : _ptr->_prev ;
95  return arg ;
96  }
97 
99  // Return next element in collection
100  if (!_ptr) return 0 ;
101  TObject* arg = _ptr->_arg ;
102  _ptr = _forward ? _ptr->_next : _ptr->_prev ;
103  return arg ;
104  }
105 
106 
107  virtual void Reset() {
108  // Return iterator to first element in collection
109  _ptr = _forward ? _list->_first : _list->_last ;
110  }
111 
112  bool operator!=(const TIterator &aIter) const {
113  const RooLinkedListIter *iter(dynamic_cast<const RooLinkedListIter*>(&aIter));
114  if (iter) return (_ptr != iter->_ptr);
115  return false; // for base class we don't implement a comparison
116  }
117 
118  bool operator!=(const RooLinkedListIter &aIter) const {
119  return (_ptr != aIter._ptr);
120  }
121 
122  virtual TObject *operator*() const {
123  // Return element iterator points to
124  return (_ptr ? _ptr->_arg : nullptr);
125  }
126 
127 protected:
128  const RooLinkedList* _list ; //! Collection iterated over
129  const RooLinkedListElem* _ptr ; //! Next link element
130  Bool_t _forward ; // Iterator direction
131 
132  ClassDef(RooLinkedListIter,2) // Iterator for RooLinkedList container class
133 } ;
134 
135 
136 
137 
138 #endif
const RooLinkedListElem * _ptr
RooLinkedListIter(const RooLinkedList *list, Bool_t forward)
bool operator!=(const TIterator &aIter) const
virtual ~RooLinkedListIter()
bool Bool_t
Definition: RtypesCore.h:59
RooFIter(const RooLinkedList *list)
const RooLinkedListElem * _ptr
Collection iterated over.
Iterator abstract base class.
Definition: TIterator.h:32
#define ClassDef(name, id)
Definition: Rtypes.h:254
RooLinkedListElem * _next
RooLinkedListElem * _first
virtual void Reset()
std::map< std::string, std::string >::const_iterator iter
Definition: TAlienJob.cxx:54
virtual TObject * Next()
TIterator & operator=(const TIterator &other)
RooLinkedListElem * _prev
virtual const TCollection * GetCollection() const
Collection abstract base class.
Definition: TCollection.h:48
RooLinkedListIter(const RooLinkedListIter &other)
virtual TObject * operator*() const
Return current object or nullptr.
RooAbsArg * next()
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
Definition: RooLinkedList.h:35
bool operator!=(const RooLinkedListIter &aIter) const
Mother of all ROOT objects.
Definition: TObject.h:58
RooLinkedListElem * _last
Link to first element of list.
const RooLinkedList * _list
RooLinkedListElem is an link element for the RooLinkedList class.
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
Bool_t _forward
Next link element.
RooLinkedListIter is the TIterator implementation for RooLinkedList.