00001 // This is mul/mbl/mbl_data_array_ptr_wrapper.h 00002 #ifndef mbl_data_array_ptr_wrapper_h 00003 #define mbl_data_array_ptr_wrapper_h 00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE 00005 #pragma interface 00006 #endif 00007 //: 00008 // \file 00009 // \author Tim Cootes 00010 // \brief A wrapper to provide access to objects through C-arrays of pointers 00011 00012 #include <mbl/mbl_data_wrapper.h> 00013 #include <vcl_vector.h> 00014 00015 //: A wrapper to provide access to objects through C-arrays of pointers 00016 template<class T> 00017 class mbl_data_array_ptr_wrapper : public mbl_data_wrapper<T> 00018 { 00019 const T*const* data_; 00020 unsigned long n_; 00021 unsigned long index_; 00022 public: 00023 //: Default constructor 00024 mbl_data_array_ptr_wrapper(); 00025 00026 //: Constructor 00027 // Sets up object to return n examples beginning at data[0]. 00028 // The data must be kept in scope, this does not take a copy. 00029 mbl_data_array_ptr_wrapper(const T*const* data, unsigned long n); 00030 00031 //: Constructor 00032 // Sets up object to wrap a vcl_vector. 00033 // The data must be kept in scope, this does not take a copy. 00034 mbl_data_array_ptr_wrapper(const vcl_vector<const T* > &data); 00035 00036 //: Initialise to return elements from data[i] 00037 // Sets up object to return n examples beginning at data[0]. 00038 // The data must be kept in scope, this does not take a copy. 00039 void set(const T*const* data, unsigned long n); 00040 00041 //: Default destructor 00042 virtual ~mbl_data_array_ptr_wrapper(); 00043 00044 //: Number of objects available 00045 virtual unsigned long size() const; 00046 00047 //: Return pointer to start of data array 00048 const T*const* data() const { return data_; } 00049 00050 //: Reset so that current() returns first object 00051 virtual void reset(); 00052 00053 //: Return current object 00054 virtual const T& current(); 00055 00056 //: Move to next object, returning true if is valid 00057 virtual bool next(); 00058 00059 //: Return current index 00060 // First example has index 0 00061 virtual unsigned long index() const; 00062 00063 //: Move to element n 00064 // First example has index 0 00065 virtual void set_index(unsigned long n); 00066 00067 //: Create copy on heap and return base pointer 00068 virtual mbl_data_wrapper< T >* clone() const; 00069 00070 //: Name of the class 00071 virtual vcl_string is_a() const; 00072 00073 //: True if this is (or is derived from) class named s 00074 virtual bool is_class(vcl_string const& s) const; 00075 }; 00076 00077 #endif // mbl_data_array_ptr_wrapper_h