-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIterable.hpp
More file actions
74 lines (55 loc) · 1.74 KB
/
Iterable.hpp
File metadata and controls
74 lines (55 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
** EPITECH PROJECT, 2025
** video-code
** File description:
** Iterable
*/
#pragma once
#include <nlohmann/json.hpp>
#include "input/IInput.hpp"
using json = nlohmann::json;
class IterableInput
{
public:
IterableInput(std::shared_ptr<IInput> input, json startTime, json endTime, int framerate)
: _input(input)
{
///< The start and end of time are floats, they represent seconds.
///< Start/Begin Index
if (startTime.is_null()) {
_beginIndex = 0;
}
else if (startTime < 0.0f) {
_beginIndex = startTime.get<float>() * framerate + static_cast<int>(input->size());
}
else {
_beginIndex = startTime.get<float>() * framerate;
}
///< End Index
if (endTime.is_null()) {
_endIndex = input->size();
}
else if (endTime < 0.0f) {
_endIndex = endTime.get<float>() * framerate + static_cast<int>(input->size());
}
else {
_endIndex = endTime.get<float>() * framerate;
}
_size = _endIndex - _beginIndex;
_beginIterator = input->begin() + _beginIndex;
_endIterator = input->begin() + _endIndex;
}
~IterableInput() = default;
std::vector<Frame>::iterator begin() { return _beginIterator; }
std::vector<Frame>::iterator end() { return _endIterator; }
IInput* operator->() { return _input.get(); }
size_t nbFrames() { return _size; };
private:
std::shared_ptr<IInput> _input;
size_t _beginIndex;
size_t _endIndex;
size_t _size;
///< Different begin and start than the size of the frames of the input
std::vector<Frame>::iterator _beginIterator;
std::vector<Frame>::iterator _endIterator;
};