Титульная страница   Иерархия классов   Алфавитный указатель   Классы   Файлы   Члены классов   Члены файла   Примеры  

BGDNetCollection.h

См. документацию.
00001 
00006 #ifndef __BGDNetCollection_h__
00007 #define __BGDNetCollection_h__
00008 
00009 #include "BGDNetConfig.h"
00010 
00011 #include <vector>
00012 #include <assert.h>
00013 
00014 namespace BGDNet
00015 {
00016 
00017 using std::vector;
00018 
00025 template<class T>
00026 class BGDNET_API Collection
00027 {
00028 public:
00029 
00030   Collection( void );
00036   Collection( const Collection& col );
00041   Collection& operator =( const Collection& col );
00046   ~Collection( void );
00051   int size( void ) const;
00057   void resize( size_t sz, const T& x = T() );
00065   void add( const T& x );
00072   void clear( void );
00077   T& operator []( int n );
00084   const T& operator []( int n ) const;
00091   T& front( void );
00097   const T& front( void ) const;
00103   T& back( void );
00109   const T& back( void ) const;
00115 private:
00116 
00117   vector<T>* m_pCont;
00121 };
00122 
00123 template<class T>
00124 Collection<T>::Collection( void )
00125 {
00126   m_pCont = new vector<T>;
00127 }
00128 
00129 template<class T>
00130 Collection<T>::Collection( const Collection& col )
00131 {
00132   m_pCont = new vector<T>(*col.m_pCont);
00133 }
00134 
00135 template<class T>
00136 Collection<T>& Collection<T>::operator =( const Collection& col )
00137 {
00138   if (this != &col) // избегаем присваивания самому себе
00139     *m_pCont = *col.m_pCont;
00140   return *this;
00141 }
00142 
00143 template<class T>
00144 Collection<T>::~Collection( void )
00145 {
00146   delete m_pCont;
00147 }
00148 
00149 template<class T>
00150 int Collection<T>::size( void ) const
00151 {
00152   return m_pCont->size();
00153 }
00154 
00155 template<class T>
00156 void Collection<T>::resize( size_t sz, const T& x )
00157 {
00158   m_pCont->resize(sz, x);
00159 }
00160 
00161 template<class T>
00162 void Collection<T>::add( const T& x )
00163 {
00164   m_pCont->push_back(x);
00165 }
00166 
00167 template<class T>
00168 void Collection<T>::clear( void )
00169 {
00170   m_pCont->clear();
00171 }
00172 
00173 template<class T>
00174 T& Collection<T>::operator []( int n )
00175 {
00176   assert(0 <= n && n < size());
00177   return m_pCont->at(n);
00178 }
00179 
00180 template<class T>
00181 const T& Collection<T>::operator []( int n ) const
00182 {
00183   assert(0 <= n && n < size());
00184   return m_pCont->at(n);
00185 }
00186 
00187 template<class T>
00188 T& Collection<T>::front( void )
00189 {
00190   assert(size() > 0);
00191   return m_pCont->front();
00192 }
00193 
00194 template<class T>
00195 const T& Collection<T>::front( void ) const
00196 {
00197   assert(size() > 0);
00198   return m_pCont->front();
00199 }
00200 
00201 template<class T>
00202 T& Collection<T>::back( void )
00203 {
00204   assert(size() > 0);
00205   return m_pCont->back();
00206 }
00207 
00208 template<class T>
00209 const T& Collection<T>::back( void ) const
00210 {
00211   assert(size() > 0);
00212   return m_pCont->back();
00213 }
00214 
00215 } // namespace BGDNet
00216 
00217 #endif //__BGDNetCollection_h__

РУП БЕЛГИПРОДОР Документация на BGDNet сгенерирована Mon Apr 1 18:36:52 2002, БЕЛГИПРОДОР ©  2001