WSL/SLF GitLab Repository

marshal_meteoio.cc 9.72 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
/***********************************************************************************/
/*  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;
	}
}

38
39
40
41
42
43
44
45
46
47
48
49
50
51
void marshal_MeteoParameters(POPBuffer &buf, MeteoData::Parameters &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=(MeteoData::Parameters)n;
	}
}

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
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);
		}
	}
}

102
void marshal_METEO_TIMESERIE(POPBuffer &buf, METEO_TIMESERIE &data, int maxsize, int flag, POPMemspool *temp)
103
104
105
106
107
108
109
110
111
112
113
114
{
	(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);
115
		data.clear();
116
117
118
119
120
121
122
123
		for(int i=0;i<n;i++) {
			MeteoData obj;
			obj.Serialize(buf,false);
			data.push_back(obj);
		}
	}
}

124
void marshal_vector_METEO_TIMESERIE(POPBuffer &buf, std::vector<METEO_TIMESERIE> &data, int maxsize, int flag, POPMemspool *temp)
125
126
127
128
129
{
	if(flag&FLAG_MARSHAL) {
		int n=data.size();
		buf.Pack(&n,1);
		for(int i=0;i<n;i++) {
130
			marshal_METEO_TIMESERIE(buf, data[i], maxsize, FLAG_MARSHAL, temp);
131
132
133
134
135
136
		}
	} else {
		int n=0;
		buf.UnPack(&n,1);
		data.clear();
		for(int i=0;i<n;i++) {
137
138
			METEO_TIMESERIE obj;
			marshal_METEO_TIMESERIE(buf, obj, maxsize, !FLAG_MARSHAL, temp);
139
140
141
142
143
			data.push_back(obj);
		}
	}
}

144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
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;
		}
	}
}

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
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);
	}
}

253
void marshal_STATION_TIMESERIE(POPBuffer &buf, STATION_TIMESERIE &data, int maxsize, int flag, POPMemspool *temp)
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
{
	(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);
		}
	}
}

275
void marshal_vector_STATION_TIMESERIE(POPBuffer &buf, std::vector<STATION_TIMESERIE> &data, int maxsize, int flag, POPMemspool *temp)
276
277
278
279
280
{
	if(flag&FLAG_MARSHAL) {
		int n=data.size();
		buf.Pack(&n,1);
		for(int i=0;i<n;i++) {
281
			marshal_STATION_TIMESERIE(buf, data[i], maxsize, FLAG_MARSHAL, temp);
282
283
284
285
286
287
		}
	} else {
		int n=0;
		buf.UnPack(&n,1);
		data.clear();
		for(int i=0;i<n;i++) {
288
289
			STATION_TIMESERIE obj;
			marshal_STATION_TIMESERIE(buf, obj, maxsize, !FLAG_MARSHAL, temp);
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
			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++) {
311
			Grid2DObject obj;
312
313
314
315
316
317
318
319
      //buf.UnPack(&obj,1);
			obj.Serialize(buf,false);
      //marshal_Grid2DObject(buf, *obj, 0, flag, NULL);
			data.push_back(obj);
		}
	}
}

320
void marshal_DOUBLE2D(POPBuffer &buf, DOUBLE2D &data, int maxsize, int flag, POPMemspool *temp)
321
322
323
324
325
326
327
328
{
	(void)maxsize;
	(void)*temp;
	if (flag & FLAG_MARSHAL) {
		unsigned int nx,ny;
		data.size(nx,ny);
		buf.Pack(&nx,1);
		buf.Pack(&ny,1);
329
330
		bool keep_nodata = data.getKeepNodata();
		buf.Pack(&keep_nodata,1);
331
		if (nx>0 && ny>0) {
332
333
			const unsigned int nxy=nx*ny;
			buf.Pack(&data(0,0), nxy);
334
335
336
337
338
		}
	} else {
		unsigned int nx,ny;
		buf.UnPack(&nx,1);
		buf.UnPack(&ny,1);
339
340
341
		bool keep_nodata;
		buf.UnPack(&keep_nodata,1);
		data.setKeepNodata(keep_nodata);
342
343
		if (nx>0 && ny>0) {
			data.resize(nx,ny);
344
345
			const unsigned int nxy=nx*ny;
			buf.UnPack(&data(0,0),nxy);
346
347
348
349
350
		} else
			data.clear();
	}
}

351
void marshal_DOUBLE3D(POPBuffer &buf, DOUBLE3D &data, int maxsize, int flag, POPMemspool *temp)
352
{//HACK: this marshalling is sub-optimal!!
353
354
355
356
357
358
359
360
	(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);
361
362
		bool keep_nodata = data.getKeepNodata();
		buf.Pack(&keep_nodata,1);
363
		if (nx>0 && ny>0 && nz>0) {
364
365
			const unsigned int nxyz=nx*ny*nz;
			buf.Pack(&data(0,0,0),nxyz);
366
367
368
369
370
371
		}
	} else {
		unsigned int nx,ny,nz;
		buf.UnPack(&nx,1);
		buf.UnPack(&ny,1);
		buf.UnPack(&nz,1);
372
373
374
		bool keep_nodata;
		buf.UnPack(&keep_nodata,1);
		data.setKeepNodata(keep_nodata);
375
376
		if (nx>0 && ny>0 && nz>0) {
			data.resize(nx,ny,nz);
377
378
			const unsigned int nxyz=nx*ny*nz;
			buf.UnPack(&data(0,0,0),nxyz);
379
380
381
382
383
		} else
			data.clear();
	}
}

384
void marshal_INT2D(POPBuffer &buf, INT2D &data, int maxsize, int flag, POPMemspool *temp)
385
386
387
388
{
	(void)maxsize;
	(void)*temp;
	if (flag & FLAG_MARSHAL) {
389
390
391
392
		unsigned int nx, ny;
		data.size(nx,ny);
		buf.Pack(&nx,1);
		buf.Pack(&ny,1);
393
394
		bool keep_nodata = data.getKeepNodata();
		buf.Pack(&keep_nodata,1);
395
		if (nx>0 && ny>0) {
396
397
			const unsigned int nxy=nx*ny;
			buf.Pack(&data(0,0), nxy);
398
399
		}
	} else {
400
401
402
		unsigned int nx,ny;
		buf.UnPack(&nx,1);
		buf.UnPack(&ny,1);
403
404
405
		bool keep_nodata;
		buf.UnPack(&keep_nodata,1);
		data.setKeepNodata(keep_nodata);
406
407
		if (nx>0 && ny>0) {
			data.resize(nx,ny);
408
409
			const unsigned int nxy=nx*ny;
			buf.UnPack(&data(0,0), nxy);
410
411
412
413
414
415
416
417
		} else
			data.clear();
	}
}

} //namespace

#endif