Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:29:06

0001 #include "FWCore/Reflection/interface/IterWithDict.h"
0002 #include <cassert>
0003 
0004 namespace edm {
0005 
0006   void IterWithDictBase::advance() {
0007     if (atEnd_) {
0008       return;
0009     }
0010     TObject* obj = iter_.Next();
0011     if (obj == nullptr) {
0012       atEnd_ = true;
0013     }
0014   }
0015 
0016   TIter const& IterWithDictBase::iter() const { return iter_; }
0017 
0018   IterWithDictBase::IterWithDictBase() : iter_(static_cast<TList*>(nullptr)), atEnd_(true) {
0019     // This ctor is used by the framework for the end of a range,
0020     // or for any type that does not have a TClass.
0021     // An iterator constructed by this ctor must not be used
0022     // as the left hand argument of operator!=().
0023   }
0024 
0025   IterWithDictBase::IterWithDictBase(TList* list) : iter_(list), atEnd_(false) {
0026     // With a TIter, you must call Next() once to point to the first element.
0027     TObject* obj = iter_.Next();
0028     if (obj == nullptr) {
0029       atEnd_ = true;
0030     }
0031   }
0032 
0033   bool IterWithDictBase::operator!=(IterWithDictBase const& rhs) const {
0034     // The special cases are needed because TIter::operator!=()
0035     // dereferences a null pointer (i.e. segfaults) if the left hand TIter
0036     // was constucted with a nullptr argument (the first constructor above).
0037     if (atEnd_ != rhs.atEnd_) {
0038       // one iterator at end, but not both
0039       return true;
0040     }
0041     if (atEnd_) {
0042       // both iterators at end
0043       return false;
0044     }
0045     // neither iterator at end
0046     return iter_ != rhs.iter_;
0047   }
0048 
0049 }  // namespace edm