Point Class Reference

A portable version of Be's BPoint class. More...

#include <Point.h>

Inheritance diagram for Point:

Inheritance graph
[legend]
List of all members.

Public Types

typedef float TupleItemType
 typedef for our item type; used by the binary operators below

Public Member Functions

 Point ()
 Default constructor, sets the point to be (0.0f, 0.0f).
 Point (float ax, float ay)
 Constructor where you specify the initial value of the point.
 Point (const Point &rhs)
 Copy Constructor.
virtual ~Point ()
 Destructor.
float & x ()
 convenience method to set the x value of this Point
float x () const
 convenience method to get the x value of this Point
float & y ()
 convenience method to set the y value of this Point
float y () const
 convenience method to get the y value of this Point
void Set (float ax, float ay)
 Sets a new value for the point.
void ConstrainTo (Point topLeft, Point bottomRight)
 If the point is outside the rectangle specified by the two arguments, it will be moved horizontally and/or vertically until it falls inside the rectangle.
void PrintToStream () const
 Print debug information about the point to stdout.
virtual bool IsFixedSize () const
 Part of the Flattenable interface: Returns true.
virtual uint32 TypeCode () const
 Part of the Flattenable interface: Returns B_POINT_TYPE.
virtual uint32 FlattenedSize () const
 Part of the Flattenable interface: 2*sizeof(float).
uint32 CalculateChecksum () const
 Returns a 32-bit checksum for this object.
virtual void Flatten (uint8 *buffer) const
 Copies this point into an endian-neutral flattened buffer.
virtual status_t Unflatten (const uint8 *buffer, uint32 size)
 Restores this point from an endian-neutral flattened buffer.
virtual bool AllowsTypeCode (uint32 code) const
 Should return true iff a buffer with uint32 (code) can be used to reconstruct this object's state.
status_t CopyTo (Flattenable &copyTo) const
 Causes (copyTo)'s state to set from this Flattenable, if possible.
status_t CopyFrom (const Flattenable &copyFrom)
 Causes our state to be set from (copyFrom)'s state, if possible.
status_t FlattenToByteBuffer (ByteBuffer &outBuf) const
 Convenience method.
Ref< ByteBufferFlattenToByteBuffer () const
 Convenience method.
status_t UnflattenFromByteBuffer (const ByteBuffer &buf)
 Convenience method.
status_t FlattenToDataIO (DataIO &outputStream, bool addSizeHeader) const
 Convenience method.
status_t UnflattenFromDataIO (DataIO &inputStream, int32 optReadSize, uint32 optMaxReadSize=MUSCLE_NO_LIMIT)
 Convenience method.
Tupleoperator+= (const Tuple &rhs)
 Adds all indices in (rhs) to their counterparts in this object.
Tupleoperator+= (const float &value)
 Adds (value) to all indices in this object.
Tupleoperator-= (const Tuple &rhs)
 Subtracts all indices in (rhs) from their counterparts in this object.
Tupleoperator-= (const float &value)
 Subtracts (value) from all indices in this object.
Tupleoperator *= (const Tuple &rhs)
 Multiplies all indices in this object by their counterparts in this (rhs).
Tupleoperator *= (const float &value)
 Multiplies all indices in this object by (value).
Tupleoperator/= (const Tuple &rhs)
 Divides all indices in this object by their counterparts in this object (rhs).
Tupleoperator/= (const float &value)
 Divides all indices in this object by (value).
Tupleoperator<<= (int numPlaces)
 Shifts the values of the indices left (numPlaces) spaces.
Tupleoperator>>= (int numPlaces)
 Shifts the values of the indices right (numPlaces) spaces.
bool operator== (const Tuple &rhs) const
 Returns true iff all indices in this object are equal to their counterparts in (rhs).
bool operator!= (const Tuple &rhs) const
 Returns true iff any indices in this object are not equal to their counterparts in (rhs).
bool operator< (const Tuple &rhs) const
 Comparison Operator.
bool operator> (const Tuple &rhs) const
 Comparison Operator.
bool operator<= (const Tuple &rhs) const
 Comparison Operator.
