Jpp  18.5.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 JRewindableObjectIterator. More...

#include <JObjectSampler.hh>

Inheritance diagram for JLANG::JObjectSampler< T, JSampler_t >:
JLANG::JObjectIterator< T > JSUPPORT::JMultipleFileSampler< JDAQSummaryslice, JRandomSampler > JSUPPORT::JMultipleFileSampler< T, JSampler_t > JSUPPORT::JTreeSampler< T, JSampler_t > JSUPPORT::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 () override
 Check availability of next element. More...
 
virtual const pointer_typenext () override
 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< Tsampler
 
JPointer< Tps
 
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 JRewindableObjectIterator.

This class can be used for iterations that are different than strict sequential. The first template parameter corresponds to the data type of the iteration and the second to the sampler.
The sampling is defined by the number of objects to be skipped. The number of objects to be skipped is returned by the function object operator of the sampler which takes the actual object as input.
The default JSampler corresponds to zero elements to be skipped, which in turn corresponds to the iteration of all objects in sequential order.

The JObjectSampler class implements the JObjectIterator using a reference to a JRewindableObjectIterator object so that the sampling of objects can continue ad infinitum.

Method JObjectSampler::hasNext normally returns true, unless

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

Definition at line 40 of file JObjectSampler.hh.

Member Typedef Documentation

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

Definition at line 45 of file JObjectSampler.hh.

Constructor & Destructor Documentation

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 52 of file JObjectSampler.hh.

52  :
53  in (input),
54  has_next(false)
55  {}
JRewindableObjectIterator< T > & in
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 64 of file JObjectSampler.hh.

65  :
66  in (input),
67  has_next(false)
68  {
69  this->sampler = sampler;
70  }
JRewindableObjectIterator< T > & in
JSampler_t< T > sampler

Member Function Documentation

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

Check availability of next element.

Returns
true if the iteration has more elements; else false

Implements JLANG::JObjectIterator< T >.

Definition at line 78 of file JObjectSampler.hh.

79  {
80  while (!has_next) {
81 
82  if (!in.hasNext()) {
83  in.rewind();
84  }
85 
86  if (in.hasNext()) {
87 
88  ps.set(in.next());
89 
90  skip_type ns = sampler(*ps);
91 
92  if (ns == 0) {
93 
94  has_next = true;
95 
96  } else {
97 
98  while ((ns -= in.skip(ns)) != 0) {
99  in.rewind();
100  }
101  }
102 
103  } else {
104 
105  // nothing to sample
106 
107  break;
108  }
109  }
110 
111  return has_next;
112  }
unsigned int skip_type
Type definition for number of objects to skip.
std::vector< size_t > ns
JRewindableObjectIterator< T > & in
virtual void set(JClass_t *p) override
Set pointer.
Definition: JPointer.hh:75
JSampler_t< T > sampler
template<class T, template< class > class JSampler_t = JSampler>
virtual const pointer_type& JLANG::JObjectSampler< T, JSampler_t >::next ( )
inlineoverridevirtual

Get next element.

Returns
pointer to element

Implements JLANG::JObjectIterator< T >.

Definition at line 120 of file JObjectSampler.hh.

121  {
122  if (!has_next) {
123  ps.reset(NULL);
124  }
125 
126  has_next = false;
127 
128  return ps;
129  }
virtual void reset() override
Reset pointer.
Definition: JPointer.hh:84
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 137 of file JObjectSampler.hh.

138  {
139  return sampler;
140  }
JSampler_t< T > sampler
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 148 of file JObjectSampler.hh.

149  {
150  return sampler;
151  }
JSampler_t< T > sampler
template<class T>
virtual skip_type JLANG::JObjectIterator< T >::skip ( const skip_type  ns)
inlinevirtualinherited

Skip items.

Parameters
nsnumber of items to skip
Returns
number of items skipped

Reimplemented in JLANG::JPipe< T >, JLANG::JPipe< JTail_t >, JLANG::JPipe< JHead_t >, JLANG::JSTDObjectIterator< T >, JLANG::JAbstractObjectReader< T >, JLANG::JAbstractObjectReader< const event_type >, JLANG::JAbstractObjectReader< JNullType >, JLANG::JAbstractObjectReader< const T >, JLANG::JAbstractObjectReader< JTail_t >, JLANG::JAbstractObjectReader< JHead_t >, JLANG::JAbstractObjectReader< KM3NETDAQ::KM3NETDAQ::JDAQEvent >, and JLANG::JAbstractObjectReader< JDAQSummaryslice >.

Definition at line 90 of file JObjectIterator.hh.

91  {
92  skip_type i = 0;
93 
94  for ( ; i != ns && hasNext(); ++i) {
95  next();
96  }
97 
98  return i;
99  }
unsigned int skip_type
Type definition for number of objects to skip.
std::vector< size_t > ns
virtual const pointer_type & next()=0
Get next element.
virtual bool hasNext()=0
Check availability of next element.

Member Data Documentation

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

Definition at line 154 of file JObjectSampler.hh.

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

Definition at line 155 of file JObjectSampler.hh.

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

Definition at line 156 of file JObjectSampler.hh.

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

Definition at line 157 of file JObjectSampler.hh.


The documentation for this class was generated from the following file: