Newton Dynamics
4.00
ndFixSizeArray.h
1
/* Copyright (c) <2003-2022> <Julio Jerez, Newton Game Dynamics>
2
*
3
* This software is provided 'as-is', without any express or implied
4
* warranty. In no event will the authors be held liable for any damages
5
* arising from the use of this software.
6
*
7
* Permission is granted to anyone to use this software for any purpose,
8
* including commercial applications, and to alter it and redistribute it
9
* freely, subject to the following restrictions:
10
*
11
* 1. The origin of this software must not be misrepresented; you must not
12
* claim that you wrote the original software. If you use this software
13
* in a product, an acknowledgment in the product documentation would be
14
* appreciated but is not required.
15
*
16
* 2. Altered source versions must be plainly marked as such, and must not be
17
* misrepresented as being the original software.
18
*
19
* 3. This notice may not be removed or altered from any source distribution.
20
*/
21
22
#ifndef __ND_FIX_SIZE_ARRAY_H__
23
#define __ND_FIX_SIZE_ARRAY_H__
24
25
#include "ndCoreStdafx.h"
26
27
template
<
class
T, ndInt32 maxSize>
28
class
ndFixSizeArray
:
public
ndClassAlloc
29
{
30
public
:
31
ndFixSizeArray
();
32
33
ndInt32 GetCount()
const
;
34
void
SetCount(ndInt32 count);
35
36
ndInt32 GetCapacity()
const
;
37
38
T& operator[] (ndInt32 i);
39
const
T& operator[] (ndInt32 i)
const
;
40
41
void
PushBack(
const
T& element);
42
43
T m_array[maxSize];
44
ndInt32 m_count;
45
};
46
47
template
<
class
T, ndInt32 maxSize>
48
ndFixSizeArray<T, maxSize>::ndFixSizeArray
()
49
:
ndClassAlloc
()
50
,m_count(0)
51
{
52
}
53
54
template
<
class
T, ndInt32 maxSize>
55
ndInt32
ndFixSizeArray<T, maxSize>::GetCapacity
()
const
56
{
57
return
maxSize;
58
}
59
60
template
<
class
T, ndInt32 maxSize>
61
ndInt32
ndFixSizeArray<T, maxSize>::GetCount
()
const
62
{
63
return
m_count;
64
}
65
66
template
<
class
T, ndInt32 maxSize>
67
void
ndFixSizeArray<T, maxSize>::SetCount
(ndInt32 count)
68
{
69
m_count = (count < 0) ? 0 : ((count > maxSize) ? maxSize : count);
70
}
71
72
template
<
class
T, ndInt32 maxSize>
73
T&
ndFixSizeArray<T, maxSize>::operator[]
(ndInt32 i)
74
{
75
ndAssert(i >= 0);
76
ndAssert(i < maxSize);
77
return
m_array[i];
78
}
79
80
template
<
class
T, ndInt32 maxSize>
81
const
T&
ndFixSizeArray<T, maxSize>::operator[]
(ndInt32 i)
const
82
{
83
ndAssert(i >= 0);
84
ndAssert(i < maxSize);
85
return
m_array[i];
86
}
87
88
template
<
class
T, ndInt32 maxSize>
89
void
ndFixSizeArray<T, maxSize>::PushBack
(
const
T& element)
90
{
91
ndAssert(m_count <= maxSize);
92
(*this)[m_count] = element;
93
m_count++;
94
}
95
96
#endif
ndClassAlloc
Base class for providing memory allocation for all other engine classes.
Definition:
ndClassAlloc.h:30
ndFixSizeArray
Definition:
ndFixSizeArray.h:29
newton-dynamics
newton-4.00
sdk
dCore
ndFixSizeArray.h
Generated by
1.8.20