bool operator>= (const Tuple &rhs) const
 Comparison Operator.
float & operator[] (uint32 i)
 Read-write array operator (not bounds-checked).
const float & operator[] (uint32 i) const
 Read-only array operator (not bounds-checked).
float DotProduct (const Tuple &rhs) const
 Returns the dot-product of (this) and (rhs).
int IndexOf (const float &value) const
 Returns the index of the first value equal to (value), or -1 if not found.
int LastIndexOf (const float &value) const
 Returns the index of the last value equal to (value), or -1 if not found.
int Compare (const Tuple &rhs) const
 Works like strcmp(), only for a tuple.
float GetMaximumValue () const
 Returns the minimum value from amongst all the items in the tuple.
float GetMinimumValue () const
 Returns the maximum value from amongst all the items in the tuple.
float GetLengthSquared () const
 Multiplies each value by itself, and returns the sum.
uint32 GetNumInstancesOf (const float &value) const
 Returns the number of times (value) appears in this tuple.
bool MatchSubrange (const Tuple &matchAgainst, uint32 startIndex=0, uint32 endIndex=MUSCLE_NO_LIMIT) const
 Returns true iff the all index values in the given range match those of the given Tuple.
void FillSubrange (floatvalue, uint32 startIndex=0, uint32 endIndex=MUSCLE_NO_LIMIT)
 Sets all items in the range [startIndex, endIndex] (inclusive) to (value).
uint32 Replace (const float &replaceMe, const float &withMe, uint32 startIndex=0, uint32 endIndex=MUSCLE_NO_LIMIT)
 Replaces all instances of (replaceMe) with (withMe).
void CopySubrange (const Tuple &rhs, uint32 startIndex=0, uint32 endIndex=MUSCLE_NO_LIMIT)
 Sets all items in the range [startIndex, endIndex] (inclusive) to be equal to their counterparts in (rhs).
void Reset ()
 Sets all our items to their zero/default values.
const uint32 GetNumItemsInTuple () const
 How many items in this tuple.
float * GetItemPointer (uint32 which)
 Convenience method -- returns a pointer to the nth item in our tuple.
const float * GetItemPointer (uint32 which) const
 Convenience method -- returns a read-only pointer to the nth item in our tuple.

Static Public Member Functions

static void WriteData (uint8 *outBuf, uint32 *writeOffset, const void *copyFrom, uint32 blockSize)
 Convenience method for writing data into a byte buffer.
static status_t ReadData (const uint8 *inBuf, uint32 inputBufferBytes, uint32 *readOffset, void *copyTo, uint32 blockSize)
 Convenience method for safely reading bytes from a byte buffer.

Protected Member Functions

virtual status_t CopyFromImplementation (const Flattenable &copyFrom)
 Called by CopyFrom() and CopyTo().

Detailed Description

A portable version of Be's BPoint class.

Definition at line 23 of file Point.h.


Constructor & Destructor Documentation

Point::Point ( float  ax,
float  ay 
) [inline]

Constructor where you specify the initial value of the point.

Parameters:
ax Initial x position
ay Initial y position

Definition at line 33 of file Point.h.

References Set().


Member Function Documentation

void Point::Set ( float  ax,
float  ay 
) [inline]

Sets a new value for the point.

Parameters:
ax The new x value
ay The new y value

Definition at line 57 of file Point.h.

References x(), and y().

Referenced by Point().

void Point::ConstrainTo ( Point  topLeft,
Point  bottomRight 
) [inline]

If the point is outside the rectangle specified by the two arguments, it will be moved horizontally and/or vertically until it falls inside the rectangle.

Parameters:
topLeft Minimum values acceptable for x and y
bottomRight Maximum values acceptable for x and y

Definition at line 64 of file Point.h.

References x(), and y().

virtual void Point::Flatten ( uint8 *  buffer  )  const [inline, virtual]

Copies this point into an endian-neutral flattened buffer.

Parameters:
buffer Points to an array of at least FlattenedSize() bytes.

Implements Flattenable.

Definition at line 93 of file Point.h.

References x(), and y().

