WSL/SLF GitLab Repository

marshal_meteoio.cc 9.01 KB
Newer Older
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
/***********************************************************************************/
/*  Copyright 2009 HES-SO Fribourg                                                 */
/***********************************************************************************/
/* This file is part of MeteoIO.
    MeteoIO is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    MeteoIO is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with MeteoIO.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef _POPC_

#include <meteoio/marshal_meteoio.h>

namespace mio {

void marshal_uint(POPBuffer &buf, unsigned int &data, int maxsize, int flag, POPMemspool *temp)
{
	(void)maxsize;
	(void)*temp;
	if (flag & FLAG_MARSHAL) {
		int n=(int)data;
		buf.Pack(&n,1);
	} else {
		int n;
		buf.UnPack(&n,1);
		data=(unsigned int)n;
	}
}

void marshal_slope_type(POPBuffer &buf, DEMObject::slope_type &data, int maxsize, int flag, POPMemspool *temp)
{
	(void)maxsize;
	(void)*temp;
	if (flag & FLAG_MARSHAL) {
		int n=(int)data;
		buf.Pack(&n,1);
	} else {
		int n;
		buf.UnPack(&n,1);
		data=(DEMObject::slope_type)n;
	}
}

void marshal_geo_distances(POPBuffer &buf, Coords::geo_distances &data, int maxsize, int flag, POPMemspool *temp)
{
	(void)maxsize;
	(void)*temp;
	if (flag & FLAG_MARSHAL) {
		int n=(int)data;
		buf.Pack(&n,1);
	} else {
		int n;
		buf.UnPack(&n,1);
		data=(Coords::geo_distances)n;
	}
}

void marshal_vec_coords(POPBuffer &buf,std::vector<Coords> &data, int maxsize, int flag, POPMemspool *temp)
{
	(void)maxsize;
	(void)*temp;
	if (flag & FLAG_MARSHAL) {
		int n=data.size();
		buf.Pack(&n,1);
		for(int i=0;i<n;i++) {
			marshal_Coords(buf, data[i], maxsize, FLAG_MARSHAL, temp);
		}
	} else {
		int n=0;
		buf.UnPack(&n,1);
		data.clear();
		for(int i=0;i<n;i++) {
			Coords obj;
			marshal_Coords(buf, obj, maxsize, !FLAG_MARSHAL, temp);
			data.push_back(obj);
		}
	}
}

void marshal_METEO_DATASET(POPBuffer &buf, METEO_DATASET &data, int maxsize, int flag, POPMemspool *temp)
{
	(void)maxsize;
	(void)*temp;
	if(flag&FLAG_MARSHAL) {
		int n=data.size();
		buf.Pack(&n,1);
		for(int i=0;i<n;i++) {
			data[i].Serialize(buf,true);
		}
	} else {
		int n=0;
		buf.UnPack(&n,1);
		data.clear();  
		for(int i=0;i<n;i++) {
			MeteoData obj;
			obj.Serialize(buf,false);
			data.push_back(obj);
		}
	}
}

void marshal_vector_METEO_DATASET(POPBuffer &buf, std::vector<METEO_DATASET> &data, int maxsize, int flag, POPMemspool *temp)
{
	if(flag&FLAG_MARSHAL) {
		int n=data.size();
		buf.Pack(&n,1);
		for(int i=0;i<n;i++) {
			marshal_METEO_DATASET(buf, data[i], maxsize, FLAG_MARSHAL, temp);
		}
	} else {
		int n=0;
		buf.UnPack(&n,1);
		data.clear();
		for(int i=0;i<n;i++) {
			METEO_DATASET obj;
			marshal_METEO_DATASET(buf, obj, maxsize, !FLAG_MARSHAL, temp);
			data.push_back(obj);
		}
	}
}

130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
void marshal_map_str_dbl(POPBuffer &buf, std::map<std::string, double> &data_map, int maxsize, int flag, POPMemspool *temp)
{
	(void)maxsize;
	(void)*temp;
	if(flag&FLAG_MARSHAL) {
		int n=data_map.size();
		buf.Pack(&n,1);
		for(std::map<std::string, double>::const_iterator it = data_map.begin(); it != data_map.end(); ++it) {
			buf.Pack(&(it->first),1);
			buf.Pack(&(it->second),1);
		}

	} else {
		int n=0;
		std::string key;
		double value;
		buf.UnPack(&n,1);
		data_map.clear();
		for(int i=0;i<n;i++) {
			buf.UnPack(&key,1);
			buf.UnPack(&value,1);
			data_map[key] = value;
		}
	}
}

156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
void marshal_map_str_str(POPBuffer &buf, std::map<std::string, std::string> &data_map, int maxsize, int flag, POPMemspool *temp)
{
	(void)maxsize;
	(void)*temp;
	if(flag&FLAG_MARSHAL) {
		int n=data_map.size();
		buf.Pack(&n,1);
		for(std::map<std::string, std::string>::const_iterator it = data_map.begin(); it != data_map.end(); ++it) {
			buf.Pack(&(it->first),1);
			buf.Pack(&(it->second),1);
		}

	} else {
		int n=0;
		std::string key;
		std::string value;
		buf.UnPack(&n,1);
		data_map.clear();
		for(int i=0;i<n;i++) {
			buf.UnPack(&key,1);
			buf.UnPack(&value,1);
			data_map[key] = value;
		}
	}
}

void marshal_vecstr(POPBuffer &buf, std::vector<std::string> &data, int maxsize, int flag, POPMemspool *temp)
{
	(void)maxsize;
	(void)*temp;
	if(flag&FLAG_MARSHAL) {
		int n=data.size();
		buf.Pack(&n,1);
		for (int jj=0; jj<n; jj++) {
			buf.Pack(&(data[jj]),1);
		}
	} else {
		int n=0;
		std::string value;
		buf.UnPack(&n,1);
		data.clear();
		for(int jj=0;jj<n;jj++) {
			buf.UnPack(&value,1);
			data.push_back(value);
		}
	}
}

void marshal_map_str_vecstr(POPBuffer &buf, std::map<std::string, STR_VECTOR> &data_map, int maxsize, int flag, POPMemspool *temp)
{
	if(flag&FLAG_MARSHAL) {
		int n=data_map.size();
		buf.Pack(&n,1);
		for(std::map<std::string, STR_VECTOR>::const_iterator it = data_map.begin(); it != data_map.end(); ++it) {
			buf.Pack(&(it->first),1);
			STR_VECTOR tmp_strvec = it->second;
			marshal_vecstr(buf, tmp_strvec, maxsize, FLAG_MARSHAL, temp);
		}
	} else {
		int n=0;
		std::string key;
		std::vector<std::string> value;
		buf.UnPack(&n,1);
		data_map.clear();
		for(int i=0;i<n;i++) {
			buf.UnPack(&key,1);
			marshal_vecstr(buf, value, maxsize, !FLAG_MARSHAL, temp);
			data_map[key] = value;
		}
	}
}

//HACK is this still needed?
void marshal_Coords(POPBuffer &buf, Coords &data, int maxsize, int flag, POPMemspool *temp) {
	(void)maxsize;
	(void)*temp;
	if(flag&FLAG_MARSHAL) {
		data.Serialize(buf,true);
	} else {
		data.Serialize(buf,false);
	}
}

void marshal_STATION_DATASET(POPBuffer &buf, STATION_DATASET &data, int maxsize, int flag, POPMemspool *temp)
{
	(void)maxsize;
	(void)*temp;
	if(flag&FLAG_MARSHAL) {
		int n=data.size();
		buf.Pack(&n,1);
		for(int i=0;i<n;i++) {
			data[i].Serialize(buf,true);
		}
	} else {
		int n=0;
		buf.UnPack(&n,1);
		data.clear();
		for(int i=0;i<n;i++) {
			StationData obj;
			obj.Serialize(buf,false);
			data.push_back(obj);
		}
	}
}

void marshal_vector_STATION_DATASET(POPBuffer &buf, std::vector<STATION_DATASET> &data, int maxsize, int flag, POPMemspool *temp)
{
	if(flag&FLAG_MARSHAL) {
		int n=data.size();
		buf.Pack(&n,1);
		for(int i=0;i<n;i++) {
			marshal_STATION_DATASET(buf, data[i], maxsize, FLAG_MARSHAL, temp);
		}
	} else {
		int n=0;
		buf.UnPack(&n,1);
		data.clear();
		for(int i=0;i<n;i++) {
			STATION_DATASET obj;
			marshal_STATION_DATASET(buf, obj, maxsize, !FLAG_MARSHAL, temp);
			data.push_back(obj);
		}
	}
}

void marshal_vector_Grid2DObject(POPBuffer &buf, std::vector<Grid2DObject> &data, int maxsize, int flag, POPMemspool *temp)
{
	(void)maxsize;
	(void)*temp;
	assert(false); /* This line is here to check if the method is used*/
	if(flag&FLAG_MARSHAL) {
		int n=data.size();
		buf.Pack(&n,1);
		for(int i=0;i<n;i++) {
			data[i].Serialize(buf,true);
		}
	} else {
		int n=0;
		buf.UnPack(&n,1);
		data.clear();
		for(int i=0;i<n;i++) {
			Grid2DObject obj; 
      //buf.UnPack(&obj,1);
			obj.Serialize(buf,false);
      //marshal_Grid2DObject(buf, *obj, 0, flag, NULL);
			data.push_back(obj);
		}
	}
}

