22
33#pragma once
44
5+ #include < algorithm>
56#include < array>
67
78#include " curve/container/iterator.h"
@@ -38,8 +39,8 @@ class Array : event::EventEntity {
3839 * @param notifier Function to call when this curve changes.
3940 * @param default_vals Default values for the array elements.
4041 */
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 ,
4344 const std::string &idstr = " " ,
4445 const EventEntity::single_change_notifier ¬ifier = nullptr ,
4546 const std::array<T, Size> &default_vals = {}) :
@@ -105,6 +106,14 @@ class Array : event::EventEntity {
105106 */
106107 std::pair<time::time_t , T> next_frame (const time::time_t &t, const index_t index) const ;
107108
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+
108117 /* *
109118 * Insert a new keyframe value at time t.
110119 *
@@ -114,7 +123,7 @@ class Array : event::EventEntity {
114123 * @param index Index of the array element.
115124 * @param value Keyframe value.
116125 */
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);
118127
119128 /* *
120129 * Insert a new keyframe value at time t. Erase all other keyframes with elem->time > t.
@@ -123,7 +132,7 @@ class Array : event::EventEntity {
123132 * @param index Index of the array element.
124133 * @param value Keyframe value.
125134 */
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);
127136
128137 /* *
129138 * Replace all keyframes at elem->time == t with a new keyframe value.
@@ -132,7 +141,7 @@ class Array : event::EventEntity {
132141 * @param index Index of the array element.
133142 * @param value Keyframe value.
134143 */
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);
136145
137146 /* *
138147 * Copy keyframes from another container to this container.
@@ -321,7 +330,7 @@ consteval size_t Array<T, Size>::size() const {
321330template <typename T, size_t Size>
322331void Array<T, Size>::set_insert(const time::time_t &t,
323332 const index_t index,
324- T value) {
333+ const T & value) {
325334 // find elem_ptr in container to get the last keyframe with time <= t
326335 auto hint = this ->last_elements [index];
327336 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,
335344template <typename T, size_t Size>
336345void Array<T, Size>::set_last(const time::time_t &t,
337346 const index_t index,
338- T value) {
347+ const T & value) {
339348 // find elem_ptr in container to get the last keyframe with time <= t
340349 auto hint = this ->last_elements [index];
341350 auto e = this ->containers .at (index).last (t, hint);
@@ -360,7 +369,7 @@ void Array<T, Size>::set_last(const time::time_t &t,
360369template <typename T, size_t Size>
361370void Array<T, Size>::set_replace(const time::time_t &t,
362371 const index_t index,
363- T value) {
372+ const T & value) {
364373 // find elem_ptr in container to get the last keyframe with time <= t
365374 auto hint = this ->last_elements [index];
366375 auto e = this ->containers .at (index).insert_overwrite (Keyframe{t, value}, hint);
0 commit comments