Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Rationalize iterators over dict (using the ones over dynars)
[simgrid.git] / include / datadesc.h
1 /* $Id$ */
2
3 /* gras/datadesc.h - Describing the data you want to exchange               */
4
5 /* Authors: Martin Quinson                                                  */
6 /* Copyright (C) 2003 the OURAGAN project.                                  */
7
8 /* This program is free software; you can redistribute it and/or modify it
9    under the terms of the license (GNU LGPL) which comes with this package. */
10
11 #ifndef GRAS_DATADESC_H
12 #define GRAS_DATADESC_H
13
14 #include <stddef.h>    /* offsetof() */
15 #include <sys/types.h>  /* size_t */
16 #include <stdarg.h>
17
18
19 /*! C++ users need love */
20 #ifndef BEGIN_DECL
21 # ifdef __cplusplus
22 #  define BEGIN_DECL extern "C" {
23 # else
24 #  define BEGIN_DECL 
25 # endif
26 #endif
27
28 /*! C++ users need love */
29 #ifndef END_DECL
30 # ifdef __cplusplus
31 #  define END_DECL }
32 # else
33 #  define END_DECL 
34 # endif
35 #endif
36 /* End of cruft for C++ */
37
38 BEGIN_DECL
39
40 /**
41  * Basic types we can embeed in DataDescriptors.
42  */
43 typedef enum
44   {CHAR_TYPE, DOUBLE_TYPE, FLOAT_TYPE, INT_TYPE, LONG_TYPE, SHORT_TYPE,
45    UNSIGNED_INT_TYPE, UNSIGNED_LONG_TYPE, UNSIGNED_SHORT_TYPE, STRUCT_TYPE}
46   DataTypes;
47 #define SIMPLE_TYPE_COUNT 9
48
49 /*!  \brief Describe a collection of data.
50  * 
51 ** A description of a collection of #type# data.  #repetitions# is used only
52 ** for arrays; it contains the number of elements.  #offset# is used only for
53 ** struct members in host format; it contains the offset of the member from the
54 ** beginning of the struct, taking into account internal padding added by the
55 ** compiler for alignment purposes.  #members#, #length#, and #tailPadding# are
56 ** used only for STRUCT_TYPE data; the #length#-long array #members# describes
57 ** the members of the nested struct, and #tailPadding# indicates how many
58 ** padding bytes the compiler adds to the end of the structure.
59 */
60
61 typedef struct DataDescriptorStruct {
62   DataTypes type;
63   size_t repetitions;
64   size_t offset;
65   /*@null@*/ struct DataDescriptorStruct *members;
66   size_t length;
67   size_t tailPadding;
68 } DataDescriptor;
69 /** DataDescriptor for an array */
70 #define SIMPLE_DATA(type,repetitions) \
71   {type, repetitions, 0, NULL, 0, 0}
72 /** DataDescriptor for an structure member */
73 #define SIMPLE_MEMBER(type,repetitions,offset) \
74   {type, repetitions, offset, NULL, 0, 0}
75 /** DataDescriptor for padding bytes */
76 #define PAD_BYTES(structType,lastMember,memberType,repetitions) \
77   sizeof(structType) - offsetof(structType, lastMember) - \
78   sizeof(memberType) * repetitions
79
80 END_DECL
81
82 #endif /* GRAS_DATADESC_H */
83