TArray< T, align, size, step > Class Template Reference

This template defines simple array with variable length. More...

#include <Array.h>

Collaboration diagram for TArray< T, align, size, step >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

typedef int (__cdecl *cmp_fce)(const void *
 Sorting function sort two items func(a,b):.
 TArray (void)
 Constructor.
 ~TArray (void)
 Destructor.
 TArray (const TArray< T, align, size, step > &orig)
 Copy constructor.
void operator= (const TArray< T, align, size, step > &orig)
 fake assignment operator
DWORD GetItemSize (void) const
 Return size of one item in this array in bytes.
void Set (const TArray< T, align, size, step > &orig)
 Sets array with values from another array.
void Clear (void)
 Releases this list.
void ClearDeallocOff (void)
 Releases this list.
void ReserveSize (const DWORD &newSize)
 Resize array.
void ReSizeAndFill (const DWORD &newSize)
 Resize array and fill all its elements.
DWORD GetSize (void) const
 Returns number of items in list.
DWORD Size (void) const
 Returns number of items in list.
DWORD Count (void) const
 Returns number of items in list.
DWORD GetAllocatedSpace (void) const
 Returns number of allocated items.
void AddItem (const T &item)
 Add item at end of list.
void Insert (const T &item, const DWORD &index)
 Insert new item to specified index.
void RemoveItem (const DWORD &index)
 Remove item with given index from array.
void RemoveItemFast (const DWORD &index)
 Remove item with given index from array.
void RemoveLastItem (void)
 Remove last item in array.
GetItem (const DWORD &index) const
 Gets item on desired index.
T & GetItemRef (const DWORD &index)
 Gets reference to item on desired index.
const T & GetItemRef (const DWORD &index) const
 Gets reference to item on desired index.
T & operator[] (const DWORD &index)
 Gets reference to item on desired index.
const T & operator[] (const DWORD &index) const
 Gets reference to item on desired index.
GetLastItem (void) const
 Gets last item in array.
T & GetLastItemRef (void)
 Gets reference to last item in array.
const T & GetLastItemRef (void) const
 Gets reference to last item in array.
T * GetArray (void)
 Return pointer to array of items stored in this list!!!
const T * GetArray (void) const
 Return pointer to array of items stored in this list!!!
void Sort (cmp_fce func)
 Sort this list by given sorting function.
void Reverse (void)
 Reverse order of items in array.

Detailed Description

template<class T, unsigned int align = 4, unsigned int size = 5, unsigned int step = 5>
class TArray< T, align, size, step >

This template defines simple array with variable length.

This template should be only used for pointers and structures which are copy via standard copy constructor. Using this template for class with non-standard copy constructor may result into undefined behavior. Because memory is allocated inside this list via malloc(), objects are not aligned, thus only objects WITHOUT ALIGMENT requierment works correctly.

Inside class items are copied as memory block - NO operator=() .

While releasing list no destructor are called (inner array is destroy via free()) - all items must be destroyed manualy. Thus if item is pointer then parent object must go through entire list and call delete for any pointer if this pointer points on object type.

Assign this class is PROHIBITED via non-implemented copy constructor.

If item type is pointer then before deleting list all pointers must be released manually!!! For non-pointers type same method for destroying must be called for all items if it's required (e.g. type contains pointer to allocated memory).

Parameters for template are:

T typr align bytes align when array is allocated size initial size of array step number of items added while array is reallocated

Definition at line 50 of file Array.h.


Constructor & Destructor Documentation

template<class T, unsigned int align, unsigned int size, unsigned int step>
TArray< T, align, size, step >::TArray void   ) 
 

Constructor.

Definition at line 133 of file Array.h.

References TMemManager::new_align().

Here is the call graph for this function:

template<class T, unsigned int align, unsigned int size, unsigned int step>
TArray< T, align, size, step >::~TArray void   ) 
 

Destructor.

Release list. Do not release items in list, it must be released manually.

Definition at line 165 of file Array.h.

References TMemManager::free_align().

Here is the call graph for this function:

template<class T, unsigned int align, unsigned int size, unsigned int step>
TArray< T, align, size, step >::TArray const TArray< T, align, size, step > &  orig  ) 
 

Copy constructor.

Parameters:
orig [in] original array

