CrystalSpace

Public API Reference

CS::SubRectangles Class Reference

A class managing allocations of sub-rectangles. More...

#include <csgeom/subrec.h>

Inheritance diagram for CS::SubRectangles:

List of all members.

Classes

class  SubRect
 Sub-rectangle. More...

Public Member Functions

virtual SubRectAlloc (int w, int h, csRect &rect)
 Allocate a new rectangle.
virtual void Clear ()
 Free all rectangles in this region.
void Dump (const char *tag=0)
 For debugging: dump all free rectangles.
void Dump (iObjectRegistry *object_reg, const char *tag=0)
 For debugging: dump all free rectangles.
csRect GetMinimumRectangle () const
 Return the rectangle to which the allocator can be shrunk to at most.
const csRectGetRectangle () const
 Get the rectangle for this region.
virtual bool Grow (int newWidth, int newHeight)
 Increase the size of the region.
bool IsEmpty () const
 Returns whether the allocator is empty (ie no rectangles have been allocated at all or all allocated rectangles have been reclaimed).
virtual bool PlaceInto (const SubRectangles *rectangles, SubRect *subRect, csHash< SubRect *, csConstPtrKey< SubRect > > *newRectangles=0)
 Place the subrectangles of another allocator into a rectangle allocated from this allocator.
void Reclaim (SubRect *subrect)
 Reclaim a subrectangle, meaning, the space occupied by the subrect can be reused by subsequent Alloc() calls.
virtual bool Shrink (int newWidth, int newHeight)
 Decrease the size of the region.
 SubRectangles (const csRect &region)
 Allocate a new empty region with the given size.
virtual ~SubRectangles ()
 Remove this region and sub-regions.

Protected Member Functions

void Split (SubRect *subRect, SubRect::SplitType split, int splitPos)
 Helper function to split a node.

Protected Attributes

csArray< SubRect * > leaves
 Leaves of the region tree.
csRect region
 Dimensions of this region.
SubRectroot
 Root of the region tree.

Detailed Description

A class managing allocations of sub-rectangles.

i.e. this class represents a rectangular region from which a client can allocate smaller rectangles until the region is full.

Remarks:
works best if bigger rectangles are inserted first.

Definition at line 48 of file subrec.h.


Constructor & Destructor Documentation

CS::SubRectangles::SubRectangles ( const csRect region  ) 

Allocate a new empty region with the given size.

virtual CS::SubRectangles::~SubRectangles (  )  [virtual]

Remove this region and sub-regions.


Member Function Documentation

virtual SubRect* CS::SubRectangles::Alloc ( int  w,
int  h,
csRect rect 
) [virtual]

Allocate a new rectangle.

Returns 0 if there is no room

Reimplemented in CS::SubRectanglesCompact.

virtual void CS::SubRectangles::Clear (  )  [virtual]

Free all rectangles in this region.

Reimplemented in CS::SubRectanglesCompact.

void CS::SubRectangles::Dump ( const char *  tag = 0  ) 

For debugging: dump all free rectangles.

Works the same as Dump(iObjectRegistry*, const char*), although has no effect Crystal Space was not compiled in debug mode.

void CS::SubRectangles::Dump ( iObjectRegistry object_reg,
const char *  tag = 0 
)

For debugging: dump all free rectangles.

Parameters:
object_reg Object registry. Used to obtain some required plugins.
tag String appended to the filename dumped to.
csRect CS::SubRectangles::GetMinimumRectangle (  )  const [inline]

Return the rectangle to which the allocator can be shrunk to at most.

Definition at line 218 of file subrec.h.

const csRect& CS::SubRectangles::GetRectangle (  )  const [inline]

Get the rectangle for this region.

Definition at line 176 of file subrec.h.

virtual bool CS::SubRectangles::Grow ( int  newWidth,
int  newHeight 
) [virtual]

Increase the size of the region.

You can only grow upwards.

bool CS::SubRectangles::IsEmpty (  )  const [inline]

Returns whether the allocator is empty (ie no rectangles have been allocated at all or all allocated rectangles have been reclaimed).

Definition at line 187 of file subrec.h.

virtual bool CS::SubRectangles::PlaceInto ( const SubRectangles rectangles,
SubRect subRect,
csHash< SubRect *, csConstPtrKey< SubRect > > *  newRectangles = 0 
) [virtual]

Place the subrectangles of another allocator into a rectangle allocated from this allocator.

void CS::SubRectangles::Reclaim ( SubRect subrect  ) 

Reclaim a subrectangle, meaning, the space occupied by the subrect can be reused by subsequent Alloc() calls.

virtual bool CS::SubRectangles::Shrink ( int  newWidth,
int  newHeight 
) [virtual]

Decrease the size of the region.

If the region can't be shrunk to the desired size because some already allocated subrectangles would be cut off false is returned. You can check if shrinking to a size is possible by comparing the result of GetMinimumRectangle() with the desired size.

void CS::SubRectangles::Split ( SubRect subRect,
SubRect::SplitType  split,
int  splitPos 
) [protected]

Helper function to split a node.


Member Data Documentation

Leaves of the region tree.

Definition at line 144 of file subrec.h.

Dimensions of this region.

Definition at line 130 of file subrec.h.

Root of the region tree.

Definition at line 132 of file subrec.h.


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

Generated for Crystal Space 2.1 by doxygen 1.6.1