code::Dim2D< X > Class Template Reference

Inheritance diagram for code::Dim2D< X >:

code::Data2D< T3, T4, X > code::CartesianGrid2D code::Grid2D code::LatLonGrid code::DEM List of all members.

Detailed Description

template<class X>
class code::Dim2D< X >

A generic two-dimentional container, efficient enough for common use.

Like the Data::D classes, copies made from a Dim2D will share the same copy of the data used by the source Dim2D. If you want a private copy (so that changes in one won't show up in the other), use clone() instead of the assignment operator or copy constructor.

Some common speedups: to initialize the grid, rather than using

    for (int i=0; i<rows; ++i)
      for (int j=0; j<cols; ++j)
         var[i][j] = Constants::MissingData;
    
Use
    var.fill (Constants::MissingData);
    

Also to walk through a grid, instead of using

    for (int i=0; i<rows; ++i)
      for (int j=0; j<cols; ++j)
         sum += var[i][j];
    
it's faster to use
    for (vartype::const_iterator it=var.begin(), end=var.end(); it!=end; ++it)
       sum += *it;
    

Author:
: Charles Kerr
Version:
:
Id
code_DimensionedData.h,v 1.44 2009/06/02 20:17:37 lakshman Exp


Public Types

typedef __normal_iterator< X > iterator
typedef __normal_iterator<
const X > 
const_iterator

Public Member Functions

iterator begin ()
iterator end ()
iterator get_iterator (size_t row, size_t col)
const_iterator begin () const
const_iterator end () const
const_iterator get_iterator (size_t row, size_t col) const
 Dim2D ()
 Creates a 0x0 grid.
 Dim2D (size_t x, size_t y, const X &value=X())
 Create an X x Y grid filled with copies of `value'.
 Dim2D (size_t x, size_t y, const X **values)
 Create an X x Y grid filled with a copy of `values'.
virtual ~Dim2D ()
 This class is meant to be subclassed.
Dim2D clone () const
 Create a completely separate copy of this 2d.
Dim2D< X > & operator= (const Dim2D< X > &source)
 Make `this' share source's data.
X & cell_ref (size_t row, size_t col)
 Deprecated alternative to dim2d[row][col].
const X & cell_ref (size_t row, size_t col) const
 Deprecated alternative to dim2d[row][col].
get_val (size_t row, size_t col) const
 Return a copy of the element in the specified coordinate.
void set_val (size_t row, size_t col, const X &value)
 Slightly more efficient form of dim2d[row][col] = value.
X * operator[] (size_t row)
const X * operator[] (size_t row) const
void get_1d_bounds (size_t row, X *&setme_begin, X *&setme_end)
void get_1d_bounds (size_t row, const X *&setme_begin, const X *&setme_end) const
void push_back (const X *begin, const X *end)
 Add a row of elements.
void push_back (const std::vector< X > &v)
 Add a row of elements.
void replace_1d (size_t row, const X *first, const X *last)
 Overwrite a 'row' of elements.
void replace_1d (int row, const std::vector< X > &v)
 Overwrite a 'row' of elements.
void replace_2d (const Dim2D< X > &d)
 Overwrite the entire 2D.
void set_2d (size_t x, size_t y, const X **values)
 Repopulate the grid as an X x Y grid with a copy of `values'.
void fill (const X &val)
 Set the entire grid to a value.
void fill (const X &val, size_t row_begin, size_t row_end, size_t col_begin, size_t col_end)
 Fill a 2D range with the specified value.
void clear ()
 resets this object to a 0x0 matrix
void reserve (size_t rows, size_t cols)
 ensure enough memory is allocated to populate an ROW x COL matrix.
void resize (size_t rows, size_t cols, const X &value=X())
 resizes to a ROW x COL grid and sets each cell to `value'
void replace (const X &old_value, const X &new_value)
 replace every instance of old_value with new_value
size_t size_d () const
 number of rows.
size_t size_d (size_t row) const
 number of columns.
int dim_x () const
 Number of rows.
int dim_y () const
 Number of cols.
Coord size () const

Protected Member Functions

virtual void shallow_copy (const Dim2D< X > &source)
virtual void deep_copy (const Dim2D< X > &source)

Protected Attributes

InitSmartPtr< Impl > _impl
 The array of 1D types that is held.

Classes

class  __normal_iterator
class  Coord
 Dimension type for Dim2D. More...
struct  Impl


Member Typedef Documentation

template<class X>
typedef __normal_iterator<const X> code::Dim2D< X >::const_iterator

template<class X>
typedef __normal_iterator<X> code::Dim2D< X >::iterator


Constructor & Destructor Documentation

template<class X>
code::Dim2D< X >::Dim2D (  )  [inline]

Creates a 0x0 grid.

Use push_back() to fill this in.

template<class X>
code::Dim2D< X >::Dim2D ( size_t  x,
size_t  y,
const X &  value = X() 
) [inline]

Create an X x Y grid filled with copies of `value'.

template<class X>
code::Dim2D< X >::Dim2D ( size_t  x,
size_t  y,
const X **  values 
) [inline]

Create an X x Y grid filled with a copy of `values'.

template<class X>
virtual code::Dim2D< X >::~Dim2D (  )  [inline, virtual]

This class is meant to be subclassed.


Member Function Documentation

template<class X>
const_iterator code::Dim2D< X >::begin (  )  const [inline]

template<class X>
iterator code::Dim2D< X >::begin (  )  [inline]

template<class X>
const X& code::Dim2D< X >::cell_ref ( size_t  row,
size_t  col 
) const [inline]

Deprecated alternative to dim2d[row][col].

template<class X>
X& code::Dim2D< X >::cell_ref ( size_t  row,
size_t  col 
) [inline]

Deprecated alternative to dim2d[row][col].

template<class X>
void code::Dim2D< X >::clear (  )  [inline]

resets this object to a 0x0 matrix

template<class X>
Dim2D code::Dim2D< X >::clone (  )  const [inline]

Create a completely separate copy of this 2d.

To create a copy that shares this data, use operator=

Reimplemented in code::CartesianGrid2D, code::Data2D< T3, T4, X >, code::Grid2D, code::Image< T >, code::LatLonGrid, code::Data2D< code::Angle, code::Angle, float >, code::Data2D< code::Length, code::Length, float >, code::Data2D< code::DLLH, code::DLLH, float >, code::Image< float >, and code::Image< int >.

template<class X>
virtual void code::Dim2D< X >::deep_copy ( const Dim2D< X > &  source  )  [inline, protected, virtual]

template<class X>
int code::Dim2D< X >::dim_x (  )  const [inline]

Number of rows.

Reimplemented in code::Image< T >, code::Image< float >, and code::Image< int >.

template<class X>
int code::Dim2D< X >::dim_y (  )  const [inline]

Number of cols.

Reimplemented in code::Image< T >, code::Image< float >, and code::Image< int >.

template<class X>
const_iterator code::Dim2D< X >::end (  )  const [inline]

template<class X>
iterator code::Dim2D< X >::end (  )  [inline]

template<class X>
void code::Dim2D< X >::fill ( const X &  val,
size_t  row_begin,
size_t  row_end,
size_t  col_begin,
size_t  col_end 
) [inline]

Fill a 2D range with the specified value.

Equivalent, but more efficient, form of "for (i=ibegin; i<iend; ++i) for (j=jbegin; j<jend; ++j) d[i][j]=val;"

template<class X>
void code::Dim2D< X >::fill ( const X &  val  )  [inline]

Set the entire grid to a value.

template<class X>
void code::Dim2D< X >::get_1d_bounds ( size_t  row,
const X *&  setme_begin,
const X *&  setme_end 
) const [inline]

template<class X>
void code::Dim2D< X >::get_1d_bounds ( size_t  row,
X *&  setme_begin,
X *&  setme_end 
) [inline]

template<class X>
const_iterator code::Dim2D< X >::get_iterator ( size_t  row,
size_t  col 
) const [inline]

template<class X>
iterator code::Dim2D< X >::get_iterator ( size_t  row,
size_t  col 
) [inline]

template<class X>
X code::Dim2D< X >::get_val ( size_t  row,
size_t  col 
) const [inline]

Return a copy of the element in the specified coordinate.

template<class X>
Dim2D<X>& code::Dim2D< X >::operator= ( const Dim2D< X > &  source  )  [inline]

Make `this' share source's data.

To create a copy that doesn't share data, use clone()

Reimplemented in code::Data2D< T3, T4, X >, code::Data2D< code::Angle, code::Angle, float >, code::Data2D< code::Length, code::Length, float >, and code::Data2D< code::DLLH, code::DLLH, float >.

template<class X>
const X* code::Dim2D< X >::operator[] ( size_t  row  )  const [inline]

template<class X>
X* code::Dim2D< X >::operator[] ( size_t  row  )  [inline]

template<class X>
void code::Dim2D< X >::push_back ( const std::vector< X > &  v  )  [inline]

Add a row of elements.

template<class X>
void code::Dim2D< X >::push_back ( const X *  begin,
const X *  end 
) [inline]

Add a row of elements.

template<class X>
void code::Dim2D< X >::replace ( const X &  old_value,
const X &  new_value 
) [inline]

replace every instance of old_value with new_value

template<class X>
void code::Dim2D< X >::replace_1d ( int  row,
const std::vector< X > &  v 
) [inline]

Overwrite a 'row' of elements.

The number of new and old elements must match.

template<class X>
void code::Dim2D< X >::replace_1d ( size_t  row,
const X *  first,
const X *  last 
) [inline]

Overwrite a 'row' of elements.

The number of old and new elements must match.

template<class X>
void code::Dim2D< X >::replace_2d ( const Dim2D< X > &  d  )  [inline]

Overwrite the entire 2D.

This copies the elements from d, rather than sharing them. If you want to share them, use the assignment operator instead.

template<class X>
void code::Dim2D< X >::reserve ( size_t  rows,
size_t  cols 
) [inline]

ensure enough memory is allocated to populate an ROW x COL matrix.

template<class X>
void code::Dim2D< X >::resize ( size_t  rows,
size_t  cols,
const X &  value = X() 
) [inline]

resizes to a ROW x COL grid and sets each cell to `value'

template<class X>
void code::Dim2D< X >::set_2d ( size_t  x,
size_t  y,
const X **  values 
) [inline]

Repopulate the grid as an X x Y grid with a copy of `values'.

template<class X>
void code::Dim2D< X >::set_val ( size_t  row,
size_t  col,
const X &  value 
) [inline]

Slightly more efficient form of dim2d[row][col] = value.

template<class X>
virtual void code::Dim2D< X >::shallow_copy ( const Dim2D< X > &  source  )  [inline, protected, virtual]

template<class X>
class Coord code::Dim2D< X >::size (  )  const [inline]

Reimplemented in code::CartesianGrid2D, code::Grid2D, and code::LatLonGrid.

template<class X>
size_t code::Dim2D< X >::size_d ( size_t  row  )  const [inline]

number of columns.

template<class X>
size_t code::Dim2D< X >::size_d (  )  const [inline]

number of rows.


Member Data Documentation

template<class X>
InitSmartPtr< Impl > code::Dim2D< X >::_impl [protected]

The array of 1D types that is held.


Generated on Fri May 4 13:40:11 2012 for WDSS-IIw2 by  doxygen 1.4.7