-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataContainer.h
More file actions
42 lines (34 loc) · 1.1 KB
/
DataContainer.h
File metadata and controls
42 lines (34 loc) · 1.1 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
#pragma once
#include <functional>
#include <DataStream.h>
template<typename DataT, typename DataHolderT=std::vector<DataT>>
class Container : public DataStream<DataT>, public Emitter<DataT> {
public:
Container( const DataHolderT& data) :
DataStream<DataT>(this),
holder(std::make_shared<DataHolderT>(data)),
i(0)
{}
Container( const Container& other) :
DataStream<DataT>(this),
holder(other.holder),
i(0)
{}
Container( const Container&& other) :
DataStream<DataT>(this),
holder(other.holder),
i(0)
{}
virtual const DataT EmitNext() override { return (*holder)[i++]; }
virtual bool Ended() override { return i == holder->size(); }
virtual void Reset() override { i = 0; }
virtual std::unique_ptr<Emitter<DataT>> Copy() const { return std::make_unique<Container>(*this); }
virtual std::unique_ptr<Emitter<DataT>> CopyState() const {
auto copy = std::make_unique<Container>(*this);
copy->i = i;
return copy;
}
private:
std::shared_ptr<const DataHolderT> holder;
int i;
};