-
Notifications
You must be signed in to change notification settings - Fork 0
/
TA_Out.h
91 lines (78 loc) · 1.5 KB
/
TA_Out.h
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#ifndef __TA_OUT_H__
#define __TA_OUT_H__
#include <stdarg.h>
namespace TA
{
template<typename T = double>
class Out
{
public:
Out(int out_beg, int out_nb_element, const std::shared_ptr<T>& serial)
: out_beg_(out_beg)
{
for (int i = 0; i < out_nb_element; i++)
{
out_serial_.push_back(serial.get()[i]);
}
}
int nb_elements() const
{
return out_serial_.size();
}
int begin() const
{
return out_beg_;
}
T operator[](int idx) const
{
if (idx < out_beg_)
{
throw RangeException("[] idx out");
}
return out_serial_[idx - out_beg_];
}
private:
TA_Integer out_beg_;
std::vector<T> out_serial_;
};
template<typename T = double, int N = 1>
class Outs
{
public:
Outs(int out_beg, int out_nb_element, const std::shared_ptr<T>* const, ...)
: out_beg_(out_beg)
{
va_list arg_ptr;
va_start(arg_ptr, out_nb_element);
for (int i = 0; i < N; i++)
{
const std::shared_ptr<T>* const _arg = va_arg(arg_ptr, const std::shared_ptr<T>* const);
for (int k = 0; k++ < out_nb_element;)
{
out_serial_[i].push_back((*_arg).get()[i]);
}
}
va_end(arg_ptr);
}
int size() const
{
return out_serial_[0].size();
}
int begin() const
{
return out_beg_;
}
const std::vector<T>& serial(int idx = 0) const
{
if (idx < 0 || idx >= N)
{
throw RangeException("serial idx out");
}
return out_serial_[idx];
}
private:
TA_Integer out_beg_;
std::vector<T> out_serial_[N];
};
}
#endif