Ice Sheet System Model  4.18
Code documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Marshalling.h
Go to the documentation of this file.
1 /*\file Marshalling.h
2  *\brief: macros to help automate the marshalling, demarshalling, and marshalling size routines.
3  */
4 
5 #ifndef _MARSHALLING_H_
6 #define _MARSHALLING_H_
7 
12 };
13 
14 #define MARSHALLING_ENUM(EN)\
15  int type_enum=EN;\
16  if(marshall_direction==MARSHALLING_FORWARD){\
17  memcpy(*pmarshalled_data,&type_enum,sizeof(int));\
18  *pmarshalled_data+=sizeof(int);\
19  }\
20  else if(marshall_direction==MARSHALLING_SIZE){\
21  *pmarshalled_data_size+=sizeof(int);\
22  }\
23  else if(marshall_direction==MARSHALLING_BACKWARD){\
24  *pmarshalled_data+=sizeof(int);\
25  }\
26  else _error_("Wrong direction during the Marshall process");\
27 
28 
29 #define MARSHALLING(FIELD)\
30  \
31  if(marshall_direction==MARSHALLING_FORWARD){\
32  memcpy(*pmarshalled_data,&FIELD,sizeof(FIELD));\
33  *pmarshalled_data+=sizeof(FIELD);\
34  }\
35  else if(marshall_direction==MARSHALLING_SIZE){\
36  *pmarshalled_data_size+=sizeof(FIELD);\
37  }\
38  else if(marshall_direction==MARSHALLING_BACKWARD){\
39  memcpy(&FIELD,*pmarshalled_data,sizeof(FIELD));\
40  *pmarshalled_data+=sizeof(FIELD);\
41  }\
42  else _error_("Wrong direction during the Marshall process");
43 
44 
45 #define MARSHALLING_ARRAY(FIELD,TYPE,SIZE) \
46  \
47  if(marshall_direction==MARSHALLING_FORWARD){\
48  memcpy(*pmarshalled_data,FIELD,SIZE*sizeof(TYPE));\
49  *pmarshalled_data+=SIZE*sizeof(TYPE);\
50  }\
51  else if(marshall_direction==MARSHALLING_SIZE){\
52  *pmarshalled_data_size+=SIZE*sizeof(TYPE);\
53  }\
54  else if(marshall_direction==MARSHALLING_BACKWARD){\
55  memcpy(FIELD,*pmarshalled_data,SIZE*sizeof(TYPE));\
56  *pmarshalled_data+=SIZE*sizeof(TYPE);\
57  }\
58  else _error_("Wrong direction during the Marshall process");
59 
60 
61 #define MARSHALLING_DYNAMIC(FIELD,TYPE,SIZE) \
62  \
63  {\
64  bool field_null=true;\
65  if (FIELD)field_null=false;\
66  MARSHALLING(field_null);\
67  \
68  if(!field_null){\
69  if(marshall_direction==MARSHALLING_FORWARD){\
70  memcpy(*pmarshalled_data,FIELD,SIZE*sizeof(TYPE));\
71  *pmarshalled_data+=SIZE*sizeof(TYPE);\
72  }\
73  else if(marshall_direction==MARSHALLING_SIZE){\
74  *pmarshalled_data_size+=SIZE*sizeof(TYPE);\
75  }\
76  else if(marshall_direction==MARSHALLING_BACKWARD){\
77  FIELD=xNew<TYPE>(SIZE);\
78  memcpy(FIELD,*pmarshalled_data,SIZE*sizeof(TYPE));\
79  *pmarshalled_data+=SIZE*sizeof(TYPE);\
80  }\
81  else _error_("Wrong direction during the Marshall process");\
82  }\
83  }
84 
85 #endif
MARSHALLING_SIZE
@ MARSHALLING_SIZE
Definition: Marshalling.h:11
marshall_directions
marshall_directions
Definition: Marshalling.h:8
MARSHALLING_BACKWARD
@ MARSHALLING_BACKWARD
Definition: Marshalling.h:10
MARSHALLING_FORWARD
@ MARSHALLING_FORWARD
Definition: Marshalling.h:9