24template <
class RecordType,
unsigned int MaxItemCount>
48 typedef typename std::remove_reference<
decltype(((RecordType*)
nullptr)->id())>::type
IdType;
55 for (
auto& rec : *
this) {
66 for (
auto& rec : *
this) {
67 if (rec.isValid() && rec.id() ==
id) {
81 template <
class UnaryPredicate>
82 constexpr RecordType*
get(UnaryPredicate p) {
83 for (
auto& obj : *
this) {
101 template <
class ValueFunction>
102 constexpr RecordType*
getMin(ValueFunction getValue) {
103 RecordType* smallest =
get([](
auto rec) {
return rec.isValid(); });
105 if (smallest ==
nullptr) {
109 for (RecordType* obj = smallest + 1; obj !=
end(); obj++) {
110 if (!obj->isValid()) {
114 if (getValue(*obj) < getValue(*smallest)) {
129 RecordType* retval =
nullptr;
130 for (
auto& rec : *
this) {
131 if (!rec.isValid()) {
134 else if (rec.id() ==
id) {
139 if (retval !=
nullptr) {
152 constexpr RecordType*
add() {
153 for (
auto& rec : *
this) {
154 if (!rec.isValid()) {
169 retval->invalidate();
181 template <
class UnaryPredicate>
182 constexpr uint16_t
countIf(UnaryPredicate p) {
184 for (
auto& rec : *
this) {
194 return countIf([](
auto& rec) { rec.isValid(); });
200 constexpr bool full() {
return count() == MaxItemCount; }
A variable size storage utility for objects of type RecordType with absolute maximum MaxItemCount.
Definition: cs_Store.h:25
constexpr RecordType * getMin(ValueFunction getValue)
Returns a pointer to the element in the store which minimizes the value function val.
Definition: cs_Store.h:102
uint16_t size()
Definition: cs_Store.h:176
constexpr RecordType * get(UnaryPredicate p)
returns the first object obj in the store satisfying p(obj) == true.
Definition: cs_Store.h:82
std::remove_reference< decltype(((RecordType *) nullptr) ->id())>::type IdType
Identifies and simplifies the type returned by the id() method of RecordType.
Definition: cs_Store.h:48
constexpr uint16_t countIf(UnaryPredicate p)
returns number of elements that satisfy the predicate.
Definition: cs_Store.h:182
uint16_t _currentSize
Current maximal number of valid records.
Definition: cs_Store.h:32
constexpr uint16_t count()
returns number of valid elements.
Definition: cs_Store.h:193
constexpr bool full()
returns true if all elements are occupied and valid.
Definition: cs_Store.h:200
constexpr RecordType * addAtEnd()
increases size of the store if possible and returns the entry at the end(), after invalidating.
Definition: cs_Store.h:165
RecordType * getOrAdd(IdType id)
same as get, but will return pointer to an invalid element if such element exists,...
Definition: cs_Store.h:128
RecordType _records[MaxItemCount]
Definition: cs_Store.h:35
RecordType * begin()
Definition: cs_Store.h:37
constexpr RecordType * add()
returns a pointer to the first invalid record.
Definition: cs_Store.h:152
RecordType * end()
Definition: cs_Store.h:39
void clear()
invalidate all records.
Definition: cs_Store.h:53
constexpr RecordType * get(const IdType &id)
linear search for the first record which has id() == id.
Definition: cs_Store.h:65