Jpp
Public Types | Public Member Functions | Protected Attributes | List of all members
JLANG::JObjectSampler< T, JSampler_t > Class Template Reference

Auxiliary class to sample objects from a rewindable object iterator. More...

#include <JObjectSampler.hh>

Inheritance diagram for JLANG::JObjectSampler< T, JSampler_t >:
JLANG::JObjectIterator< T > JSUPPORT::JMultipleFileSampler< JDAQSummaryslice, JRandomSampler > JSUPPORT::JMultipleFileSampler< T, JSampler_t > JTRIGGER::JRunByRun

Public Types

typedef JObjectIterator< T >::pointer_type pointer_type
 

Public Member Functions

 JObjectSampler (JRewindableObjectIterator< T > &input)
 Constructor. More...
 
 JObjectSampler (JRewindableObjectIterator< T > &input, const JSampler_t< T > &sampler)
 Constructor. More...
 
virtual bool hasNext ()
 Check availability of next element. More...
 
virtual const pointer_typenext ()
 Get next element. More...
 
const JSampler_t< T > & getSampler () const
 Get sampler. More...
 
JSampler_t< T > & getSampler ()
 Get sampler. More...
 
virtual skip_type skip (const skip_type ns)
 Skip items. More...
 

Protected Attributes

JRewindableObjectIterator< T > & in
 
JSampler_t< T > sampler
 
JPointer< T > ps
 
bool has_next
 

Detailed Description

template<class T, template< class > class JSampler_t = JSampler>
class JLANG::JObjectSampler< T, JSampler_t >

Auxiliary class to sample objects from a rewindable object iterator.

Method hasNext normally returns true, unless

Note that the internal sampler is a copy of the specified sampler and not a reference thereof.

This class implements the JObjectIterator interface.

Definition at line 30 of file JObjectSampler.hh.

Member Typedef Documentation

◆ pointer_type

template<class T, template< class > class JSampler_t = JSampler>
typedef JObjectIterator<T>::pointer_type JLANG::JObjectSampler< T, JSampler_t >::pointer_type

Definition at line 35 of file JObjectSampler.hh.

Constructor & Destructor Documentation

◆ JObjectSampler() [1/2]

template<class T, template< class > class JSampler_t = JSampler>
JLANG::JObjectSampler< T, JSampler_t >::JObjectSampler ( JRewindableObjectIterator< T > &  input)
inline

Constructor.

Parameters
inputinput

Definition at line 42 of file JObjectSampler.hh.

42  :
43  in (input),
44  has_next(false)
45  {}

◆ JObjectSampler() [2/2]

template<class T, template< class > class JSampler_t = JSampler>
JLANG::JObjectSampler< T, JSampler_t >::JObjectSampler ( JRewindableObjectIterator< T > &  input,
const JSampler_t< T > &  sampler 
)
inline

Constructor.

Parameters
inputinput
samplersampler

Definition at line 54 of file JObjectSampler.hh.

55  :
56  in (input),
57  has_next(false)
58  {
59  this->sampler = sampler;
60  }

Member Function Documentation

◆ hasNext()

template<class T, template< class > class JSampler_t = JSampler>
virtual bool JLANG::JObjectSampler< T, JSampler_t >::hasNext ( )
inlinevirtual

Check availability of next element.

Returns
true if the iteration has more elements; else false

Implements JLANG::JObjectIterator< T >.

Definition at line 68 of file JObjectSampler.hh.

69  {
70  while (!has_next) {
71 
72  if (!in.hasNext()) {
73  in.rewind();
74  }
75 
76  if (in.hasNext()) {
77 
78  ps.set(in.next());
79 
80  skip_type ns = sampler(*ps);
81 
82  if (ns == 0) {
83 
84  has_next = true;
85 
86  } else {
87 
88  while ((ns -= in.skip(ns)) != 0) {
89  in.rewind();
90  }
91  }
92 
93  } else {
94 
95  // nothing to sample
96 
97  break;
98  }
99  }
100 
101  return has_next;
102  }

◆ next()

template<class T, template< class > class JSampler_t = JSampler>
virtual const pointer_type& JLANG::JObjectSampler< T, JSampler_t >::next ( )
inlinevirtual

Get next element.

Returns
pointer to element

Implements JLANG::JObjectIterator< T >.

Definition at line 110 of file JObjectSampler.hh.

111  {
112  if (!has_next) {
113  ps.reset(NULL);
114  }
115 
116  has_next = false;
117 
118  return ps;
119  }

◆ getSampler() [1/2]

template<class T, template< class > class JSampler_t = JSampler>
const JSampler_t<T>& JLANG::JObjectSampler< T, JSampler_t >::getSampler ( ) const
inline

Get sampler.

Returns
sampler

Definition at line 127 of file JObjectSampler.hh.

128  {
129  return sampler;
130  }

◆ getSampler() [2/2]

template<class T, template< class > class JSampler_t = JSampler>
JSampler_t<T>& JLANG::JObjectSampler< T, JSampler_t >::getSampler ( )
inline

Get sampler.

Returns
sampler

Definition at line 138 of file JObjectSampler.hh.

139  {
140  return sampler;
141  }

◆ skip()

template<class T>
virtual skip_type JLANG::JObjectIterator< T >::skip ( const skip_type  ns)
inlinevirtualinherited

Member Data Documentation

◆ in

template<class T, template< class > class JSampler_t = JSampler>
JRewindableObjectIterator<T>& JLANG::JObjectSampler< T, JSampler_t >::in
protected

Definition at line 144 of file JObjectSampler.hh.

◆ sampler

template<class T, template< class > class JSampler_t = JSampler>
JSampler_t<T> JLANG::JObjectSampler< T, JSampler_t >::sampler
protected

Definition at line 145 of file JObjectSampler.hh.

◆ ps

template<class T, template< class > class JSampler_t = JSampler>
JPointer<T> JLANG::JObjectSampler< T, JSampler_t >::ps
protected

Definition at line 146 of file JObjectSampler.hh.

◆ has_next

template<class T, template< class > class JSampler_t = JSampler>
bool JLANG::JObjectSampler< T, JSampler_t >::has_next
protected

Definition at line 147 of file JObjectSampler.hh.


The documentation for this class was generated from the following file:
JLANG::JPointer::set
virtual void set(JClass_t *p)
Set pointer.
Definition: JPointer.hh:75
JLANG::skip_type
unsigned int skip_type
Type definition for number of objects to skip.
Definition: JObjectIterator.hh:25
JLANG::JObjectIterator::hasNext
virtual bool hasNext()=0
Check availability of next element.
JLANG::JObjectSampler::in
JRewindableObjectIterator< T > & in
Definition: JObjectSampler.hh:144
JLANG::JPointer::reset
virtual void reset()
Reset pointer.
Definition: JPointer.hh:84
JLANG::JObjectSampler::has_next
bool has_next
Definition: JObjectSampler.hh:147
JLANG::JObjectSampler::ps
JPointer< T > ps
Definition: JObjectSampler.hh:146
JLANG::JObjectIterator::next
virtual const pointer_type & next()=0
Get next element.
JLANG::JObjectSampler::sampler
JSampler_t< T > sampler
Definition: JObjectSampler.hh:145