acme
Foundational cross-platform layer of the ca2 framework
Toggle main menu visibility
Loading...
Searching...
No Matches
array_map.h
1
// Created by camilo on 2026-01-07 12:03 <3ThomasBorregaardSørensen!!
2
#pragma once
3
4
5
template
<
typename
ARRAY >
6
class
array_map :
7
public
ARRAY
8
{
9
public
:
10
11
using
KEY =
decltype
(&ARRAY::BASE_TYPE::key());
12
13
array_map() =
default
;
14
~array_map()
override
=
default
;
15
16
ARRAY::BASE_TYPE & find(
const
KEY & key)
17
{
18
for
(
auto
&
item
: *
this
)
19
{
20
if
(
item
.key() == key)
21
{
22
return
item
;
23
}
24
}
25
throw ::exception(error_not_found);
26
}
27
ARRAY::BASE_TYPE &operator[](
const
KEY &key)
28
{
29
for
(
auto
&
item
: *
this
)
30
{
31
if
(
item
.key() == key)
32
{
33
return
item
;
34
}
35
}
36
throw ::exception(error_not_found);
37
}
38
39
ARRAY::BASE_TYPE &ø(
const
KEY &key)
40
{
41
for
(
auto
&
item
: *
this
)
42
{
43
if
(
item
.key() == key)
44
{
45
return
item
;
46
}
47
}
48
this->add(key);
49
return
this->last();
50
}
51
};
52
53
54
55
template
<
typename
ARRAY>
56
class
pointer_array_map :
public
ARRAY
57
{
58
public
:
59
60
using
MAIN_TYPE =
typename
ARRAY::MAIN_TYPE;
61
using
KEY = ::std::invoke_result_t <
decltype
(&MAIN_TYPE::key),
const
MAIN_TYPE >;
62
63
pointer_array_map() =
default
;
64
~pointer_array_map()
override
=
default
;
65
66
MAIN_TYPE * find(
const
KEY &key)
67
{
68
for
(
auto
& pitem: *
this
)
69
{
70
if
(pitem->key() == key)
71
{
72
return
pitem;
73
}
74
}
75
//throw ::exception(error_not_found);
76
return
nullptr
;
77
}
78
MAIN_TYPE * operator[](
const
KEY &key)
79
{
80
for
(
auto
& pitem: *
this
)
81
{
82
if
(pitem->key() == key)
83
{
84
return
pitem;
85
}
86
}
87
//throw ::exception(error_not_found);
88
return
nullptr
;
89
}
90
91
MAIN_TYPE * &ø(
const
KEY &key)
92
{
93
for
(
auto
&pitem: *
this
)
94
{
95
if
(pitem->key() == key)
96
{
97
return
pitem;
98
}
99
}
100
101
this->add(::allocateø MAIN_TYPE(key));
102
103
return
this->last();
104
105
}
106
};
107
108
template
<
typename
TYPE>
109
using
pointer_map = ::pointer_array_map < ::pointer_array < TYPE > >;
110
111
item
Definition
item.h:93
prototype
collection
array_map.h
Generated by
1.17.0