Go to the documentation of this file.00001
00002 #ifndef vbl_sparse_array_2d_h_
00003 #define vbl_sparse_array_2d_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <vcl_iostream.h>
00026 #include <vcl_utility.h>
00027 #include <vbl/vbl_sparse_array_base.h>
00028
00029
00030 template <class T>
00031 class vbl_sparse_array_2d : public vbl_sparse_array_base<T, vcl_pair<unsigned, unsigned> >
00032 {
00033 typedef typename vbl_sparse_array_base<T,vcl_pair<unsigned,unsigned> >::Index_type Index_type;
00034 public:
00035 typedef typename vbl_sparse_array_base<T,vcl_pair<unsigned,unsigned> >::const_iterator const_iterator;
00036
00037
00038 bool put(unsigned i, unsigned j, const T& t)
00039 {
00040 return vbl_sparse_array_base<T, Index_type>::put(vcl_make_pair(i, j), t);
00041 }
00042
00043
00044
00045
00046 T& operator () (unsigned i, unsigned j)
00047 {
00048 return vbl_sparse_array_base<T, Index_type>::operator() (vcl_make_pair(i, j));
00049 }
00050
00051
00052 const T& operator () (unsigned i, unsigned j) const
00053 {
00054 return vbl_sparse_array_base<T, Index_type>::operator() (vcl_make_pair(i, j));
00055 }
00056
00057
00058 void erase(unsigned i, unsigned j) {
00059 vbl_sparse_array_base<T, Index_type>::erase(vcl_make_pair(i,j));
00060 }
00061
00062
00063 bool fullp(unsigned i, unsigned j) const
00064 {
00065 return vbl_sparse_array_base<T, Index_type>::fullp(vcl_make_pair(i, j));
00066 }
00067
00068
00069 T* get_addr(unsigned i, unsigned j)
00070 {
00071 return vbl_sparse_array_base<T, Index_type>::get_addr(vcl_make_pair(i, j));
00072 }
00073
00074
00075 vcl_ostream& print(vcl_ostream& out) const
00076 {
00077 for (const_iterator p = this->begin(); p != this->end(); ++p)
00078 out << '(' << (*p).first.first
00079 << ',' << (*p).first.second
00080 << "): " << (*p).second << vcl_endl;
00081 return out;
00082 }
00083 };
00084
00085
00086 template <class T>
00087 inline vcl_ostream& operator<< (vcl_ostream& s, const vbl_sparse_array_2d<T>& a)
00088 {
00089 return a.print(s);
00090 }
00091
00092 #ifndef VBL_SPARSE_ARRAY_BASE_INSTANTIATE
00093 #define VBL_SPARSE_ARRAY_BASE_INSTANTIATE(T) \
00094 extern "please include vbl/vbl_sparse_array_base.txx instead"
00095 #endif // VBL_SPARSE_ARRAY_BASE_INSTANTIATE
00096 #define VBL_SPARSE_ARRAY_2D_INSTANTIATE(T) \
00097 extern "please include vbl/vbl_sparse_array_2d.txx instead"
00098
00099 #endif // vbl_sparse_array_2d_h_