core/vbl/vbl_sparse_array_1d.h
Go to the documentation of this file.
00001 // This is core/vbl/vbl_sparse_array_1d.h
00002 #ifndef vbl_sparse_array_1d_h_
00003 #define vbl_sparse_array_1d_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Sparse array allowing space efficient access of the form s[3000]=2.
00010 // \author  Andrew W. Fitzgibbon, Oxford RRG
00011 // \date    02 Oct 96
00012 //
00013 // \verbatim
00014 //  Modifications
00015 //   Ian Scott (Manchester, ISBE) rewritten to use vbl_sparse_array_base
00016 // \endverbatim
00017 //---------------------------------------------------------------------------
00018 
00019 #include <vbl/vbl_sparse_array_base.h>
00020 #include <vcl_iostream.h>
00021 
00022 //: Sparse array allowing space efficient access of the form s[3000] = 2;
00023 template <class T>
00024 class vbl_sparse_array_1d: public vbl_sparse_array_base<T, unsigned>
00025 {
00026  public:
00027   typedef typename vbl_sparse_array_base<T,unsigned>::const_iterator const_iterator;
00028 
00029   //: Print the Array to a stream in "(i,j): value" format.
00030   vcl_ostream& print(vcl_ostream& out) const
00031   {
00032     for (const_iterator p = this->begin(); p != this->end(); ++p)
00033       out << '(' << (*p).first << "): " << (*p).second << vcl_endl;
00034     return out;
00035   }
00036 };
00037 
00038 //: Stream operator - print the Array to a stream in "(i,j): value" format.
00039 template <class T>
00040 inline vcl_ostream& operator<< (vcl_ostream& s, const vbl_sparse_array_1d<T>& a)
00041 {
00042   return a.print(s);
00043 }
00044 
00045 #ifndef VBL_SPARSE_ARRAY_BASE_INSTANTIATE
00046 #define VBL_SPARSE_ARRAY_BASE_INSTANTIATE(T) \
00047 extern "please include vbl/vbl_sparse_array_base.txx instead"
00048 #endif // VBL_SPARSE_ARRAY_BASE_INSTANTIATE
00049 #define VBL_SPARSE_ARRAY_1D_INSTANTIATE(T) \
00050 extern "please include vbl/vbl_sparse_array_1d.txx instead"
00051 
00052 #endif // vbl_sparse_array_1d_h_