OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
csv_multiarray.hpp
1/*
2 * csv_multiarray_copy.hpp
3 *
4 * Created on: Jun 20, 2015
5 * Author: i-bird
6 */
7
8#ifndef CSV_MULTIARRAY_COPY_HPP_
9#define CSV_MULTIARRAY_COPY_HPP_
10
11
12
31template<typename T>
33{
34 inline csv_col_str(std::string prp, std::stringstream & str)
35 {
36 str << "," << prp;
37 }
38};
39
41template<typename T,size_t N1>
42struct csv_col_str<T[N1]>
43{
44 inline csv_col_str(std::string prp, std::stringstream & str)
45 {
46 for (size_t i = 0 ; i < N1 ; i++)
47 str << "," << prp << "_" << "[" << i << "]";
48 }
49};
50
52template<typename T,size_t N1,size_t N2>
53struct csv_col_str<T[N1][N2]>
54{
55 inline csv_col_str(std::string prp, std::stringstream & str)
56 {
57 for (size_t i1 = 0 ; i1 < N1 ; i1++)
58 {
59 for (size_t i2 = 0 ; i2 < N2 ; i2++)
60 {
61 str << "," << prp << "_" << "[" << i1 << "]" << "[" << i2 << "]";
62 }
63 }
64 }
65};
66
68template<typename T,size_t N1,size_t N2,size_t N3>
69struct csv_col_str<T[N1][N2][N3]>
70{
71 inline csv_col_str(std::string prp, std::stringstream & str)
72 {
73 for (size_t i1 = 0 ; i1 < N1 ; i1++)
74 {
75 for (size_t i2 = 0 ; i2 < N2 ; i2++)
76 {
77 for (size_t i3 = 0 ; i3 < N3 ; i3++)
78 {
79 str << "," << prp << "_" << "[" << i1 << "]" << "[" << i2 << "]" << "[" << i3 << "]";
80 }
81 }
82 }
83 }
84};
85
87template<typename T,size_t N1,size_t N2,size_t N3,size_t N4>
88struct csv_col_str<T[N1][N2][N3][N4]>
89{
90 inline csv_col_str(std::string prp, std::stringstream & str)
91 {
92 for (size_t i1 = 0 ; i1 < N1 ; i1++)
93 {
94 for (size_t i2 = 0 ; i2 < N2 ; i2++)
95 {
96 for (size_t i3 = 0 ; i3 < N3 ; i3++)
97 {
98 for (size_t i4 = 0 ; i4 < N4 ; i4++)
99 {
100 str << "," << prp << "_" << "[" << i1 << "]" << "[" << i2 << "]" << "[" << i3 << "]" << "[" << i4 << "]";
101 }
102 }
103 }
104 }
105 }
106};
107
108
127template<typename T, bool is_writable>
129{
130 inline csv_value_str(T & v, std::stringstream & str)
131 {
132 str << "," << v;
133 }
134};
135
137template<typename T,size_t N1, bool is_writable>
138struct csv_value_str<T[N1], is_writable>
139{
140 template<typename ArrObject>
141 inline csv_value_str(const ArrObject v, std::stringstream & str)
142 {
143 for (size_t i = 0 ; i < N1 ; i++)
144 str << "," << v[i];
145 }
146};
147
149template<typename T,size_t N1,size_t N2, bool is_writable>
150struct csv_value_str<T[N1][N2], is_writable>
151{
152 template<typename ArrObject>
153 inline csv_value_str(const ArrObject v, std::stringstream & str)
154 {
155 for (size_t i1 = 0 ; i1 < N1 ; i1++)
156 {
157 for (size_t i2 = 0 ; i2 < N2 ; i2++)
158 {
159 str << "," << v[i1][i2];
160 }
161 }
162 }
163};
164
166template<typename T,size_t N1,size_t N2,size_t N3, bool is_writable>
167struct csv_value_str<T[N1][N2][N3], is_writable>
168{
169 template<typename ArrObject>
170 inline csv_value_str(const ArrObject v, std::stringstream & str)
171 {
172 for (size_t i1 = 0 ; i1 < N1 ; i1++)
173 {
174 for (size_t i2 = 0 ; i2 < N2 ; i2++)
175 {
176 for (size_t i3 = 0 ; i3 < N3 ; i3++)
177 {
178 str << "," << v[i1][i2][i3];
179 }
180 }
181 }
182 }
183};
184
186template<typename T,size_t N1,size_t N2,size_t N3,size_t N4, bool is_writable>
187struct csv_value_str<T[N1][N2][N3][N4],is_writable>
188{
189 template<typename ArrObject>
190 inline csv_value_str(const ArrObject v, std::stringstream & str)
191 {
192 for (size_t i1 = 0 ; i1 < N1 ; i1++)
193 {
194 for (size_t i2 = 0 ; i2 < N2 ; i2++)
195 {
196 for (size_t i3 = 0 ; i3 < N3 ; i3++)
197 {
198 for (size_t i4 = 0 ; i4 < N4 ; i4++)
199 {
200 str << "," << v[i1][i2][i3][i4];
201 }
202 }
203 }
204 }
205 }
206};
207
209template<typename T>
210struct csv_value_str<T,false>
211{
212 inline csv_value_str(const T v, std::stringstream & str)
213 {
214 str << "," << 0.0;
215 }
216};
217
218#endif /* CSV_MULTIARRAY_COPY_HPP_ */
This class is an helper to produce csv headers from multi-array.
This class is an helper to produce csv data from multi-array.