Deluge Firmware 1.3.0
Build date: 2026.11.28
Loading...
Searching...
No Matches
param_node_vector.h
1/*
2 * Copyright © 2017-2023 Synthstrom Audible Limited
3 *
4 * This file is part of The Synthstrom Audible Deluge Firmware.
5 *
6 * The Synthstrom Audible Deluge Firmware is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU General Public License as published by the Free Software Foundation,
8 * either version 3 of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * See the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along with this program.
15 * If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#pragma once
19
20#include "util/container/array/ordered_resizeable_array.h"
21#include <utility>
22
23class ParamNode;
24
25class ParamNodeVector : public OrderedResizeableArrayWith32bitKey {
26public:
27 ParamNodeVector();
28
29 ParamNode* getElement(int32_t index);
30 ParamNode* getFirst();
31 ParamNode* getLast();
32};
33
40class LazyParamNodeVector {
41public:
42 LazyParamNodeVector() = default;
43 ~LazyParamNodeVector() { empty(); }
44 LazyParamNodeVector(LazyParamNodeVector const&) = delete;
45 LazyParamNodeVector& operator=(LazyParamNodeVector const&) = delete;
46
48 void init() { vector_ = nullptr; }
50 void empty();
52 bool cloneFrom(LazyParamNodeVector const* other);
54 Error beenCloned();
55 void swapStateWith(LazyParamNodeVector* other) { std::swap(vector_, other->vector_); }
56
58 ParamNodeVector* get() { return vector_; }
59
60 int32_t getNumElements() const { return vector_ ? vector_->getNumElements() : 0; }
61 ParamNode* getElement(int32_t index) { return vector_ ? vector_->getElement(index) : nullptr; }
62 ParamNode* getFirst() { return vector_ ? vector_->getFirst() : nullptr; }
63 ParamNode* getLast() { return vector_ ? vector_->getLast() : nullptr; }
64 void* getElementAddress(int32_t index) { return vector_->getElementAddress(index); }
65
66 int32_t search(int32_t key, int32_t comparison, int32_t rangeBegin = 0) {
67 return vector_ ? vector_->search(key, comparison, rangeBegin) : rangeBegin + comparison;
68 }
69 int32_t search(int32_t key, int32_t comparison, int32_t rangeBegin, int32_t rangeEnd) {
70 return vector_ ? vector_->search(key, comparison, rangeBegin, rangeEnd) : rangeBegin + comparison;
71 }
72 int32_t searchExact(int32_t key) { return vector_ ? vector_->searchExact(key) : -1; }
73 void searchDual(int32_t const* __restrict__ searchTerms, int32_t* __restrict__ resultingIndexes);
74 void testSequentiality(char const* errorCode) {
75 if (vector_) {
76 vector_->testSequentiality(errorCode);
77 }
78 }
79
80 Error insertAtIndex(int32_t i, int32_t numToInsert = 1, void* thingNotToStealFrom = nullptr);
81 int32_t insertAtKey(int32_t key, bool isDefinitelyLast = false);
82 bool ensureEnoughSpaceAllocated(int32_t numAdditionalElementsNeeded);
83 void deleteAtIndex(int32_t i, int32_t numToDelete = 1, bool mayShortenMemoryAfter = true);
84
85 void shiftHorizontal(int32_t amount, int32_t effectiveLength) {
86 if (vector_) {
87 vector_->shiftHorizontal(amount, effectiveLength);
88 }
89 }
90 bool generateRepeats(int32_t wrapPoint, int32_t endPos) {
91 return vector_ ? vector_->generateRepeats(wrapPoint, endPos) : true;
92 }
93
94private:
95 bool allocate();
96 void freeIfEmpty();
97
98 ParamNodeVector* vector_ = nullptr;
99};
Definition param_node_vector.h:40
void init()
Forget the current vector without freeing it - for when this object was memcpy'd from another one.
Definition param_node_vector.h:48
bool cloneFrom(LazyParamNodeVector const *other)
Like ResizeableArray::cloneFrom(), this assumes there's currently nothing here to free.
Definition param_node_vector.cpp:70
ParamNodeVector * get()
The underlying vector, or nullptr if there are no nodes.
Definition param_node_vector.h:58
Error beenCloned()
Call after this object was memcpy'd from another one, to give it its own copy of the nodes.
Definition param_node_vector.cpp:83
void empty()
Free the vector and all its nodes.
Definition param_node_vector.cpp:56
Definition param_node_vector.h:25
Definition param_node.h:23