acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
array_2d.h
1// Created by camilo on 2023-07-08 17:02 <3ThomasBorregaardSorensen!!
2#pragma once
3
4
5template < class TYPE, class ARG_TYPE >
6class row :
7 public range < TYPE * >
8{
9public:
10
11
12 using BASE_RANGE = range < TYPE * >;
13
14
15 // FISC - Flaw in some compiler
16
17 //inline operator TYPE * () { return this->m_begin; }
18 //inline operator const TYPE * () const { return this->m_begin; }
19
20
21 inline TYPE & operator[](::collection::index i) { return this->m_begin[i]; }
22 inline const TYPE & operator [](::collection::index i) const { return this->m_begin[i]; }
23
24
25 row(TYPE * pbegin, TYPE * pend):BASE_RANGE(pbegin, pend) {}
26
27};
28
29
30template < class TYPE, class ARG_TYPE, typename TYPED, typename MEMORY, ::enum_type t_etypeContainer >
31class array_2d :
32 virtual public ::base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer >
33{
34public:
35
36
37 using BASE_ARRAY = ::base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer >;
38 using row = ::row < TYPE, ARG_TYPE >;
39
40
41 // FISC - Flaw in some compiler
42
43//protected:
44//
45//
46// using BASE_ARRAY::operator TYPE *;
47// using BASE_ARRAY::operator const TYPE *;
48//
49//
50//public:
51
52
53 ::i64 m_iWidth;
54
55
56 ::collection::count set_size(::collection::count w, ::collection::count h)
57 {
58
59 m_iWidth = w;
60
61 return BASE_ARRAY::set_size(w * h);
62
63 }
64
65 ::collection::count set_size(::i32_size size)
66 {
67
68 return this->set_size(size.cx, size.cy);
69
70 }
71
72
73 ::i32_size size() const
74 {
75
76 return { m_iWidth, BASE_ARRAY::size() / m_iWidth };
77
78 }
79
80
81 row operator [](::collection::index iRowIndex)
82 {
83
84 auto prowdata = this->begin() + m_iWidth * iRowIndex;
85
86 return { prowdata, prowdata + m_iWidth };
87
88 }
89
90
91 const row operator [](::collection::index iRowIndex) const
92 {
93
94 auto prowdata = this->begin() + m_iWidth * iRowIndex;
95
96 return { prowdata, prowdata + m_iWidth };
97
98 }
99
100
101 TYPE & element_at(::collection::index x, ::collection::index y)
102 {
103
104 return this->m_begin + m_iWidth * y + x;
105
106 }
107
108
109 const TYPE & element_at(::collection::index x, ::collection::index y) const
110 {
111
112 return this->m_begin + m_iWidth * y + x;
113
114 }
115
116
117 void set_at(::collection::index x, ::collection::index y, ARG_TYPE t)
118 {
119
120 element_at(x, y) = t;
121
122 }
123
124};
125
126
127using i32_array_2d = ::array_2d < ::i32, ::i32 >;
128
129
130using f32_array_2d = ::array_2d < ::f32, ::f32 >;
131
132
133using f64_array_2d = ::array_2d < ::f64, ::f64 >;
134
135
136
137
138
Definition array_2d.h:33