acme
Foundational cross-platform layer of the ca2 framework
Toggle main menu visibility
Loading...
Searching...
No Matches
numeric_array_range.h
1
#pragma once
2
3
4
template
<
typename
A >
5
class
numeric_array_each
6
{
7
public
:
8
9
A & a;
10
inline
numeric_array_each(A & array):a(array){}
11
inline
numeric_array_each & operator += (
const
typename
A::BASE_TYPE & t)
12
{
13
for
(::collection::index i = 0; i < a.get_count(); i++)
14
{
15
a[i] += t;
16
}
17
return
*
this
;
18
}
19
inline
numeric_array_each & operator -= (
const
typename
A::BASE_TYPE & t)
20
{
21
for
(::collection::index i = 0; i < a.get_count(); i++)
22
{
23
a[i] -= t;
24
}
25
return
*
this
;
26
}
27
28
};
29
30
31
template
<
typename
A >
32
class
numeric_array_range
33
{
34
public
:
35
36
A & a;
37
::collection::index m_iBeg;
38
::collection::index m_iEnd;
39
40
inline
numeric_array_range(numeric_array_range && r):a(r.a),m_iBeg(a.m_iBeg),m_iEnd(a.m_iEnd) {}
41
42
inline
numeric_array_range(A & array, ::collection::index iStart, ::collection::index iCount = -1):a(array)
43
{
44
45
if
(iCount == 0)
46
return ;
47
48
::collection::index iEnd;
49
50
if
(iCount < 0)
51
{
52
53
iEnd = iCount + a.get_size();
54
55
}
56
else
57
{
58
59
iEnd = iCount - 1;
60
61
}
62
63
if
(iStart < 0)
64
{
65
66
iStart += a.get_size();
67
68
}
69
70
if
(iStart < 0)
71
{
72
73
iEnd += iStart;
74
75
iStart = 0;
76
77
}
78
79
if
(iStart < 0)
80
throw_exception(error_bad_argument);
81
82
if
(iStart >= a.get_count())
83
throw_exception(error_bad_argument);
84
85
if
(iEnd < 0)
86
throw_exception(error_bad_argument);
87
88
if
(iEnd >= a.get_count())
89
throw_exception(error_bad_argument);
90
91
m_iBeg = iStart;
92
93
m_iEnd = iEnd;
94
95
}
96
97
inline
numeric_array_range & operator += (
const
typename
A::BASE_TYPE & t)
98
{
99
for
(::collection::index i = m_iBeg; i <= m_iEnd; i++)
100
{
101
a[i] += t;
102
}
103
return
*
this
;
104
}
105
106
inline
numeric_array_range & operator -= (
const
typename
A::BASE_TYPE & t)
107
{
108
for
(::collection::index i = m_iBeg; i <= m_iEnd; i++)
109
{
110
a[i] -= t;
111
}
112
return
*
this
;
113
}
114
115
};
116
117
prototype
collection
numeric_array_range.h
Generated by
1.17.0