vtf-logo

SparseArraySigned1.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00008 #if !defined(__ads_SparseArraySigned1_h__)
00009 #error This file is an implementation detail of the class SparseArraySigned.
00010 #endif
00011 
00012 #include "../defs.h"
00013 
00014 BEGIN_NAMESPACE_ADS
00015 
00016 
00018 
00035 template<typename T>
00036 class SparseArraySigned<1,T> : public SparseArray<1,T> {
00037   //
00038   // Private types.
00039   //
00040 
00041 private:
00042 
00043   typedef ArrayTypes<T> Types;
00044   typedef SparseArray<1,T> Base;
00045 
00046   //
00047   // Public Types.
00048   //
00049 
00050 public:
00051 
00053   typedef typename Types::value_type value_type;
00055 
00058   typedef typename Types::parameter_type parameter_type;
00060 
00063   typedef typename Types::unqualified_value_type unqualified_value_type;
00064 
00066   typedef typename Types::pointer pointer;
00068   typedef typename Types::const_pointer const_pointer;
00069 
00071   typedef typename Types::iterator iterator;
00073   typedef typename Types::const_iterator const_iterator;
00074 
00076   typedef typename Types::reference reference;
00078   typedef typename Types::const_reference const_reference;
00079 
00081 
00087   typedef typename Types::size_type size_type;
00089   typedef typename Types::difference_type difference_type;
00090 
00092   typedef int index_type;
00093 
00094   //
00095   // Data.
00096   //
00097 
00098 protected:
00099 
00101   int _sign;
00102 
00103   //
00104   // Using
00105   //
00106 
00107 public:
00108 
00109   // Static members.
00110   using Base::getRank;
00111 
00112   // Accessors.
00113   using Base::size;
00114   using Base::empty;
00115   using Base::max_size;
00116   using Base::begin;
00117   using Base::end;
00118   using Base::data;
00119   using Base::operator[];
00120   using Base::getNull;
00121   using Base::isNull;
00122   using Base::isNonNull;
00123   using Base::fillNonNull;
00124   using Base::getIndices;
00125 
00126   // Manipulators.
00127   //using Base::begin;
00128   //using Base::end;
00129   //using Base::data;
00130 
00131   // File I/O.
00132   using Base::write_elements_ascii;
00133   using Base::write_elements_binary;
00134   using Base::read_elements_ascii;
00135   using Base::read_elements_binary;
00136 
00137 protected:
00138 
00139   // Data.
00140   using Base::_indices;
00141   using Base::_null;
00142 
00143   //
00144   // Friends.
00145   //
00146 
00148   friend void merge<>(const SparseArraySigned<1,T>& a, 
00149                       const SparseArraySigned<1,T>& b, 
00150                       SparseArraySigned<1,T>* c);
00151 
00153   friend void removeUnecessaryElements<>(SparseArraySigned<1,T>* a);
00154 
00156   friend void computeUnion<>(const SparseArraySigned<1,T>& a, 
00157                              const SparseArraySigned<1,T>& b, 
00158                              SparseArraySigned<1,T>* c);
00159 
00161   friend void computeIntersection<>(const SparseArraySigned<1,T>& a, 
00162                                     const SparseArraySigned<1,T>& b, 
00163                                     SparseArraySigned<1,T>* c);
00164 
00165 public:
00166 
00167   //--------------------------------------------------------------------------
00169   // @{
00170 
00172   SparseArraySigned(parameter_type nullValue 
00173                     = std::numeric_limits<value_type>::max()) :
00174     Base(nullValue),
00175     _sign(1)
00176   {}
00177 
00179   template<typename IndexForwardIter, typename ValueForwardIter>
00180   SparseArraySigned(IndexForwardIter indicesBeginning, 
00181                     IndexForwardIter indicesEnd,
00182                     ValueForwardIter valuesBeginning, 
00183                     ValueForwardIter valuesEnd,
00184                     parameter_type nullValue
00185                     = std::numeric_limits<value_type>::max());
00186 
00188   template<typename T2, bool A>
00189   SparseArraySigned(const Array<1,T2,A>& array, parameter_type nullValue);
00190 
00192   SparseArraySigned(const SparseArraySigned& other) :
00193     Base(other),
00194     _sign(other._sign)
00195   {}
00196 
00198   ~SparseArraySigned()
00199   {}
00200 
00201   // @}
00202   //--------------------------------------------------------------------------
00204   // @{
00205 
00207   SparseArraySigned& 
00208   operator=(const SparseArraySigned& other) {
00209     if (&other != this) {
00210       Base::operator=(other);
00211       _sign = other._sign;
00212     }
00213     return *this;
00214   }
00215 
00216   // @}
00217   //--------------------------------------------------------------------------
00219   // @{
00220 
00222   int
00223   getSign() const {
00224     return _sign;
00225   }
00226 
00228   size_type 
00229   getMemoryUsage() const {
00230     return Base::getMemoryUsage() + sizeof(int);
00231   }
00232 
00234   value_type
00235   operator()(const int i) const;
00236 
00238   bool
00239   operator==(const SparseArraySigned& x) const {
00240     return (Base::operator==(x) && _sign == x._sign);
00241   }
00242 
00244   template<typename T2, bool A>
00245   void
00246   fill(ads::Array<1,T2,A>* array) const;
00247 
00248   // @}
00249   //--------------------------------------------------------------------------
00251   // @{
00252 
00254   void
00255   swap(SparseArraySigned& x) {
00256     Base::swap(x);
00257     std::swap(_sign, x._sign);
00258   }
00259 
00261   void
00262   negate() {
00263     if (empty()) {
00264       _sign = - _sign;
00265     }
00266     Base::negate();
00267   }
00268 
00270   void
00271   setSign(const int sign) {
00272     _sign = sign;
00273   }
00274 
00275   // @}
00276   //--------------------------------------------------------------------------
00281   // @{
00282 
00284   SparseArraySigned& 
00285   operator=(parameter_type x) {
00286     Base::operator=(x);
00287     return *this;
00288   }
00289 
00291   SparseArraySigned& 
00292   operator+=(parameter_type x) {
00293     Base::operator+=(x);
00294     return *this;
00295   }
00296 
00298   SparseArraySigned& 
00299   operator-=(parameter_type x) {
00300     Base::operator-=(x);
00301     return *this;
00302   }
00303 
00305   SparseArraySigned& 
00306   operator*=(parameter_type x) {
00307     Base::operator*=(x);
00308     return *this;
00309   }
00310 
00312   SparseArraySigned& 
00313   operator/=(parameter_type x) {
00314     Base::operator/=(x);
00315     return *this;
00316   }
00317 
00319   SparseArraySigned& 
00320   operator%=(parameter_type x) {
00321     Base::operator%=(x);
00322     return *this;
00323   }
00324 
00325   // @}
00326   //--------------------------------------------------------------------------
00328   // @{
00329 
00331   void
00332   put(std::ostream& out) const;
00333 
00335   void
00336   get(std::istream& in);
00337 
00338   // @}
00339 };
00340 
00341 
00342 END_NAMESPACE_ADS
00343 
00344 #define __ads_SparseArraySigned1_ipp__
00345 #include "SparseArraySigned1.ipp"
00346 #undef __ads_SparseArraySigned1_ipp__

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