vtf-logo

ArrayWithNullHoles.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00008 #if !defined(__ads_array_ArrayWithNullHoles_h__)
00009 #define __ads_array_ArrayWithNullHoles_h__
00010 
00011 // If we are debugging the whole ads package.
00012 #if defined(DEBUG_ads) && !defined(DEBUG_ArrayWithNullHoles)
00013 #define DEBUG_ArrayWithNullHoles
00014 #endif
00015 
00016 #include "../defs.h"
00017 
00018 #include "../../third-party/loki/TypeTraits.h"
00019 
00020 #include <vector>
00021 #include <set>
00022 
00023 #include <cassert>
00024 
00025 BEGIN_NAMESPACE_ADS
00026 
00028 
00031 template<typename T>
00032 class ArrayWithNullHoles {
00033   //
00034   // Private types.
00035   //
00036 
00037 private:
00038 
00039   typedef std::vector<T> ValueContainer;
00040   typedef std::vector<int> IndexContainer;
00041 
00042   //
00043   // Public types.
00044   //
00045 
00046 public:
00047 
00049   typedef T ValueType;
00051 
00054   typedef typename Loki::TypeTraits<ValueType>::ParameterType ParameterType;
00055 
00057   typedef typename ValueContainer::pointer Pointer;
00059   typedef typename ValueContainer::const_pointer ConstPointer;
00060 
00061   // CONTINUE: Iterators need to skip the holes.
00062 #if 0
00064   typedef typename Something Iterator;
00066   typedef typename Something ConstIterator;
00067 #endif
00068 
00070   typedef typename ValueContainer::reference Reference;
00072   typedef typename ValueContainer::const_reference ConstReference;
00073 
00075 
00081   typedef int SizeType;
00083   typedef typename ValueContainer::difference_type DifferenceType;
00084 
00085   //
00086   // Data.
00087   //
00088 
00089 private:
00090 
00092   ValueContainer _data;
00094   IndexContainer _holes;
00096   ValueType _null;
00097 
00098   //
00099   // Not implemented.
00100   //
00101 
00102 private:
00103 
00105   ArrayWithNullHoles();
00106 
00107 public:
00108 
00109   //--------------------------------------------------------------------------
00111   // @{
00112 
00114   ArrayWithNullHoles(ParameterType null) :
00115     _data(),
00116     _holes(),
00117     _null(null)
00118   {}
00119 
00121   ArrayWithNullHoles(const ArrayWithNullHoles& other) :
00122     _data(other._data),
00123     _holes(other._holes),
00124     _null(other._null)
00125   {}
00126 
00128   ArrayWithNullHoles& 
00129   operator=(const ArrayWithNullHoles& other)
00130   {
00131     // Avoid assignment to self.
00132     if (&other != this) {
00133       _data = other._data;
00134       _holes = other._holes;
00135       _null = other._null;
00136     }
00137     // Return *this so assignments can chain.
00138     return *this;
00139   }
00140 
00142   ~ArrayWithNullHoles()
00143   {}
00144 
00145   // @}
00146   //--------------------------------------------------------------------------
00148   // @{
00149 
00151   int
00152   size() const {
00153     return int(_data.size());
00154   }
00155 
00157   int
00158   sizeNull() const {
00159     return int(_holes.size());
00160   }
00161 
00163   int
00164   sizeNonNull() const {
00165     return size() - sizeNull();
00166   }
00167 
00169   bool
00170   isNull(int index) const;
00171 
00173   bool
00174   isNonNull(int index) const;
00175 
00177   ParameterType
00178   get(int index) const;
00179 
00180   // @}
00181   //--------------------------------------------------------------------------
00183   // @{
00184 
00186 
00189   int
00190   insert(ParameterType value);
00191 
00193 
00196   void
00197   erase(int index);
00198 
00200 
00203   template<typename IntInputIterator>
00204   void
00205   erase(IntInputIterator begin, IntInputIterator end);
00206 
00208 
00211   void
00212   set(int index, ParameterType value);
00213 
00214   // @}
00215   //--------------------------------------------------------------------------
00217   // @{
00218 
00220   bool
00221   isValid() const;
00222 
00223   // @}
00224 };
00225 
00226 
00227 END_NAMESPACE_ADS
00228 
00229 #define __ads_array_ArrayWithNullHoles_ipp__
00230 #include "ArrayWithNullHoles.ipp"
00231 #undef __ads_array_ArrayWithNullHoles_ipp__
00232 
00233 #endif

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