Public Member Functions | Private Member Functions | Private Attributes

chomp::homology::tRectangle< coordtype > Class Template Reference

This class can be used for iterating a rectangular set of points, given its left and right bound. More...

#include <pointset.h>

List of all members.

Public Member Functions

 tRectangle (const coordtype *_left=NULL, const coordtype *_right=NULL, int _dim=0)
 The only possible constructor for new objects.
 tRectangle (const tRectangle< coordtype > &r)
 The copy constructor.
tRectangleoperator= (const tRectangle< coordtype > &r)
 The assignment operator.
 ~tRectangle ()
 The destructor.
const coordtype * get ()
 Returns the next point in the recatngle.
void reset ()
 Resets the current point to the first one in the range.

Private Member Functions

void initialize (const coordtype *_left=NULL, const coordtype *_right=NULL, int _dim=0)
 Initializes the internal data of an object of this class.
void deallocate ()
 Deallocates any memory previously allocated for this object.

Private Attributes

int dim
 The dimension of the space.
const coordtype * left
 A pointer to the left point (not allocated!).
const coordtype * right
 A pointer to the right point (not allocated!).
coordtype * point
 The coordinates of a created point.
int firstpoint
 Should the 0 pointer be returned after the last point?

Detailed Description

template<class coordtype>
class chomp::homology::tRectangle< coordtype >

This class can be used for iterating a rectangular set of points, given its left and right bound.

The source points must exist all the time you use this structure for these points, because they are not copied, only the addresses of their coordinate tables are stored. Example: "rectangle ([0,0], [2,2], 2)" represents a set of four points: [0,0], [0,1], [1,0] and [1,1].

Definition at line 1581 of file pointset.h.


Constructor & Destructor Documentation

template<class coordtype>
chomp::homology::tRectangle< coordtype >::tRectangle ( const coordtype *  _left = NULL,
const coordtype *  _right = NULL,
int  _dim = 0 
)

The only possible constructor for new objects.

Definition at line 1654 of file pointset.h.

References chomp::homology::tRectangle< coordtype >::initialize().

{
        initialize (_left, _right, _dim);
        return;
} /* tRectangle::tRectangle */

template<class coordtype>
chomp::homology::tRectangle< coordtype >::tRectangle ( const tRectangle< coordtype > &  r  ) 
template<class coordtype >
chomp::homology::tRectangle< coordtype >::~tRectangle< coordtype > (  ) 

The destructor.


Member Function Documentation

template<class coordtype >
void chomp::homology::tRectangle< coordtype >::deallocate (  )  [private]

Deallocates any memory previously allocated for this object.

Definition at line 1677 of file pointset.h.

References chomp::homology::tRectangle< coordtype >::point.

Referenced by chomp::homology::tRectangle< coordtype >::operator=().

{
        if (point)
                delete [] point;
        return;
} /* tRectangle::deallocate */

template<class coordtype >
const coordtype * chomp::homology::tRectangle< coordtype >::get (  ) 

Returns the next point in the recatngle.

If no more points are available then returns 0 and rewinds to the first point.

Definition at line 1701 of file pointset.h.

References chomp::homology::tRectangle< coordtype >::dim, chomp::homology::tRectangle< coordtype >::firstpoint, chomp::homology::tRectangle< coordtype >::left, chomp::homology::tRectangle< coordtype >::point, and chomp::homology::tRectangle< coordtype >::right.

{
        // if this is the first point, check if the rectangle is nonempty
        if (firstpoint)
        {
                firstpoint = 0;
                for (int i = 0; i < dim; ++ i)
                        if (left [i] >= right [i])
                                return NULL;
                return point;
        }

        // compute the next point of the rectangle
        int cur = 0;
        while ((cur < dim) && (++ (point [cur]) >= right [cur]))
        {
                point [cur] = left [cur];
                ++ cur;
        }

        // if the iterator has run out of points, return NULL
        if (cur >= dim)
        {
                firstpoint = 1;
                return NULL;
        }

        // return the point's coordinates
        return point;

} /* tRectangle::get */

template<class coordtype>
void chomp::homology::tRectangle< coordtype >::initialize ( const coordtype *  _left = NULL,
const coordtype *  _right = NULL,
int  _dim = 0 
) [private]

Initializes the internal data of an object of this class.

Definition at line 1632 of file pointset.h.

References chomp::homology::tRectangle< coordtype >::dim, chomp::homology::tRectangle< coordtype >::firstpoint, chomp::homology::tRectangle< coordtype >::left, chomp::homology::tRectangle< coordtype >::point, chomp::homology::tRectangle< coordtype >::reset(), and chomp::homology::tRectangle< coordtype >::right.

Referenced by chomp::homology::tRectangle< coordtype >::operator=(), and chomp::homology::tRectangle< coordtype >::tRectangle().

{
        firstpoint = 0;
        left = _left;
        right = _right;
        dim = _dim;
        if (dim <= 0)
        {
                dim = 0;
                point = NULL;
                return;
        }
        point = new coordtype [dim];
        if (!point)
                throw "Can't allocate memory for a rectangle.";
        reset ();

        return;
} /* tRectangle::initialize */

template<class coordtype>
tRectangle< coordtype > & chomp::homology::tRectangle< coordtype >::operator= ( const tRectangle< coordtype > &  r  ) 
template<class coordtype >
void chomp::homology::tRectangle< coordtype >::reset ( void   ) 

Resets the current point to the first one in the range.

Definition at line 1692 of file pointset.h.

References chomp::homology::tRectangle< coordtype >::dim, chomp::homology::tRectangle< coordtype >::firstpoint, chomp::homology::tRectangle< coordtype >::left, and chomp::homology::tRectangle< coordtype >::point.

Referenced by chomp::homology::tRectangle< coordtype >::initialize().

{
        for (int i = 0; i < dim; ++ i)
                point [i] = left [i];
        firstpoint = 1;
        return;
} /* tRectangle::reset */


Member Data Documentation

template<class coordtype>
int chomp::homology::tRectangle< coordtype >::dim [private]
template<class coordtype>
int chomp::homology::tRectangle< coordtype >::firstpoint [private]

Should the 0 pointer be returned after the last point?

Definition at line 1618 of file pointset.h.

Referenced by chomp::homology::tRectangle< coordtype >::get(), chomp::homology::tRectangle< coordtype >::initialize(), and chomp::homology::tRectangle< coordtype >::reset().

template<class coordtype>
const coordtype* chomp::homology::tRectangle< coordtype >::left [private]
template<class coordtype>
coordtype* chomp::homology::tRectangle< coordtype >::point [private]
template<class coordtype>
const coordtype* chomp::homology::tRectangle< coordtype >::right [private]

The documentation for this class was generated from the following file: