TeComposite< T > Class Template Reference

#include <TeComposite.h>

Inheritance diagram for TeComposite< T >:

TeCounted TeTableImpl

Detailed Description

template<class T>
class TeComposite< T >

Provides a vector for storing components and ensures proper destruction of them, by means of a handle/body idiom. Provide a handle to an implementation and thus allow efficient copying of derived objects

Note:
This is a specialised example of the "Composite" design pattern, with support for the "Bridge" pattern (also known as the handle/body idiom).

Definition at line 85 of file TeComposite.h.


Public Types

typedef vector< T >
::const_iterator 
const_iterator
typedef vector< T >
::iterator 
iterator
 An iterator to the composite elements.
typedef vector< T >
::reverse_iterator 
reverse_iterator
 A reverse iterator to the composite elements.

Public Member Functions

void add (const T &elem)
 Adds a new component.
void attach ()
 Increases the number of references to this object.
iterator begin (void)
 Returns an iterator to the composite first element.
void clear ()
 Removes all elements.
void detach ()
 Decreases the number of references to this object. Destroy it if there are no more references to it.
bool empty () const
 Returns TRUE if the composite is empty.
iterator end (void)
 Returns a iterator to the composite last plus one element.
iterator erase (iterator it)
 Removes an element pointed by an iterator.
bool erase (T &elem)
 Removes a specific element.
bool erase (unsigned int i)
 Removes the i-th component.
T & operator[] (int i)
 Returns the i-th element.
reverse_iterator rbegin (void)
 The iterator to the first position in the TeComposite in reverse order.
int refCount ()
 Returns the number of references to this object.
reverse_iterator rend (void)
 The iterator to the last plus one position in the TeComposite in reverse order.
void reserve (int nelem)
 Reserves space for n elements (reserve is available for vectors).
size_t size () const
 Returns the size of the composite.

Protected Attributes

vector< T > components_
 a vector of components

Member Typedef Documentation

template<class T>
typedef vector<T>::const_iterator TeComposite< T >::const_iterator

Definition at line 94 of file TeComposite.h.

template<class T>
typedef vector<T>::iterator TeComposite< T >::iterator

Definition at line 93 of file TeComposite.h.

template<class T>
typedef vector<T>::reverse_iterator TeComposite< T >::reverse_iterator

Definition at line 163 of file TeComposite.h.


Member Function Documentation

template<class T>
void TeComposite< T >::add ( const T &  elem  )  [inline]

Definition at line 97 of file TeComposite.h.

Referenced by TeTable::add().

00098         { components_.push_back ( elem ); }

void TeCounted::attach (  )  [inline, inherited]

Definition at line 49 of file TeCounted.h.

00050                 { refCount_++; }

template<class T>
iterator TeComposite< T >::begin ( void   )  [inline]

Definition at line 151 of file TeComposite.h.

Referenced by buildData(), TeTin::copyBreaklines(), TeTin::edgeBegin(), TePolygonSetProperties::getPolygonRadius(), TeTin::insertBreaklinesPoints(), TePolygonSetProperties::rotatePolygon(), TeGraphNetwork::TeGraphNetwork(), TeTin::triangleBegin(), and TeTin::vertexBegin().

00152         {
00153                 return components_.begin();
00154         }

template<class T>
void TeComposite< T >::clear (  )  [inline]

Definition at line 131 of file TeComposite.h.

Referenced by TeTable::clear().

00132         {       components_.clear (); }

void TeCounted::detach (  )  [inline, inherited]

Definition at line 53 of file TeCounted.h.

00054                 { if ( --refCount_ == 0 )
00055                         delete this; }

template<class T>
bool TeComposite< T >::empty (  )  const [inline]

Definition at line 143 of file TeComposite.h.

00144         { return components_.empty(); }

template<class T>
iterator TeComposite< T >::end ( void   )  [inline]

Definition at line 157 of file TeComposite.h.

Referenced by buildData().

00158         {
00159                 return components_.end();
00160         }

template<class T>
iterator TeComposite< T >::erase ( iterator  it  )  [inline]

Definition at line 125 of file TeComposite.h.

00126         {
00127                 return components_.erase(it);
00128         }

template<class T>
bool TeComposite< T >::erase ( T &  elem  )  [inline]

Parameters:
elem the element to be removed

Definition at line 112 of file TeComposite.h.

00113         { 
00114                 typename vector<T>::iterator location = find(components_.begin(),components_.end(), elem);
00115                 if ( location != components_.end())
00116                 {
00117                         components_.erase(location);
00118                         return true;
00119                 }
00120                 else
00121                         return false; 
00122         }

template<class T>
bool TeComposite< T >::erase ( unsigned int  i  )  [inline]

Definition at line 101 of file TeComposite.h.

00102         {       
00103                 if ( components_.size() < i )
00104                         return false;
00105                 return ! ( components_.erase ( components_.begin() + i ) == components_.end() );
00106         }

template<class T>
T& TeComposite< T >::operator[] ( int  i  )  [inline]

Definition at line 139 of file TeComposite.h.

00140         { return components_[ i ]; }

template<class T>
reverse_iterator TeComposite< T >::rbegin ( void   )  [inline]

Definition at line 166 of file TeComposite.h.

00167         {
00168                 return components_.rbegin();
00169         }

int TeCounted::refCount (  )  [inline, inherited]

Definition at line 58 of file TeCounted.h.

00059         { return refCount_; }

template<class T>
reverse_iterator TeComposite< T >::rend ( void   )  [inline]

Definition at line 172 of file TeComposite.h.

00173         {
00174                 return components_.rend();
00175         }

template<class T>
void TeComposite< T >::reserve ( int  nelem  )  [inline]

Definition at line 147 of file TeComposite.h.

00148         { components_.reserve(nelem); }

template<class T>
size_t TeComposite< T >::size (  )  const [inline]

Definition at line 135 of file TeComposite.h.

Referenced by TeLine2D::isRing(), TeTable::size(), and TeExportQuerierToShapefile().

00136         { return components_.size(); }


Field Documentation

template<class T>
vector<T> TeComposite< T >::components_ [protected]

Definition at line 179 of file TeComposite.h.

Referenced by TeComposite< TeCoord2D >::add(), TeComposite< TeCoord2D >::begin(), TeComposite< TeCoord2D >::clear(), TeComposite< TeCoord2D >::empty(), TeComposite< TeCoord2D >::end(), TeComposite< TeCoord2D >::erase(), TeComposite< TeCoord2D >::operator[](), TeComposite< TeCoord2D >::rbegin(), TeComposite< TeCoord2D >::rend(), TeComposite< TeCoord2D >::reserve(), and TeComposite< TeCoord2D >::size().


The documentation for this class was generated from the following file:
Generated on Sun Jul 29 04:05:32 2012 for TerraLib - Development Source by  doxygen 1.5.3