Definition at line 149 of file Array.h.

References TArray< T, align, size, step >::alloc, TArray< T, align, size, step >::array, TArray< T, align, size, step >::count, TMemManager::new_align(), and TArray< T, align, size, step >::onestep.

Here is the call graph for this function:


Member Function Documentation

template<class T, unsigned int align, unsigned int size, unsigned int step>
void TArray< T, align, size, step >::AddItem const T &  item  ) 
 

Add item at end of list.

New item is created with copy of memory block.

Parameters:
item new item to add

Definition at line 266 of file Array.h.

References TArray< T, align, size, step >::ReserveSize().

Referenced by NSMeshes::TMeshCreator::CreateDeclarationArray(), NSXLoader::TXFrame::Export_XYZ(), NSXLoader::TXFrame::Export_XYZ_NXNYNZ(), NSXLoader::TXFrame::Export_XYZ_NXNYNZ_TUTV(), and NSXLoader::TXFrame::Export_XYZ_TUTV().

Here is the call graph for this function:

template<class T, unsigned int align, unsigned int size, unsigned int step>
void TArray< T, align, size, step >::Clear void   )  [inline]
 

Releases this list.

Only sets number of items to 0 - memory is still allocated only for one object! No destructors are called for object type!

Definition at line 197 of file Array.h.

References TMemManager::free_align(), and TMemManager::new_align().

Referenced by NSXLoader::TXFrame::Export_XYZ(), NSXLoader::TXFrame::Export_XYZ_NXNYNZ(), NSXLoader::TXFrame::Export_XYZ_NXNYNZ_TUTV(), NSXLoader::TXFrame::Export_XYZ_TUTV(), TRendererCreatorHelper::FindRenderersHW(), TRendererCreatorHelper::FindRenderersSW(), and TRendererCreatorHelper::FreeEnumerateRenderers().

Here is the call graph for this function:

template<class T, unsigned int align, unsigned int size, unsigned int step>
void TArray< T, align, size, step >::ClearDeallocOff void   )  [inline]
 

Releases this list.

Only sets number of items to 0.

After calling this method memory is allocated in the same way as before calling. From this reason method is more effective than Clear method.

Definition at line 214 of file Array.h.

template<class T, unsigned int align, unsigned int size, unsigned int step>
DWORD TArray< T, align, size, step >::Count void   )  const [inline]
 

Returns number of items in list.

Returns:
number of items in list

Definition at line 244 of file Array.h.

template<class T, unsigned int align, unsigned int size, unsigned int step>
DWORD TArray< T, align, size, step >::GetAllocatedSpace void   )  const [inline]
 

Returns number of allocated items.

Array contains preallocated items for newly added items

Returns:
number of allocated items

Definition at line 255 of file Array.h.

template<class T, unsigned int align, unsigned int size, unsigned int step>
const T * TArray< T, align, size, step >::GetArray void   )  const [inline]
 

Return pointer to array of items stored in this list!!!

Returns:
pointer to array stored in this list.

Definition at line 488 of file Array.h.

template<class T, unsigned int align, unsigned int size, unsigned int step>
T * TArray< T, align, size, step >::GetArray void   )  [inline]
 

Return pointer to array of items stored in this list!!!

Returns:
pointer to array stored in this list.

Definition at line 478 of file Array.h.

template<class T, unsigned int align, unsigned int size, unsigned int step>
T TArray< T, align, size, step >::GetItem const DWORD index  )  const [inline]
 

Gets item on desired index.

Creates new item with copy constructor!!! Please use GetItemRef() or operator=() for reference getting. Index must be in range <0,count-1>

Parameters:
index [in] index to list
Returns:
item on desired index

Definition at line 370 of file Array.h.

References DBGASSERT.

Referenced by TRendererCreatorHelper::FindRenderersHW(), and TRendererCreatorHelper::FindRenderersSW().

template<class T, unsigned int align, unsigned int size, unsigned int step>
const T & TArray< T, align, size, step >::GetItemRef const DWORD index  )  const [inline]
 

Gets reference to item on desired index.

Index must be in range <0,count-1>

Parameters:
index [in] index to list
Returns:
reference to item on desired index

Definition at line 400 of file Array.h.

References DBGASSERT.

