Newton Dynamics  4.00
ndArray< T > Class Template Reference

Generic template vector. More...

Inheritance diagram for ndArray< T >:
ndClassAlloc ndOpenclBuffer< T >

Public Member Functions

 ndArray ()
 constructor, set count and capacity to zero, not memory is allocated.
 
 ndArray (ndInt32 count)
 constructor, set count and capacity, allocated space for count elements.
 
 ndArray (const ndArray &source)
 copy constructor, allocate and copy only m_size elements from source.
 
 ~ndArray ()
 deallocate all memory, dos not call destructor on any of th elements.
 
ndInt32 GetCount () const
 return the size of the array.
 
void SetCount (ndInt32 count)
 Set a new size. More...
 
void Resize (ndInt32 count)
 Set a new size. More...
 
ndInt32 GetCapacity () const
 return the capacity of the array.
 
T & operator[] (ndInt32 i)
 Get the i element for the array. More...
 
const T & operator[] (ndInt32 i) const
 Get the i element for the array. More...
 
void Swap (ndArray &other)
 Interchange all the information with other. More...
 
void PushBack (const T &element)
 Add element to the end of the buffer. More...
 
void RandomShuffle (ndInt32 count)
 Randomize the vector entries.
 
void ResetMembers ()
 set all member to 0. More...
 
void SetMembers (ndInt32 size, void *const memory)
 assign all members. More...
 
- Public Member Functions inherited from ndClassAlloc
 ndClassAlloc ()
 Empty default constructor.
 
 ~ndClassAlloc ()
 Empty.
 

Protected Attributes

T * m_array
 
ndInt32 m_size
 
ndInt32 m_capacity
 

Additional Inherited Members

- Static Public Member Functions inherited from ndClassAlloc
D_OPERATOR_NEW_AND_DELETE static D_CORE_API void * Malloc (size_t size)
 Generic allocation for any function subclass from ndClassAlloc.
 
static D_CORE_API void Free (void *const ptr)
 Generic destruction for any function subclass from ndClassAlloc.
 

Detailed Description

template<class T>
class ndArray< T >

Generic template vector.

note: this template vector is similar to std::vector but has some significant differences. therefore is not meant to be a replacement of the sdt::vector, it is simple a tool for this engine

Member Function Documentation

◆ operator[]() [1/2]

template<class T >
T & ndArray< T >::operator[] ( ndInt32  i)

Get the i element for the array.

behavior is undefined is i is larger of equal to the array size

◆ operator[]() [2/2]

template<class T >
const T & ndArray< T >::operator[] ( ndInt32  i) const

Get the i element for the array.

behavior is undefined is i is larger of equal to the array size

◆ PushBack()

template<class T >
void ndArray< T >::PushBack ( const T &  element)

Add element to the end of the buffer.

size is incremented by one, and the array is resized if it reaches max capacity

◆ ResetMembers()

template<class T >
void ndArray< T >::ResetMembers

set all member to 0.

useful for when making vectors of vectors (ex matrices)

◆ Resize()

template<class T >
void ndArray< T >::Resize ( ndInt32  count)

Set a new size.

the array resized to count, all the data is simply copied to the new array and old array is deleted.

◆ SetCount()

template<class T >
void ndArray< T >::SetCount ( ndInt32  count)

Set a new size.

if count is larger than m_size, the array resized by doubling its size, all the data is simply copied to the new array and old array is deleted.

◆ SetMembers()

template<class T >
void ndArray< T >::SetMembers ( ndInt32  size,
void *const  memory 
)

assign all members.

useful for when making vectors of vectors (ex matrices)

◆ Swap()

template<class T >
void ndArray< T >::Swap ( ndArray< T > &  other)

Interchange all the information with other.

other must be of the same type.