00001 // This is mul/mbl/mbl_data_array_wrapper.h 00002 #ifndef mbl_data_array_wrapper_h 00003 #define mbl_data_array_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 C-arrays of objects 00011 00012 #include <mbl/mbl_data_wrapper.h> 00013 #include <vcl_vector.h> 00014 00015 //: A wrapper to provide access to C-arrays of objects 00016 template<class T> 00017 class mbl_data_array_wrapper : public mbl_data_wrapper<T> 00018 { 00019 const T* data_; 00020 unsigned long n_; 00021 unsigned long index_; 00022 public: 00023 //: Default constructor 00024 mbl_data_array_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_wrapper(const T* 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_wrapper(const vcl_vector<T > &data); 00035 00036 //: Copy Constructor 00037 // The copy will point to the same data as the original. 00038 // The data must be kept in scope, this does not take a copy. 00039 mbl_data_array_wrapper(const mbl_data_array_wrapper<T > &orig); 00040 00041 //: Initialise to return elements from data[i] 00042 // Sets up object to return n examples beginning at data[0]. 00043 // The data must be kept in scope, this does not take a copy. 00044 void set(const T* data, unsigned long n); 00045 00046 //: Default destructor 00047 virtual ~mbl_data_array_wrapper(); 00048 00049 //: Number of objects available 00050 virtual unsigned long size() const; 00051 00052 //: Return pointer to start of data array 00053 const T* data() const { return data_; } 00054 00055 //: Reset so that current() returns first object 00056 virtual void reset(); 00057 00058 //: Return current object 00059 virtual const T& current(); 00060 00061 //: Move to next object, returning true if is valid 00062 virtual bool next(); 00063 00064 //: Return current index 00065 // First example has index 0 00066 virtual unsigned long index() const; 00067 00068 //: Move to element n 00069 // First example has index 0 00070 virtual void set_index(unsigned long n); 00071 00072 //: Create copy on heap and return base pointer 00073 virtual mbl_data_wrapper< T >* clone() const; 00074 00075 //: Name of the class 00076 virtual vcl_string is_a() const; 00077 00078 //: True if this is (or is derived from) class named s 00079 virtual bool is_class(vcl_string const& s) const; 00080 }; 00081 00082 #endif // mbl_data_array_wrapper_h