void marshal_DOUBLE2D(POPBuffer &buf, DOUBLE2D &data,int maxsize, int flag, POPMemspool *temp)
{
	(void)maxsize;
	(void)*temp;
	if (flag & FLAG_MARSHAL) {
		unsigned int nx,ny;
		data.size(nx,ny);
		buf.Pack(&nx,1);
		buf.Pack(&ny,1);
		if (nx>0 && ny>0) {
316
			for (unsigned int i=0;i<ny;i++) buf.Pack(&data(0,i), nx);
317
318
319
320
321
322
323
		}
	} else {
		unsigned int nx,ny;
		buf.UnPack(&nx,1);
		buf.UnPack(&ny,1);
		if (nx>0 && ny>0) {
			data.resize(nx,ny);
324
			for (unsigned int i=0;i<ny;i++) buf.UnPack(&data(0,i),nx);
325
326
327
328
329
330
		} else
			data.clear();
	}
}

void marshal_DOUBLE3D(POPBuffer &buf, DOUBLE3D &data,int maxsize, int flag, POPMemspool *temp)
331
{//HACK: this marshalling is sub-optimal!!
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
	(void)maxsize;
	(void)*temp;
	if (flag & FLAG_MARSHAL) {
		unsigned int nx,ny,nz;
		data.size(nx,ny,nz);
		buf.Pack(&nx,1);
		buf.Pack(&ny,1);
		buf.Pack(&nz,1);
		if (nx>0 && ny>0 && nz>0) {
			for (unsigned int i=0;i<nx;i++) {
				for (unsigned int j=0;j<ny;j++) buf.Pack(&data(i,j,0),nz);
			}
		}
	} else {
		unsigned int nx,ny,nz;
		buf.UnPack(&nx,1);
		buf.UnPack(&ny,1);
		buf.UnPack(&nz,1);
		if (nx>0 && ny>0 && nz>0) {
			data.resize(nx,ny,nz);
			for (unsigned int i=0;i<nx;i++) {
				for (unsigned int j=0;j<ny;j++) buf.UnPack(&data(i,j,0),nz);
			}
		} else
			data.clear();
	}
}

void marshal_INT2D(POPBuffer &buf, INT2D &data,int maxsize, int flag, POPMemspool *temp)
{
	(void)maxsize;
	(void)*temp;
	if (flag & FLAG_MARSHAL) {
365
366
367
368
		unsigned int nx, ny;
		data.size(nx,ny);
		buf.Pack(&nx,1);
		buf.Pack(&ny,1);
369
		if (nx>0 && ny>0) {
370
			for (unsigned int i=0;i<ny;i++) buf.Pack(&data(0,i),nx);
371
372
		}
	} else {
373
374
375
		unsigned int nx,ny;
		buf.UnPack(&nx,1);
		buf.UnPack(&ny,1);
376
377
		if (nx>0 && ny>0) {
			data.resize(nx,ny);
378
			for (unsigned int i=0;i<ny;i++) buf.UnPack(&data(0,i),nx);
379
380
381
382
383
384
385
386
		} else
			data.clear();
	}
}

} //namespace

#endif