template<class T, unsigned int align, unsigned int size, unsigned int step>
T & TArray< T, align, size, step >::GetItemRef const DWORD index  )  [inline]
 

Gets reference to item on desired index.

Index must be in range <0,count-1>

Parameters:
index [in] index to list
Returns:
reference to item on desired index

Definition at line 385 of file Array.h.

References DBGASSERT.

Referenced by NSXLoader::TXFrame::Export_XYZ(), NSXLoader::TXFrame::Export_XYZ_NXNYNZ(), NSXLoader::TXFrame::Export_XYZ_NXNYNZ_TUTV(), and NSXLoader::TXFrame::Export_XYZ_TUTV().

template<class T, unsigned int align, unsigned int size, unsigned int step>
DWORD TArray< T, align, size, step >::GetItemSize void   )  const [inline]
 

Return size of one item in this array in bytes.

Definition at line 124 of file Array.h.

template<class T, unsigned int align, unsigned int size, unsigned int step>
T TArray< T, align, size, step >::GetLastItem void   )  const [inline]
 

Gets last item in array.

Warning:
At least one item must be in array!

Definition at line 442 of file Array.h.

References DBGASSERT.

template<class T, unsigned int align, unsigned int size, unsigned int step>
const T & TArray< T, align, size, step >::GetLastItemRef void   )  const [inline]
 

Gets reference to last item in array.

Warning:
At least one item must be in array!

Definition at line 466 of file Array.h.

References DBGASSERT.

template<class T, unsigned int align, unsigned int size, unsigned int step>
T & TArray< T, align, size, step >::GetLastItemRef void   )  [inline]
 

Gets reference to last item in array.

Warning:
At least one item must be in array!

Definition at line 454 of file Array.h.

References DBGASSERT.

template<class T, unsigned int align, unsigned int size, unsigned int step>
DWORD TArray< T, align, size, step >::GetSize void   )  const [inline]
 

Returns number of items in list.

Returns:
number of items in list

Definition at line 224 of file Array.h.

Referenced by NSXLoader::TXFrame::Export_XYZ(), NSXLoader::TXFrame::Export_XYZ_NXNYNZ(), NSXLoader::TXFrame::Export_XYZ_NXNYNZ_TUTV(), NSXLoader::TXFrame::Export_XYZ_TUTV(), TRendererCreatorHelper::FindRenderersHW(), TRendererCreatorHelper::FindRenderersSW(), NSXLoader::TXBone::GetVerticesCount(), and NSMeshes::TMeshLoader::SaveMeshToFile().

template<class T, unsigned int align, unsigned int size, unsigned int step>
void TArray< T, align, size, step >::Insert const T &  item,
const DWORD index
 

Insert new item to specified index.

Index must be in range.

Parameters:
item [in] item inserted on specified index
index [in] index in valid range <0,count-1>

Definition at line 285 of file Array.h.

References DBGASSERT, and TArray< T, align, size, step >::ReserveSize().

Here is the call graph for this function:

template<class T, unsigned int align = 4, unsigned int size = 5, unsigned int step = 5>
typedef TArray< T, align, size, step >::int __cdecl *  cmp_fce  )  const
 

Sorting function sort two items func(a,b):.

	*		< 0		....	a < b
	*		= 0		....	a = b
	*		> 0		....	a > b
	*	

template<class T, unsigned int align = 4, unsigned int size = 5, unsigned int step = 5>
void TArray< T, align, size, step >::operator= const TArray< T, align, size, step > &  orig  ) 
 

fake assignment operator

template<class T, unsigned int align, unsigned int size, unsigned int step>
const T & TArray< T, align, size, step >::operator[] const DWORD index  )  const [inline]
 

Gets reference to item on desired index.

Index must be in range <0,count-1>

Parameters:
index [in] index to list
Returns:
reference to item on desired index

Definition at line 430 of file Array.h.

References DBGASSERT.

template<class T, unsigned int align, unsigned int size, unsigned int step>
T & TArray< T, align, size, step >::operator[] const DWORD index  )  [inline]
 

Gets reference to item on desired index.

Index must be in range <0,count-1>

Parameters:
index [in] index to list
Returns:
reference to item on desired index

Definition at line 415 of file Array.h.

References DBGASSERT.