virtual status_t Point::Unflatten ( const uint8 *  buffer,
uint32  size 
) [inline, virtual]

Restores this point from an endian-neutral flattened buffer.

Parameters:
buffer Points to an array of (size) bytes
size The number of bytes (buffer) points to (should be at least FlattenedSize())
Returns:
B_NO_ERROR on success, B_ERROR on failure (size was too small)

Implements Flattenable.

Definition at line 105 of file Point.h.

References FlattenedSize(), x(), and y().

virtual bool Flattenable::AllowsTypeCode ( uint32  code  )  const [inline, virtual, inherited]

Should return true iff a buffer with uint32 (code) can be used to reconstruct this object's state.

Defaults implementation returns true iff (code) equals TypeCode() or B_RAW_DATA.

Parameters:
code A type code constant, e.g. B_RAW_TYPE or B_STRING_TYPE, or something custom.
Returns:
True iff this object can Unflatten from a buffer of the given type, false otherwise.

Reimplemented in ByteBuffer.

Definition at line 56 of file Flattenable.h.

References Flattenable::TypeCode().

Referenced by Flattenable::CopyFrom(), and Flattenable::CopyTo().

status_t Flattenable::CopyTo ( Flattenable copyTo  )  const [inline, inherited]

Causes (copyTo)'s state to set from this Flattenable, if possible.

Default implementation is not very efficient, since it has to flatten this object into a byte buffer, and then unflatten the bytes back into (copyTo). However, you can override CopyFromImplementation() to provide a more efficient implementation when possible.

Parameters:
copyTo Object to make into the equivalent of this object. (copyTo) May be any subclass of Flattenable.
Returns:
B_NO_ERROR on success, or B_ERROR on failure (typecode mismatch, out-of-memory, etc)

Definition at line 76 of file Flattenable.h.

References Flattenable::AllowsTypeCode(), Flattenable::CopyFromImplementation(), and Flattenable::TypeCode().

status_t Flattenable::CopyFrom ( const Flattenable copyFrom  )  [inline, inherited]

Causes our state to be set from (copyFrom)'s state, if possible.

Default implementation is not very efficient, since it has to flatten (copyFrom) into a byte buffer, and then unflatten the bytes back into (this). However, you can override CopyFromImplementation() to provide a more efficient implementation when possible.

Parameters:
copyFrom Object to read from to set the state of this object. (copyFrom) may be any subclass of Flattenable.
Returns:
B_NO_ERROR on success, or B_ERROR on failure (typecode mismatch, out-of-memory, etc)

Definition at line 91 of file Flattenable.h.

References Flattenable::AllowsTypeCode(), Flattenable::CopyFromImplementation(), and Flattenable::TypeCode().

static void Flattenable::WriteData ( uint8 *  outBuf,
uint32 *  writeOffset,
const void *  copyFrom,
uint32  blockSize 
) [inline, static, inherited]

Convenience method for writing data into a byte buffer.

Writes data consecutively into a byte buffer. The output buffer is assumed to be large enough to hold the data.

Parameters:
outBuf Flat buffer to write to
writeOffset Offset into buffer to write to. Incremented by (blockSize) on success.
copyFrom memory location to copy bytes from
blockSize number of bytes to copy

Definition at line 105 of file Flattenable.h.

static status_t Flattenable::ReadData ( const uint8 *  inBuf,
uint32  inputBufferBytes,
uint32 *  readOffset,
void *  copyTo,
uint32  blockSize 
) [inline, static, inherited]

Convenience method for safely reading bytes from a byte buffer.

(Checks to avoid buffer overrun problems)

Parameters:
inBuf Flat buffer to read bytes from
inputBufferBytes total size of the input buffer
readOffset Offset into buffer to read from. Incremented by (blockSize) on success.
copyTo memory location to copy bytes to
blockSize number of bytes to copy
Returns:
B_NO_ERROR if the data was successfully read, B_ERROR if the data couldn't be read (because the buffer wasn't large enough)

Definition at line 120 of file Flattenable.h.

status_t Flattenable::FlattenToByteBuffer ( ByteBuffer outBuf  )  const [inherited]

