ISequence.h
Go to the documentation of this file.
1 #ifndef WIRECELL_ISEQUENCE
2 #define WIRECELL_ISEQUENCE
3 
5 
6 #include <memory>
7 
8 namespace WireCell {
9 
10  /** Abstract base class interface for sequence of data providing
11  * facade iterators over abstract base iterators.
12  *
13  * If a subclass multiply-inherits then one has to do
14  * myobj->ISequence<IThisData>::begin() etc or cast to the desired
15  * interface.
16  */
17  template<class IDataClass>
18  class ISequence { // note: not a WireCell::Interface
19  public:
21 
22  /// Access this sequence via shared (non-const) pointer.
23  typedef std::shared_ptr<this_type> pointer;
24 
25  typedef typename IDataClass::iterator iterator;
27  typedef typename IDataClass::base_iterator base_iterator;
28  typedef typename IDataClass::iterator_range iterator_range;
29 
30  /// Adapt one iterator to the standard facade iterator.
31  template<typename OtherIter>
32  static iterator adapt(const OtherIter& itr) {
34  }
35  template<typename OtherIter>
36  static const_iterator cadapt(const OtherIter& itr) {
38  }
39 
40  /// Concrete class must implement:
41  virtual const_iterator cbegin() const = 0;
42  virtual const_iterator cend() const = 0;
43  virtual const_iterator begin() const { return cbegin(); }
44  virtual const_iterator end() const { return cbegin(); }
45  virtual iterator begin() { return iterator(cbegin()); }
46  virtual iterator end() { return iterator(cbegin()); }
47 
48 
49  /// Return begin/end pair as iterator range.
50  virtual iterator_range range() {
51  return iterator_range(begin(), end());
52  }
53 
54  virtual ~ISequence() ;
55  };
56 
57  /** An ISequence made by adapting begin/end iterators of some
58  * other type.
59  */
60  template<class IDataClass>
61  class SequenceAdapter : public ISequence<IDataClass> {
62  public:
63 
65 
66  template<typename OtherIter>
67  SequenceAdapter(const OtherIter& begin, const OtherIter& end)
68  : m_begin(ISequence<IDataClass>::adapt(begin))
69  , m_end((ISequence<IDataClass>::adapt(end)))
70  {}
71 
72  virtual iterator begin() { return m_begin; }
73  virtual iterator end() { return m_end; }
74 
75  virtual ~SequenceAdapter();
76  private:
77  iterator m_begin, m_end;
78 
79  };
80 
81 }
82 
83 
84 
85 #endif
86 
intermediate_table::iterator iterator
virtual const_iterator cend() const =0
virtual const_iterator cbegin() const =0
Concrete class must implement:
virtual iterator end()
Definition: ISequence.h:46
virtual iterator end()
Definition: ISequence.h:73
intermediate_table::const_iterator const_iterator
static const_iterator cadapt(const OtherIter &itr)
Definition: ISequence.h:36
IDataClass::base_iterator base_iterator
Definition: ISequence.h:27
SequenceAdapter(const OtherIter &begin, const OtherIter &end)
Definition: ISequence.h:67
ISequence< IDataClass > this_type
Definition: ISequence.h:20
virtual iterator begin()
Definition: ISequence.h:45
IDataClass::iterator iterator
Definition: ISequence.h:25
Definition: Main.h:22
virtual const_iterator begin() const
Definition: ISequence.h:43
std::shared_ptr< this_type > pointer
Access this sequence via shared (non-const) pointer.
Definition: ISequence.h:23
IDataClass::const_iterator const_iterator
Definition: ISequence.h:26
virtual iterator begin()
Definition: ISequence.h:72
ISequence< IDataClass >::iterator iterator
Definition: ISequence.h:64
IDataClass::iterator_range iterator_range
Definition: ISequence.h:28
virtual const_iterator end() const
Definition: ISequence.h:44
virtual iterator_range range()
Return begin/end pair as iterator range.
Definition: ISequence.h:50
static iterator adapt(const OtherIter &itr)
Adapt one iterator to the standard facade iterator.
Definition: ISequence.h:32