template<class T, unsigned int align, unsigned int size, unsigned int step>
void TArray< T, align, size, step >::RemoveItem const DWORD index  ) 
 

Remove item with given index from array.

No destructor is called to item!!!

Parameters:
index [in] index of item - must be in range <0,count-1>!!!

Definition at line 312 of file Array.h.

References DBGASSERT.

template<class T, unsigned int align, unsigned int size, unsigned int step>
void TArray< T, align, size, step >::RemoveItemFast const DWORD index  ) 
 

Remove item with given index from array.

This methods change order of items in list!!! Last item is set to deleted item. No destructor is called to item!!!

Parameters:
index [in] index of item - must be in range <0, count - 1>

Definition at line 334 of file Array.h.

References DBGASSERT.

template<class T, unsigned int align, unsigned int size, unsigned int step>
void TArray< T, align, size, step >::RemoveLastItem void   )  [inline]
 

Remove last item in array.

No destructor is called to item!!!

Only decrease number of items, thus this method is very fast.

Definition at line 352 of file Array.h.

template<class T, unsigned int align, unsigned int size, unsigned int step>
void TArray< T, align, size, step >::ReserveSize const DWORD newSize  ) 
 

Resize array.

Number of elements stay unchanged. Only allocates space is changed. Original array items are copy to new array. If size in parameter is less than actual size than new size is set to actual size thus methods do nothing. Items are copy via memory - no copy constructor or operator= is used.

Parameters:
newSize [in] new size of array in number of items

Definition at line 520 of file Array.h.

References TMemManager::free_align(), and TMemManager::new_align().

Referenced by TArray< T, align, size, step >::AddItem(), NSXLoader::TXFrame::Export_XYZ(), NSXLoader::TXFrame::Export_XYZ_NXNYNZ(), NSXLoader::TXFrame::Export_XYZ_NXNYNZ_TUTV(), NSXLoader::TXFrame::Export_XYZ_TUTV(), and TArray< T, align, size, step >::Insert().

Here is the call graph for this function:

template<class T, unsigned int align, unsigned int size, unsigned int step>
void TArray< T, align, size, step >::ReSizeAndFill const DWORD newSize  ) 
 

Resize array and fill all its elements.

This method is useful for copying data from file into array as chunk of bytes. Original array items are copy to new array. Other items are set to random values.

If size in parameter is less than actual size than new size is set to actual size thus methods do nothing. Items are copy via memory - no copy constructor or operator= is used.

Parameters:
newSize [in] new size of array in number of items

Definition at line 546 of file Array.h.

References TMemManager::free_align(), and TMemManager::new_align().

Here is the call graph for this function:

template<class T, unsigned int align, unsigned int size, unsigned int step>
void TArray< T, align, size, step >::Reverse void   ) 
 

Reverse order of items in array.

Definition at line 572 of file Array.h.

References TMemManager::new_align().

Here is the call graph for this function:

template<class T, unsigned int align, unsigned int size, unsigned int step>
void TArray< T, align, size, step >::Set const TArray< T, align, size, step > &  orig  )  [inline]
 

Sets array with values from another array.

(Creates identical copy) Previous array is deallocated and new is allocated. Items are copy via memcpy function.

Parameters:
orig [in] original array

Definition at line 180 of file Array.h.

References TArray< T, align, size, step >::alloc, TArray< T, align, size, step >::array, TArray< T, align, size, step >::count, TMemManager::free_align(), TMemManager::new_align(), and TArray< T, align, size, step >::onestep.

Here is the call graph for this function:

template<class T, unsigned int align, unsigned int size, unsigned int step>
DWORD TArray< T, align, size, step >::Size void   )  const [inline]
 

Returns number of items in list.

Returns:
number of items in list

Definition at line 234 of file Array.h.

template<class T, unsigned int align, unsigned int size, unsigned int step>
void TArray< T, align, size, step >::Sort cmp_fce  func  )  [inline]
 

Sort this list by given sorting function.

Sorting function sort two items func(a,b):

*		< 0		....	a < b
*		= 0		....	a = b
*		> 0		....	a > b
*	

Parameters:
func sorting function

Definition at line 506 of file Array.h.


The documentation for this class was generated from the following file:
Generated on Wed Nov 28 22:41:35 2007 for Joy4D by  doxygen 1.4.6-NO