Convenience method.

Flattens this object into the supplied ByteBuffer object.

Parameters:
outBuf the ByteBuffer to dump our flattened bytes into.
Returns:
B_NO_ERROR on success, or B_ERROR on failure (out of memory?)

Ref<ByteBuffer> Flattenable::FlattenToByteBuffer (  )  const [inherited]

Convenience method.

Allocated an appropriately sized ByteBuffer object via GetByteBufferFromPool(), Flatten()s this object into the byte buffer, and returns the resulting ByteBufferRef. Returns a NULL reference on failure (out of memory?)

status_t Flattenable::UnflattenFromByteBuffer ( const ByteBuffer buf  )  [inherited]

Convenience method.

Unflattens this object from the supplied ByteBuffer object.

Parameters:
buf The ByteBuffer to unflatten from.
Returns:
B_NO_ERROR on success, or B_ERROR on failure.

status_t Flattenable::FlattenToDataIO ( DataIO outputStream,
bool  addSizeHeader 
) const [inherited]

Convenience method.

Flattens this object to the given DataIO object.

Parameters:
outputStream The DataIO object to send our flattened data to. This DataIO should be in blocking I/O mode; this method won't work reliably if used with non-blocking I/O.
addSizeHeader If true, we will prefix our flattened data with a four-byte little-endian uint32 indicating the number of bytes of flattened data that we are going to write. If false, then the buffer size will need to be determined by the reading code by some other means.
Returns:
B_NO_ERROR on success, or B_ERROR on failure.

status_t Flattenable::UnflattenFromDataIO ( DataIO inputStream,
int32  optReadSize,
uint32  optMaxReadSize = MUSCLE_NO_LIMIT 
) [inherited]

Convenience method.

Flattens this object from the given DataIO object.

Parameters:
inputStream the DataIO object to read data from. This DataIO should be in blocking I/O mode; this method won't work reliably if used with non-blocking I/O.
optReadSize If non-negative, this many bytes will be read from (inputStream). If set to -1, then the first four bytes read from the stream will be used to determine how many more bytes should be read from the stream. If the data was created with Flatten(io, true), then set this parameter to -1.
optMaxReadSize An optional value indicating the largest number of bytes that should be read by this call. This value is only used if (optReadSize) is negative. If (optReadSize) is negative and the first four bytes read from (inputStream) are greater than this value, then this method will return B_ERROR instead of trying to read that many bytes. This can be useful if you want to prevent the possibility of huge buffers being allocated due to malicious or corrupted size headers. Defaults to MUSCLE_NO_LIMIT, meaning that no size limit is enforced.
Returns:
B_NO_ERROR if the data was correctly read, or B_ERROR otherwise.

virtual status_t Flattenable::CopyFromImplementation ( const Flattenable copyFrom  )  [protected, virtual, inherited]

Called by CopyFrom() and CopyTo().

Sets our state from (copyFrom) if possible. Default implementation is not very efficient, since it has to flatten (copyFrom) into a byte buffer, and then unflatten the bytes back into (this). However, you can override CopyFromImplementation() to provide a more efficient implementation when possible.

Parameters:
copyFrom Object to set this object's state from. May be any subclass of Flattenable, but it has been pre-screened by CopyFrom() (or CopyTo()) to make sure it's not (*this), and that we allow its type code.
Returns:
B_NO_ERROR on success, or B_ERROR on failure (out-of-memory, etc)

Reimplemented in Message, and ByteBuffer.

Referenced by Flattenable::CopyFrom(), and Flattenable::CopyTo().

Tuple& Tuple< NumItems, float >::operator<<= ( int  numPlaces  )  [inline, inherited]

Shifts the values of the indices left (numPlaces) spaces.

Default values (typically zero) are filled in on the right.

Definition at line 68 of file Tuple.h.

Tuple& Tuple< NumItems, float >::operator>>= ( int  numPlaces  )  [inline, inherited]

Shifts the values of the indices right (numPlaces) spaces.

Default values (typically zero) are filled in on the left.

Definition at line 71 of file Tuple.h.

