The Original CHomP Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
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>

Public Member Functions

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

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. More...
 
void deallocate ()
 Deallocates any memory previously allocated for this object. More...
 

Private Attributes

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

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 1626 of file pointset.h.

Constructor & Destructor Documentation

◆ tRectangle() [1/2]

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 1699 of file pointset.h.

1701{
1702 initialize (_left, _right, _dim);
1703 return;
1704} /* tRectangle::tRectangle */
void initialize(const coordtype *_left=NULL, const coordtype *_right=NULL, int _dim=0)
Initializes the internal data of an object of this class.
Definition: pointset.h:1677

◆ tRectangle() [2/2]

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

The copy constructor.

Definition at line 1707 of file pointset.h.

1708{
1709 initialize (r. left, r. right, r. dim);
1710 return;
1711} /* tRectangle::tRectangle */
int dim
The dimension of the space.
Definition: pointset.h:1651
const coordtype * left
A pointer to the left point (not allocated!).
Definition: pointset.h:1654
const coordtype * right
A pointer to the right point (not allocated!).
Definition: pointset.h:1657

◆ ~tRectangle()

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

The destructor.

Definition at line 1722 of file pointset.h.

1731{
1732 deallocate ();
1733 return;
1734} /* tRectangle::~tRectangle */
void deallocate()
Deallocates any memory previously allocated for this object.
Definition: pointset.h:1722

Member Function Documentation

◆ deallocate()

template<class coordtype >
void chomp::homology::tRectangle< coordtype >::deallocate
private

Deallocates any memory previously allocated for this object.

Definition at line 1722 of file pointset.h.

1723{
1724 if (point)
1725 delete [] point;
1726 return;
1727} /* tRectangle::deallocate */
coordtype * point
The coordinates of a created point.
Definition: pointset.h:1660

◆ get()

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 1746 of file pointset.h.

1747{
1748 // if this is the first point, check if the rectangle is nonempty
1749 if (firstpoint)
1750 {
1751 firstpoint = 0;
1752 for (int i = 0; i < dim; ++ i)
1753 if (left [i] >= right [i])
1754 return NULL;
1755 return point;
1756 }
1757
1758 // compute the next point of the rectangle
1759 int cur = 0;
1760 while ((cur < dim) && (++ (point [cur]) >= right [cur]))
1761 {
1762 point [cur] = left [cur];
1763 ++ cur;
1764 }
1765
1766 // if the iterator has run out of points, return NULL
1767 if (cur >= dim)
1768 {
1769 firstpoint = 1;
1770 return NULL;
1771 }
1772
1773 // return the point's coordinates
1774 return point;
1775
1776} /* tRectangle::get */
int firstpoint
Should the 0 pointer be returned after the last point?
Definition: pointset.h:1663

◆ initialize()

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 1677 of file pointset.h.

1679{
1680 firstpoint = 0;
1681 left = _left;
1682 right = _right;
1683 dim = _dim;
1684 if (dim <= 0)
1685 {
1686 dim = 0;
1687 point = NULL;
1688 return;
1689 }
1690 point = new coordtype [dim];
1691 if (!point)
1692 throw "Can't allocate memory for a rectangle.";
1693 reset ();
1694
1695 return;
1696} /* tRectangle::initialize */
void reset()
Resets the current point to the first one in the range.
Definition: pointset.h:1737

◆ operator=()

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

The assignment operator.

Definition at line 1714 of file pointset.h.

1715{
1716 deallocate ();
1717 initialize (r. left, r. right, r. dim);
1718 return *this;
1719} /* tRectangle::operator = */

◆ reset()

template<class coordtype >
void chomp::homology::tRectangle< coordtype >::reset ( void  )

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

Definition at line 1737 of file pointset.h.

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

Member Data Documentation

◆ dim

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

The dimension of the space.

Definition at line 1651 of file pointset.h.

◆ firstpoint

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

Should the 0 pointer be returned after the last point?

Definition at line 1663 of file pointset.h.

◆ left

template<class coordtype >
const coordtype* chomp::homology::tRectangle< coordtype >::left
private

A pointer to the left point (not allocated!).

Definition at line 1654 of file pointset.h.

◆ point

template<class coordtype >
coordtype* chomp::homology::tRectangle< coordtype >::point
private

The coordinates of a created point.

Definition at line 1660 of file pointset.h.

◆ right

template<class coordtype >
const coordtype* chomp::homology::tRectangle< coordtype >::right
private

A pointer to the right point (not allocated!).

Definition at line 1657 of file pointset.h.


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