]> rtime.felk.cvut.cz Git - frescor/forb.git/blob - src/basic_types.h
8aa5dc767dfc0c0ee1bb240b5bce43789bccfffa
[frescor/forb.git] / src / basic_types.h
1 /**************************************************************************/
2 /* ---------------------------------------------------------------------- */
3 /* Copyright (C) 2006 - 2008 FRESCOR consortium partners:                 */
4 /*                                                                        */
5 /*   Universidad de Cantabria,              SPAIN                         */
6 /*   University of York,                    UK                            */
7 /*   Scuola Superiore Sant'Anna,            ITALY                         */
8 /*   Kaiserslautern University,             GERMANY                       */
9 /*   Univ. Politécnica  Valencia,           SPAIN                        */
10 /*   Czech Technical University in Prague,  CZECH REPUBLIC                */
11 /*   ENEA                                   SWEDEN                        */
12 /*   Thales Communication S.A.              FRANCE                        */
13 /*   Visual Tools S.A.                      SPAIN                         */
14 /*   Rapita Systems Ltd                     UK                            */
15 /*   Evidence                               ITALY                         */
16 /*                                                                        */
17 /*   See http://www.frescor.org for a link to partners' websites          */
18 /*                                                                        */
19 /*          FRESCOR project (FP6/2005/IST/5-034026) is funded             */
20 /*       in part by the European Union Sixth Framework Programme          */
21 /*       The European Union is not liable of any use that may be          */
22 /*       made of this code.                                               */
23 /*                                                                        */
24 /*                                                                        */
25 /*  This file is part of FORB (Frescor Object Request Broker)             */
26 /*                                                                        */
27 /* FORB is free software; you can redistribute it and/or modify it        */
28 /* under terms of the GNU General Public License as published by the      */
29 /* Free Software Foundation; either version 2, or (at your option) any    */
30 /* later version.  FORB is distributed in the hope that it will be        */
31 /* useful, but WITHOUT ANY WARRANTY; without even the implied warranty    */
32 /* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU    */
33 /* General Public License for more details. You should have received a    */
34 /* copy of the GNU General Public License along with FORB; see file       */
35 /* COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,  */
36 /* Cambridge, MA 02139, USA.                                              */
37 /*                                                                        */
38 /* As a special exception, including FORB header files in a file,         */
39 /* instantiating FORB generics or templates, or linking other files       */
40 /* with FORB objects to produce an executable application, does not       */
41 /* by itself cause the resulting executable application to be covered     */
42 /* by the GNU General Public License. This exception does not             */
43 /* however invalidate any other reasons why the executable file might be  */
44 /* covered by the GNU Public License.                                     */
45 /**************************************************************************/
46
47 #ifndef BASIC_TYPES_H
48 #define BASIC_TYPES_H 1
49
50 #include <stdint.h>
51 #include <string.h>
52
53 enum {
54         CORBA_FALSE = 0,
55         CORBA_TRUE  = 1
56 };
57
58 typedef int16_t   CORBA_short;
59 typedef int32_t   CORBA_long;
60 typedef int64_t   CORBA_long_long;
61 typedef uint16_t  CORBA_unsigned_short;
62 typedef uint32_t  CORBA_unsigned_long;
63 typedef uint64_t  CORBA_unsigned_long_long;
64 typedef float     CORBA_float;
65 typedef double    CORBA_double;
66 typedef char      CORBA_char;
67 typedef int16_t   CORBA_wchar;
68 typedef uint8_t   CORBA_boolean;
69 typedef uint8_t   CORBA_octet;
70 typedef double    CORBA_long_double;
71
72 /*
73  * Bad hack, oh well
74  */
75
76 typedef CORBA_char  *CORBA_string;
77 typedef CORBA_wchar *CORBA_wstring;
78
79 #define CORBA_sequence_get_release(seq) ((seq)->_release)
80 /** 
81  * CORBA_sequence_set_release can be used to set the state of the release flag.
82  * 
83  * @param seq
84  * 
85  * @param val The value of the release flag.  If the flag is set to
86  * TRUE, the sequence effectively "owns" the storage pointed to by
87  * _buffer; if FALSE, the programmer is responsible for the storage
88  * [99-07-35.pdf].
89  */
90 #define CORBA_sequence_set_release(seq, val) ((seq)->_release = (val))
91
92 CORBA_boolean
93 __forb_sequence_alloc_buf_internal(void *seq, size_t seq_size,
94                                    void **buf_pptr, CORBA_unsigned_long *maximum_ptr,
95                                    CORBA_unsigned_long num_elements, size_t elem_size);
96
97 /** @name Sequence helper macros */
98 /**@{*/
99 /**
100  *
101  *
102  * @param seq
103  * @param num_elements
104  *
105  * @return CORBA_TRUE if the allocation was sucessfull, CORBA_FALSE if wasn't.
106  */
107 #define forb_sequence_alloc_buf(seq, num_elements)                      \
108         __forb_sequence_alloc_buf_internal(&(seq), sizeof(seq),         \
109                                            (void**)&(seq)._buffer, &(seq)._maximum, \
110                                            (num_elements), sizeof(*(seq)._buffer))
111
112 #define forb_sequence_alloc(seq_ptr, num_elements) do {                 \
113                 (seq_ptr) = forb_malloc(sizeof(*(seq_ptr)));            \
114                 memset((seq_ptr), 0, sizeof(*(seq_ptr)));               \
115                 forb_sequence_alloc_buf(*(seq_ptr), (num_elements));    \
116         } while(0)
117
118 static inline void forb_no_destructor() {}
119
120 #define forb_sequence_free_buf(seq, elem_destructor) do {               \
121                 if (CORBA_sequence_get_release(&(seq))) {               \
122                         CORBA_unsigned_long i;                          \
123                         for (i=0; i<(seq)._length; i++) { \
124                                 elem_destructor(&(seq)._buffer[i]);     \
125                         }                                               \
126                         forb_free((seq)._buffer);                       \
127                 }                                                       \
128         } while(0)
129
130 #define forb_sequence_free(seq_ptr, elem_destructor) do {               \
131                 forb_sequence_free_buf(*(seq_ptr), (elem_destructor));  \
132                 forb_free(seq_ptr);                                     \
133         } while(0)
134
135 #define forb_sequence_elem(seq, index) ((seq)._buffer[index])
136
137 #define forb_sequence_length(seq) ((seq)._length)
138
139 #define forb_sequence_foreach(seq, elemptr)           \
140         for ((elemptr)=&forb_sequence_elem((seq), 0); \
141              (elemptr)<&forb_sequence_elem((seq), forb_sequence_length(seq)); \
142              (elemptr)++)
143
144 /**@}*/
145
146 #endif