[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pbmserv-dev] Q: array of integers



A first attempt (open to improvement):

class MyArray2D:public ReadWriteIntList {
public:
	  MyArray2D(); // constructor

      int GetAt( int x, int y);
      void PutAt( int x, int y, int value );
      int Width();
      void SetWidth( int width );

protected:
      const char *Name(void) { return "MyArray2D"; };
private:
	int mWidth;
};

inline MyArray2D::MyArray2D() : mWidth(0)
{
};

inline int MyArray2D::Width()
{
	return mWidth;
};

inline void MyArray2D::SetWidth( int width )
{
	mWidth = width;
};

inline int MyArray2D::GetAt( int x, int y )
{
	return (*this)[ x + mWidth * y ];
}

inline void MyArray2D::PutAt( int x, int y, int value
)
{
	(*this)[ x + mWidth * y ] = value;
}

--- Douglas Zander <dzander@solaria.sol.net> wrote:
> On Wed, 31 Dec 2003, Richard Rognlie wrote:
> 
> > You can construct a 2d array from a 1d array...  
> say you want a
> > 6x8 matrix.  that's 48 elements.
> > 
> > build a 48 element ReadWriteintList
> > 
> > then access it as  array(x,y) ==>  array(8*x + y)
> > 
> 
>  That's what I thought of doing, I was just
> wondering if there was anything
> written up for a 2D or 3D integer board class.   I
> guess not.  Thanks.
> (I'm trying to read "lists.cpp" and my head is
> spinning :-)
> ( I was thinking of something like 
>  int value;
> 
>  value = GetAt(3,4);
> 
>  value = value + 1;
> 
>  PutAt(7,5,value);
> )
> 
> -- 
>  Douglas Zander 
> 
> 
> 
> To unsubscribe, send a message to esquire@gamerz.net
> with
> 	unsubscribe pbmserv-dev@gamerz.net
> as the BODY of the message.  The SUBJECT is ignored.
>