]> rtime.felk.cvut.cz Git - frescor/forb.git/blob - src/basic_types.h
Fixed g++ warning about signedness
[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
52 enum {
53         CORBA_FALSE = 0,
54         CORBA_TRUE  = 1
55 };
56
57 typedef int16_t   CORBA_short;
58 typedef int32_t   CORBA_long;
59 typedef int64_t   CORBA_long_long;
60 typedef uint16_t  CORBA_unsigned_short;
61 typedef uint32_t  CORBA_unsigned_long;
62 typedef uint64_t  CORBA_unsigned_long_long;
63 typedef float     CORBA_float;
64 typedef double    CORBA_double;
65 typedef char      CORBA_char;
66 typedef int16_t   CORBA_wchar;
67 typedef uint8_t   CORBA_boolean;
68 typedef uint8_t   CORBA_octet;
69 typedef double    CORBA_long_double;
70
71 /*
72  * Bad hack, oh well
73  */
74
75 typedef CORBA_char  *CORBA_string;
76 typedef CORBA_wchar *CORBA_wstring;
77
78 #define CORBA_sequence_get_release(seq) ((seq)->_release)
79 /** 
80  * CORBA_sequence_set_release can be used to set the state of the release flag.
81  * 
82  * @param seq
83  * 
84  * @param val The value of the release flag.  If the flag is set to
85  * TRUE, the sequence effectively "owns" the storage pointed to by
86  * _buffer; if FALSE, the programmer is responsible for the storage
87  * [99-07-35.pdf].
88  */
89 #define CORBA_sequence_set_release(seq, val) ((seq)->_release = (val))
90
91 /** @name Sequence helper macros */
92 /**@{*/
93 #define forb_sequence_alloc_buf(seq, num_elements) do {                 \
94                 memset(&(seq), 0, sizeof(seq));                         \
95                 if (num_elements) (seq)._buffer = forb_malloc((num_elements)*sizeof(*(seq)._buffer)); \
96                 else (seq)._buffer = NULL;                              \
97                 (seq)._maximum = (seq)._buffer ? (num_elements) : 0;    \
98                 (seq)._length = 0;                                      \
99         } while(0)
100
101 #define forb_sequence_alloc(seq_ptr, num_elements) do {                 \
102                 (seq_ptr) = forb_malloc(sizeof(*(seq_ptr)));            \
103                 memset((seq_ptr), 0, sizeof(*(seq_ptr)));               \
104                 forb_sequence_alloc_buf(*(seq_ptr), (num_elements));    \
105         } while(0)
106
107 static inline void forb_no_destructor() {}
108
109 #define forb_sequence_free_buf(seq, elem_destructor) do {               \
110                 if (CORBA_sequence_get_release(&(seq))) {               \
111                         CORBA_unsigned_long i;                          \
112                         for (i=0; i<(seq)._length; i++) { \
113                                 elem_destructor(&(seq)._buffer[i]);     \
114                         }                                               \
115                         forb_free((seq)._buffer);                       \
116                 }                                                       \
117         } while(0)
118
119 #define forb_sequence_free(seq_ptr, elem_destructor) do {               \
120                 forb_sequence_free_buf(*(seq_ptr), (elem_destructor));  \
121                 forb_free(seq_ptr);                                     \
122         } while(0)
123
124 #define forb_sequence_elem(seq, index) ((seq)._buffer[index])
125 /**@}*/
126
127 #endif