00001 // This is mul/mbl/mbl_selected_data_wrapper.h 00002 #ifndef mbl_selected_data_wrapper_h 00003 #define mbl_selected_data_wrapper_h 00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE 00005 #pragma interface 00006 #endif 00007 //: 00008 // \file 00009 // \author Ian Scott 00010 // \brief A subset of an existing mbl_data_wrapper. 00011 00012 #include <vcl_string.h> 00013 #include <vcl_vector.h> 00014 #include <mbl/mbl_data_wrapper.h> 00015 00016 //: A subset of an existing mbl_data_wrapper. 00017 // This wraps another mbl_data_wrapper, and acts like a rearrangement 00018 // of the original data. The rearrangement does not have to refer 00019 // to all of the original data, and can refer to the same data more than 00020 // once. 00021 00022 template <class T> 00023 class mbl_selected_data_wrapper: public mbl_data_wrapper<T> 00024 { 00025 mbl_data_wrapper<T> *data_; 00026 vcl_vector<unsigned> selection_; 00027 unsigned index_; 00028 public: 00029 //: Copy constructor. 00030 mbl_selected_data_wrapper(const mbl_selected_data_wrapper<T>& p); 00031 00032 //: Constructor. 00033 // This will take its own copy of selection and the data wrapper, 00034 // but not the underlying data. 00035 mbl_selected_data_wrapper(const mbl_data_wrapper<T>& data, 00036 const vcl_vector<unsigned> &subset); 00037 00038 //: Default constructor. 00039 mbl_selected_data_wrapper(); 00040 00041 //: Default destructor. 00042 virtual ~mbl_selected_data_wrapper(); 00043 00044 //: Copy operator. 00045 mbl_selected_data_wrapper<T>& operator=(const mbl_selected_data_wrapper<T>& b); 00046 00047 //: Set the wrappers data. 00048 // This will take its own copy of selection and the data wrapper, 00049 // but not the underlying data. 00050 void set(const mbl_data_wrapper<T>& data, 00051 const vcl_vector<unsigned> &selection); 00052 00053 //: Number of objects available. 00054 virtual unsigned long size() const; 00055 00056 //: Reset so that current() returns first object. 00057 virtual void reset(); 00058 00059 //: Return current object. 00060 virtual const T& current(); 00061 00062 //: Move to next object, returning true if is valid. 00063 virtual bool next(); 00064 00065 //: Return current index. 00066 // First example has index 0 00067 virtual unsigned long index() const; 00068 00069 //: Move to element n. 00070 // First example has index 0 00071 virtual void set_index(unsigned long n); 00072 00073 //: Create copy on heap and return base pointer. 00074 // This will create an independent iterator on the underlying data. 00075 // The original data is not copied. 00076 // Be careful of destruction of underlying data. 00077 virtual mbl_data_wrapper< T >* clone() const ; 00078 00079 //: Name of the class. 00080 virtual vcl_string is_a() const; 00081 00082 //: True if this is (or is derived from) class named s 00083 virtual bool is_class(vcl_string const& s) const; 00084 }; 00085 00086 #endif // mbl_selected_data_wrapper_h