-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_row.h
153 lines (117 loc) · 3.27 KB
/
data_row.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#ifndef datastream_data_row_h
#define datastream_data_row_h
#include <map>
#include <list>
#include <sstream>
#include "data_element.h"
#include "schema_set.h"
#include "datastream_definitions.h"
#include "formatter.h"
#include <boost/range/algorithm_ext/for_each.hpp>
namespace datastream {
/* Drew Dormann -
I only removed "using std::map;" here, as it was triggering
a compiler error, but I recommend not moving any symbols out
of "std::" in a header. */
using std::vector;
using std::shared_ptr;
using std::list;
using std::ostream;
class DataRow;
template <typename T>
struct is_row_containter {
enum { value = false };
};
template <>
struct is_row_containter <std::vector<std::shared_ptr<DataRow>>> {
enum { value = true };
};
template <>
struct is_row_containter <std::vector<std::weak_ptr<DataRow>>> {
enum { value = true };
};
template <>
struct is_row_containter <std::vector<DataRow>> {
enum { value = true };
};
template <>
struct is_row_containter <std::list<DataRow>> {
enum { value = true };
};
template <>
struct is_row_containter <std::vector<DataRow*>> {
enum { value = true };
};
class DataRow{
template <typename T>
typename std::enable_if<is_row_containter<T>::value>::type
friend writeRows(
ostream & os,
RowWrapper parent_row_wrapper_type,
const SchemaSet& schema_set,
T const& rows ,
Formatter& formatter,
unsigned int & siblings_written
)
{
if(rows.size() == 0 ){
if (schema_set.hideWhenEmpty() == false){
formatter.writeEmptyGroup(
os,
schema_set.groupName(),
schema_set.rowName(),
siblings_written,
parent_row_wrapper_type,
schema_set.limitSingleChild(),
schema_set.groupWrapper(),
schema_set.rowWrapper()
);
}
return;
}
formatter.openGroup(
os,
schema_set.groupName(),
schema_set.rowName(),
siblings_written,
//parent row wrapper
parent_row_wrapper_type, //schema_set.rowWrapper,
schema_set.limitSingleChild(),
schema_set.groupWrapper()
);
unsigned int children_written = 0;
for (auto& row : rows){
deref(row).write(os, schema_set, formatter, children_written);
if(schema_set.limitSingleChild() && children_written > 0){
break;
}
}
formatter.closeGroup(
os,
schema_set.groupName(),
schema_set.rowName(),
siblings_written,
parent_row_wrapper_type,
schema_set.limitSingleChild(),
schema_set.groupWrapper()
);
++siblings_written;
}
public:
DataRow (unsigned int id, unsigned int parent, unsigned int position);
void load(const list<SchemaElement> & schema_elements, const string & line_values);
void connect(int set_id, std::shared_ptr<std::vector<DataRow*>> child_rows);
void write(ostream & os, const SchemaSet& schema_set, Formatter& formatter, unsigned int & siblings_written) const;
inline unsigned int id() const {return id_;}
inline unsigned int parent() const {return parent_;}
inline unsigned int position() const {return position_;}
private:
unsigned int id_;
unsigned int parent_;
unsigned int position_;
list<DataElement> child_elements_;
// shared with other rows in this set with the same id
std::map<int, shared_ptr<vector<DataRow*>>> child_rows_by_set_id_;
};
}
#endif