Base class for objects which can return a set of objects, one at a time. More...
#include <mbl_file_data_wrapper.h>
Public Member Functions | |
mbl_file_data_wrapper (const vcl_string path) | |
virtual | ~mbl_file_data_wrapper () |
Default destructor. | |
void | calc_data_size () |
count number of data items. | |
virtual unsigned long | size () const |
Number of objects available. | |
virtual void | reset () |
Reset so that current() returns first object. | |
virtual const T & | current () |
Return current object. | |
virtual bool | next () |
Move to next object, returning true if is valid. | |
virtual unsigned long | index () const |
Return current index. | |
virtual mbl_data_wrapper< T > * | clone () const |
Create copy on heap and return base pointer. | |
virtual vcl_string | is_a () const |
Name of the class. | |
virtual bool | is_class (vcl_string const &s) const |
True if this is (or is derived from) class named s. | |
virtual void | set_index (unsigned long n) |
Move to element n. | |
Private Attributes | |
vsl_b_ifstream | bfs_ |
vcl_string | path_ |
T | d_ |
unsigned long | index_ |
unsigned long | size_ |
Base class for objects which can return a set of objects, one at a time.
This is an iterator-like object. However, unlike STL, generality is obtained by deriving from the class rather than providing a similar interface.
In particular one can query the object to find out how many examples to expect.
A typical use is to allow clients to build models from sets of data without having to hold all the data in memory at once.
Example:
vnl_vector<double> my_sum(mbl_file_data_wrapper<vnl_vector<double> >& data) { data.reset(); vnl_vector<double> sum = data.current(); while (data.next()) sum += data.current(); }
Note: It should be fairly simple to provide an iterator type object which steps through the examples in a standard STL way by using this class.
Definition at line 43 of file mbl_file_data_wrapper.h.
mbl_file_data_wrapper< T >::mbl_file_data_wrapper | ( | const vcl_string | path | ) |
Definition at line 15 of file mbl_file_data_wrapper.txx.
mbl_file_data_wrapper< T >::~mbl_file_data_wrapper | ( | ) | [virtual] |
Default destructor.
Definition at line 72 of file mbl_file_data_wrapper.txx.
void mbl_file_data_wrapper< T >::calc_data_size | ( | ) |
count number of data items.
Count number of items in file.
Definition at line 34 of file mbl_file_data_wrapper.txx.
mbl_data_wrapper< T > * mbl_file_data_wrapper< T >::clone | ( | ) | const [virtual] |
Create copy on heap and return base pointer.
This will create an independent iterator on the underlying data. The original data is not copied. Be careful of destruction of underlying data.
Implements mbl_data_wrapper< T >.
Definition at line 182 of file mbl_file_data_wrapper.txx.
const T & mbl_file_data_wrapper< T >::current | ( | ) | [virtual] |
Return current object.
Implements mbl_data_wrapper< T >.
Definition at line 121 of file mbl_file_data_wrapper.txx.
unsigned long mbl_file_data_wrapper< T >::index | ( | ) | const [virtual] |
Return current index.
First example has index 0
Implements mbl_data_wrapper< T >.
Definition at line 157 of file mbl_file_data_wrapper.txx.
virtual vcl_string mbl_file_data_wrapper< T >::is_a | ( | ) | const [virtual] |
Name of the class.
Implements mbl_data_wrapper< T >.
bool mbl_file_data_wrapper< T >::is_class | ( | vcl_string const & | s | ) | const [virtual] |
True if this is (or is derived from) class named s.
Implements mbl_data_wrapper< T >.
Definition at line 188 of file mbl_file_data_wrapper.txx.
bool mbl_file_data_wrapper< T >::next | ( | ) | [virtual] |
Move to next object, returning true if is valid.
Read in next object.
Implements mbl_data_wrapper< T >.
Definition at line 129 of file mbl_file_data_wrapper.txx.
void mbl_file_data_wrapper< T >::reset | ( | ) | [virtual] |
Reset so that current() returns first object.
Reset.
Implements mbl_data_wrapper< T >.
Definition at line 86 of file mbl_file_data_wrapper.txx.
void mbl_data_wrapper< T >::set_index | ( | unsigned long | n | ) | [virtual, inherited] |
Move to element n.
First example has index 0
Reimplemented in mbl_selected_data_wrapper< T >, mbl_data_array_wrapper< T >, mbl_data_wrapper_mixer< T >, and mbl_data_array_ptr_wrapper< T >.
Definition at line 29 of file mbl_data_wrapper.txx.
unsigned long mbl_file_data_wrapper< T >::size | ( | ) | const [virtual] |
Number of objects available.
return number of items in file.
Implements mbl_data_wrapper< T >.
Definition at line 78 of file mbl_file_data_wrapper.txx.
vsl_b_ifstream mbl_file_data_wrapper< T >::bfs_ [private] |
Definition at line 46 of file mbl_file_data_wrapper.h.
T mbl_file_data_wrapper< T >::d_ [private] |
Definition at line 52 of file mbl_file_data_wrapper.h.
unsigned long mbl_file_data_wrapper< T >::index_ [private] |
Definition at line 55 of file mbl_file_data_wrapper.h.
vcl_string mbl_file_data_wrapper< T >::path_ [private] |
Definition at line 49 of file mbl_file_data_wrapper.h.
unsigned long mbl_file_data_wrapper< T >::size_ [private] |
Definition at line 58 of file mbl_file_data_wrapper.h.