proton  0
type_compat.h
Go to the documentation of this file.
1 #ifndef PROTON_TYPE_COMPAT_H
2 #define PROTON_TYPE_COMPAT_H 1
3 
4 /*
5  *
6  * Licensed to the Apache Software Foundation (ASF) under one
7  * or more contributor license agreements. See the NOTICE file
8  * distributed with this work for additional information
9  * regarding copyright ownership. The ASF licenses this file
10  * to you under the Apache License, Version 2.0 (the
11  * "License"); you may not use this file except in compliance
12  * with the License. You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing,
17  * software distributed under the License is distributed on an
18  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19  * KIND, either express or implied. See the License for the
20  * specific language governing permissions and limitations
21  * under the License.
22  *
23  */
24 
25 // Get Boolean
26 #if !defined(__cplusplus) && !defined(__bool_true_false_are_defined)
27 # if __STDC_VERSION__ >= 199901L || __GNUC__ >= 3 || _MSC_VER >=1800
28 # include <stdbool.h>
29 # else
30 // Need to get bool/true/false manually
31 # if _MSC_VER
32 # define bool char
33 # define false 0
34 # define true 1
35 # define __bool_true_false_are_defined
36 # else
37 # error "No definitions for bool/true/false"
38 # endif
39 # endif
40 #endif
41 /*
42  * Handle special cases for stdint.h and the definition for ssize_t.
43  * Third party libraries (e.g. Boost) may provide competing solutions.
44  *
45  * The effects of this include file may be controlled by overrides:
46  * PN_DEFINE_STDINT/PN_NODEFINE_STDINT : turn on/off definition of int64_t etc.
47  * PN_DEFINE_SSIZE_T/PN_NODEFINE_SSIZE_T : turn on/off definition of ssize_t
48  * PN_INCLUDE_STDINT/PN_NOINCLUDE_STDINT : include (or not) stdint.h
49  */
50 
51 // Honor positive overrides
52 #if defined(PN_DEFINE_STDINT)
53 # define PNI_DEFINE_STDINT
54 #endif
55 #if defined(PN_INCLUDE_STDINT)
56 # define PNI_INCLUDE_STDINT)
57 #endif
58 #if defined(PN_DEFINE_SSIZE_T)
59 # define PNI_DEFINE_SSIZE_T
60 #endif
61 
62 // Determinine default action
63 #ifndef _MSC_VER
64 // Not Windows and not using Visual Studio
65 
66 /* MBED_BUILD_TIMESTAMP is used to detect whether Proton is being built on www.mbed.org with
67 the ARM compiler. In that case ssize_t needs to be defined in this file. */
68 #if defined(MBED_BUILD_TIMESTAMP)
69 # define PNI_DEFINE_SSIZE_T
70 #else
71 #include <sys/types.h>
72 #endif /* defined(MBED_LIBRARY_VERSION) */
73 
74 # ifndef PNI_INCLUDE_STDINT
75 # define PNI_INCLUDE_STDINT
76 # endif
77 #else
78 // all versions of Visual Studio
79 # ifndef PNI_DEFINE_SSIZE_T
80 // ssize_t def is needed, unless third party definition interferes, e.g. python/swig
81 # ifndef Py_CONFIG_H
82 # define PNI_DEFINE_SSIZE_T
83 # endif
84 # endif
85 
86 # if (_MSC_VER < 1600)
87 // VS 2008 and earlier
88 # ifndef PNI_DEFINE_STDINT
89 # define PNI_DEFINE_STDINT
90 # endif
91 # else
92 // VS 2010 and newer
93 # ifndef PNI_INCLUDE_STDINT
94 # define PNI_INCLUDE_STDINT
95 # endif
96 
97 # endif // (_MSC_VER < 1600)
98 #endif //_MSC_VER
99 
100 // Honor negative overrides
101 #ifdef PN_NODEFINE_SSIZE_T
102 # undef PNI_DEFINE_SSIZE_T
103 #endif
104 #ifdef PN_NODEFINE_STDINT
105 # undef PNI_DEFINE_STDINT
106 #endif
107 #ifdef PN_NOINCLUDE_STDINT
108 # undef PNI_INCLUDE_STDINT
109 #endif
110 
111 #ifdef PNI_INCLUDE_STDINT
112 # include <stdint.h>
113 #endif
114 
115 #ifdef PNI_DEFINE_SSIZE_T
116 # ifdef _MSC_VER
117 # include <BaseTsd.h>
118 typedef SSIZE_T ssize_t;
119 # else
120 typedef intptr_t ssize_t;
121 # endif
122 #endif // PNI_DEFINE_SSIZE_T
123 
124 #ifdef PNI_DEFINE_STDINT
125 # ifdef _MSC_VER
126 
127 typedef signed __int8 int8_t;
128 typedef signed __int16 int16_t;
129 typedef signed __int32 int32_t;
130 typedef signed __int64 int64_t;
131 
132 typedef unsigned __int8 uint8_t;
133 typedef unsigned __int16 uint16_t;
134 typedef unsigned __int32 uint32_t;
135 typedef unsigned __int64 uint64_t;
136 
137 # else // _MSC_VER
138 # error stdint.h definitions not kown
139 # endif
140 #endif // PNI_DEFINE_SSIZE_T
141 
142 #endif /* type_compat.h */