2
2
3
3
#pragma once
4
4
5
+ #include < algorithm>
5
6
#include < array>
6
7
7
8
#include " curve/container/iterator.h"
@@ -38,8 +39,8 @@ class Array : event::EventEntity {
38
39
* @param notifier Function to call when this curve changes.
39
40
* @param default_vals Default values for the array elements.
40
41
*/
41
- Array (const std::shared_ptr<event::EventLoop> &loop,
42
- size_t id,
42
+ Array (const std::shared_ptr<event::EventLoop> &loop = nullptr ,
43
+ size_t id = 0 ,
43
44
const std::string &idstr = " " ,
44
45
const EventEntity::single_change_notifier ¬ifier = nullptr ,
45
46
const std::array<T, Size > &default_vals = {}) :
@@ -105,6 +106,14 @@ class Array : event::EventEntity {
105
106
*/
106
107
std::pair<time::time_t , T> next_frame (const time::time_t &t, const index_t index) const ;
107
108
109
+
110
+ void set_insert_range (const time::time_t &t, auto begin_it, auto end_it) {
111
+ ENSURE (std::distance (begin_it, end_it) <= Size ,
112
+ " trying to insert more values than there are postions: max allowed = " << Size );
113
+ index_t i = 0 ;
114
+ std::for_each (begin_it, end_it, [&](const T &val) { this ->set_insert (t, i++, val); });
115
+ }
116
+
108
117
/* *
109
118
* Insert a new keyframe value at time t.
110
119
*
@@ -114,7 +123,7 @@ class Array : event::EventEntity {
114
123
* @param index Index of the array element.
115
124
* @param value Keyframe value.
116
125
*/
117
- void set_insert (const time::time_t &t, const index_t index, T value);
126
+ void set_insert (const time::time_t &t, const index_t index, const T & value);
118
127
119
128
/* *
120
129
* Insert a new keyframe value at time t. Erase all other keyframes with elem->time > t.
@@ -123,7 +132,7 @@ class Array : event::EventEntity {
123
132
* @param index Index of the array element.
124
133
* @param value Keyframe value.
125
134
*/
126
- void set_last (const time::time_t &t, const index_t index, T value);
135
+ void set_last (const time::time_t &t, const index_t index, const T & value);
127
136
128
137
/* *
129
138
* Replace all keyframes at elem->time == t with a new keyframe value.
@@ -132,7 +141,7 @@ class Array : event::EventEntity {
132
141
* @param index Index of the array element.
133
142
* @param value Keyframe value.
134
143
*/
135
- void set_replace (const time::time_t &t, const index_t index, T value);
144
+ void set_replace (const time::time_t &t, const index_t index, const T & value);
136
145
137
146
/* *
138
147
* Copy keyframes from another container to this container.
@@ -321,7 +330,7 @@ consteval size_t Array<T, Size>::size() const {
321
330
template <typename T, size_t Size >
322
331
void Array<T, Size >::set_insert(const time::time_t &t,
323
332
const index_t index,
324
- T value) {
333
+ const T & value) {
325
334
// find elem_ptr in container to get the last keyframe with time <= t
326
335
auto hint = this ->last_elements [index ];
327
336
auto e = this ->containers .at (index ).insert_after (Keyframe{t, value}, hint);
@@ -335,7 +344,7 @@ void Array<T, Size>::set_insert(const time::time_t &t,
335
344
template <typename T, size_t Size >
336
345
void Array<T, Size >::set_last(const time::time_t &t,
337
346
const index_t index,
338
- T value) {
347
+ const T & value) {
339
348
// find elem_ptr in container to get the last keyframe with time <= t
340
349
auto hint = this ->last_elements [index ];
341
350
auto e = this ->containers .at (index ).last (t, hint);
@@ -360,7 +369,7 @@ void Array<T, Size>::set_last(const time::time_t &t,
360
369
template <typename T, size_t Size >
361
370
void Array<T, Size >::set_replace(const time::time_t &t,
362
371
const index_t index,
363
- T value) {
372
+ const T & value) {
364
373
// find elem_ptr in container to get the last keyframe with time <= t
365
374
auto hint = this ->last_elements [index ];
366
375
auto e = this ->containers .at (index ).insert_overwrite (Keyframe{t, value}, hint);
0 commit comments