vtf-logo

SparseArray2.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00008 #if !defined(__ads_SparseArray2_h__)
00009 #error This file is an implementation detail of the class SparseArray.
00010 #endif
00011 
00012 #include "../defs.h"
00013 
00014 #include "../functor/select.h"
00015 
00016 BEGIN_NAMESPACE_ADS
00017 
00018 
00020 
00027 template<typename T>
00028 class SparseArray<2,T> : public SparseArray<1,T> {
00029   //
00030   // Private types.
00031   //
00032 
00033 private:
00034 
00035   typedef ArrayTypes<T> Types;
00036   typedef SparseArray<1,T> Base;
00037 
00038   //
00039   // Public Types.
00040   //
00041 
00042 public:
00043 
00045   typedef typename Types::value_type value_type;
00047 
00050   typedef typename Types::parameter_type parameter_type;
00052 
00055   typedef typename Types::unqualified_value_type unqualified_value_type;
00056 
00058   typedef typename Types::pointer pointer;
00060   typedef typename Types::const_pointer const_pointer;
00061 
00063   typedef typename Types::iterator iterator;
00065   typedef typename Types::const_iterator const_iterator;
00066 
00068   typedef typename Types::reference reference;
00070   typedef typename Types::const_reference const_reference;
00071 
00073 
00079   typedef typename Types::size_type size_type;
00081   typedef typename Types::difference_type difference_type;
00082 
00084   typedef FixedArray<2,int> index_type;
00085 
00086   //
00087   // Data.
00088   //
00089 
00090 private:
00091 
00093   Array<1,int> _offsets;
00094 
00095   //
00096   // Using
00097   //
00098 
00099 public:
00100 
00101   // Accessors.
00102   using Base::size;
00103   using Base::empty;
00104   using Base::max_size;
00105   using Base::begin;
00106   using Base::end;
00107   using Base::data;
00108   using Base::operator[];
00109   using Base::getNull;
00110 
00111   // Manipulators.
00112   //using Base::begin;
00113   //using Base::end;
00114   //using Base::data;
00115   using Base::negate;
00116 
00117   // File I/O.
00118   using Base::write_elements_ascii;
00119   using Base::write_elements_binary;
00120   using Base::read_elements_ascii;
00121   using Base::read_elements_binary;
00122 
00123 private:
00124 
00125   // Using base data.
00126   using Base::_indices;
00127   using Base::_null;
00128 
00129 public:
00130 
00131   //--------------------------------------------------------------------------
00133   // @{
00134 
00136   SparseArray() :
00137     Base(),
00138     _offsets()
00139   {}
00140 
00142 
00147   template<typename IndexBiDirIter, typename ValueForwardIter>
00148   SparseArray(IndexBiDirIter indicesBeginning, IndexBiDirIter indicesEnd,
00149               ValueForwardIter valuesBeginning, ValueForwardIter valuesEnd,
00150               parameter_type nullValue = value_type());
00151 
00153   template<typename T2, bool A>
00154   SparseArray(const Array<2,T2,A>& array, parameter_type nullValue);
00155 
00157   SparseArray(const SparseArray& x) :
00158     Base(x),
00159     _offsets(x._offsets)
00160   {}
00161 
00163   ~SparseArray()
00164   {}
00165 
00166   // @}
00167   //--------------------------------------------------------------------------
00169   // @{
00170 
00172   SparseArray& 
00173   operator=(const SparseArray& other) {
00174     if (&other != this) {
00175       Base::operator=(other);
00176       _offsets = other._offsets;
00177     }
00178     return *this;
00179   }
00180 
00181   // @}
00182   //--------------------------------------------------------------------------
00184   // @{
00185 
00187   static
00188   int
00189   getRank() {
00190     return 2;
00191   }
00192 
00193   // @}
00194   //--------------------------------------------------------------------------
00196   // @{
00197 
00199   size_type 
00200   getMemoryUsage() const {
00201     return Base::getMemoryUsage() + _offsets.getMemoryUsage();
00202   }
00203 
00205   bool
00206   isNull(const index_type& index) const;
00207 
00209   bool
00210   isNonNull(const index_type& index) const {
00211     return ! isNull(index);
00212   }
00213 
00215   parameter_type
00216   operator()(const index_type& index) const;
00217 
00219   bool
00220   operator==(const SparseArray& x) const {
00221     return Base::operator==(x) && _offsets == x._offsets;
00222   }
00223 
00225   bool
00226   operator!=(const SparseArray& x) const {
00227     return ! operator==(x);
00228   }
00229 
00231   template<typename T2, bool A>
00232   void
00233   fill(ads::Array<2,T2,A>* array) const;
00234 
00236   template<typename T2, bool A>
00237   void
00238   fillNonNull(ads::Array<2,T2,A>* array) const;
00239 
00240   // @}
00241   //--------------------------------------------------------------------------
00243   // @{
00244 
00246   void
00247   swap(SparseArray& other) {
00248     if (&other != this) {
00249       Base::swap(other);
00250       _offsets.swap(other._offsets);
00251     }
00252   }
00253 
00254   // @}
00255   //--------------------------------------------------------------------------
00258   // @{
00259 
00261   SparseArray& 
00262   operator=(parameter_type x) {
00263     Base::operator=(x);
00264     return *this;
00265   }
00266 
00267   // @}
00268   //--------------------------------------------------------------------------
00270   // @{
00271 
00273   void
00274   put(std::ostream& out) const;
00275 
00277   void
00278   get(std::istream& in);
00279 
00280   // @}
00281 };
00282 
00283 END_NAMESPACE_ADS
00284 
00285 #define __ads_SparseArray2_ipp__
00286 #include "SparseArray2.ipp"
00287 #undef __ads_SparseArray2_ipp__

Generated on Fri Aug 24 12:55:29 2007 for Algorithms and Data Structures Package by  doxygen 1.4.7