bool Tuple< NumItems, float >::operator< ( const Tuple< 2, float > &  rhs  )  const [inline, inherited]

Comparison Operator.

Returns true if this tuple comes before (rhs) lexically.

Definition at line 80 of file Tuple.h.

References Tuple< NumItems, ItemType >::_items.

bool Tuple< NumItems, float >::operator> ( const Tuple< 2, float > &  rhs  )  const [inline, inherited]

Comparison Operator.

Returns true if this tuple comes after (rhs) lexically.

Definition at line 83 of file Tuple.h.

References Tuple< NumItems, ItemType >::_items.

bool Tuple< NumItems, float >::operator<= ( const Tuple< 2, float > &  rhs  )  const [inline, inherited]

Comparison Operator.

Returns true if the two tuple are equal, or this tuple comes before (rhs) lexically.

Definition at line 86 of file Tuple.h.

bool Tuple< NumItems, float >::operator>= ( const Tuple< 2, float > &  rhs  )  const [inline, inherited]

Comparison Operator.

Returns true if the two tuple are equal, or this tuple comes after (rhs) lexically.

Definition at line 89 of file Tuple.h.

bool Tuple< NumItems, float >::MatchSubrange ( const Tuple< 2, float > &  matchAgainst,
uint32  startIndex = 0,
uint32  endIndex = MUSCLE_NO_LIMIT 
) const [inline, inherited]

Returns true iff the all index values in the given range match those of the given Tuple.

Parameters:
matchAgainst The Tuple to do a partial index value match against
startIndex The first index to match on. Defaults to zero.
endIndex The last index to match on, plus one. Values that are greater than the number of items in the tuple will be capped to (the number of items in the tuple). Defaults to MUSCLE_NO_LIMIT.
Returns:
true iff all indices in the range are equal, else false.

Definition at line 128 of file Tuple.h.

References Tuple< NumItems, ItemType >::_items.

void Tuple< NumItems, float >::FillSubrange ( float   value,
uint32  startIndex = 0,
uint32  endIndex = MUSCLE_NO_LIMIT 
) [inline, inherited]

Sets all items in the range [startIndex, endIndex] (inclusive) to (value).

Parameters:
value The value to set items to.
startIndex The first index to set. Defaults to zero.
endIndex The last index to set, plus one. Values that are greater than the number of items in the tuple will be capped to (the number of items in the tuple). Defaults to MUSCLE_NO_LIMIT.
Returns:
true iff all indices in the range are equal, else false.

Definition at line 142 of file Tuple.h.

uint32 Tuple< NumItems, float >::Replace ( const float &  replaceMe,
const float &  withMe,
uint32  startIndex = 0,
uint32  endIndex = MUSCLE_NO_LIMIT 
) [inline, inherited]

Replaces all instances of (replaceMe) with (withMe).

Parameters:
replaceMe Value to be replaced
withMe Value to replace instances of (replaceMe) with.
startIndex The first index to process. Defaults to zero.
endIndex The last index to process, plus one. Values that are greater than the number of items in the tuple will be capped to (the number of items in the tuple). Defaults to MUSCLE_NO_LIMIT.
Returns:
The number of substitutions that were made.

Definition at line 156 of file Tuple.h.

void Tuple< NumItems, float >::CopySubrange ( const Tuple< 2, float > &  rhs,
uint32  startIndex = 0,
uint32  endIndex = MUSCLE_NO_LIMIT 
) [inline, inherited]

Sets all items in the range [startIndex, endIndex] (inclusive) to be equal to their counterparts in (rhs).

Parameters:
rhs The tuple to copy from.
startIndex The first index to set. Defaults to zero.
endIndex The last index to set, plus one. Values that are greater than the number of items in the tuple will be capped to (the number of items in the tuple). Defaults to MUSCLE_NO_LIMIT.
Returns:
true iff all indices in the range are equal, else false.

Definition at line 178 of file Tuple.h.


The documentation for this class was generated from the following file:
Generated on Thu Jun 5 17:48:20 2008 for MUSCLE by  doxygen 1.5.1