OpenSplice ISO C++ 2 DCPS  v6.x
ISO C++ 2 OpenSplice Data Distribution Service Data-Centric Publish-Subscribe API
macros.hpp
Go to the documentation of this file.
1 /*
2  * Vortex OpenSplice
3  *
4  * This software and documentation are Copyright 2006 to 2021 ADLINK
5  * Technology Limited, its affiliated companies and licensors. All rights
6  * reserved.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 #ifndef OSPL_DDS_CORE_DETAIL_MACROS_HPP_
22 #define OSPL_DDS_CORE_DETAIL_MACROS_HPP_
23 
28 // Implementation
29 
30 #include <iostream>
31 #include <string.h>
32 #include <os_defs.h>
33 
34 // == Constants
35 #define OMG_DDS_DEFAULT_STATE_BIT_COUNT_DETAIL (size_t)32
36 #define OMG_DDS_DEFAULT_STATUS_COUNT_DETAIL (size_t)32
37 // ==========================================================================
38 
39 #ifdef DOXYGEN_FOR_ISOCPP2
40 /* The above macro is never (and must never) be defined in normal compilation. The
41  below macros may be defined individually for the effect described in the documentation */
46 #define OSPL_USE_CXX11
47 
51 #define OSPL_USE_TR1
52 
56 #define OSPL_USE_BOOST
57 #endif
58 
59 // == C++ 11 / Techical Report 1 / Boost availability
60 /* Determine if C++ 11 compile flag is 'on', or is usually on by default */
61 #if (defined __GXX_EXPERIMENTAL_CXX0X || \
62  __cplusplus >= 201103L || \
63  _MSC_VER >= 1900 || \
64  (_MSC_VER >= 1600 && _HAS_CPP0X))
65 # define OSPL_DEFAULT_TO_CXX11
66 #endif
67 
68 #if (_MSC_VER >= 1500) || ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 0)))
69 # define OSPL_DEFAULT_TO_TR1
70 #endif
71 
72 /* Compiling explicitly w/ C++ 11 e.g. -std=cxx0x; Studio 2010; &c... */
73 #if (defined(OSPL_DEFAULT_TO_CXX11) && !defined (OSPL_USE_BOOST) && !defined (OSPL_USE_TR1)) \
74  || defined(OSPL_USE_CXX11)
75 # ifndef OSPL_USE_CXX11
76 # define OSPL_USE_CXX11
77 # endif
78 
79 /* Tech Report 1 headers are known available. Use unless we specifically ask for boost */
80 #elif (defined (OSPL_DEFAULT_TO_TR1) && !defined (OSPL_USE_BOOST)) \
81  || defined(OSPL_USE_TR1)
82 # ifndef OSPL_USE_TR1
83 # define OSPL_USE_TR1
84 # endif
85 
86 #else /* Not C++11, no TR1, or explicit OSPL_USE_BOOST - use boost */
87 # ifndef OSPL_USE_BOOST
88 # define OSPL_USE_BOOST
89 # endif
90 
91 #endif
92 
93 // == Static Assert
94 #if defined (OSPL_USE_CXX11) /* static_assert keyword supported */
95 # define OMG_DDS_STATIC_ASSERT_DETAIL(condition) static_assert(condition, #condition)
96 #else
97 # if defined (OSPL_USE_BOOST)
98 # include <boost/static_assert.hpp>
99 # define OMG_DDS_STATIC_ASSERT_DETAIL BOOST_STATIC_ASSERT
100 # else /* Create a compilation error by creating a negative sized array type when condition not true */
101 # define OSPL_MACRO_CONCAT_(a, b) a ## b
102 # define OSPL_MACRO_CONCAT(a, b) OSPL_MACRO_CONCAT_(a, b)
103 # if (__GNUC__ >= 4) /* Have seen 'attribute unused' on types in gcc 3.1 docs but we're only worried re 4+ anyway... */
104 # define OSPL_GCC_ATTRIBUTE_UNUSED __attribute__ ((unused))
105 /* If the above addition does not silence warnings like:
106  * typedef ‘OMG_DDS_STATIC_ASSERT_FAILED_nn’ locally defined but not used [-Wunused-local-typedefs]
107  * then you may wish to consider also/instead uncommenting the below line.
108  * @see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54372 and OSPL-3329 */
109 //# pragma GCC diagnostic ignored "-Wunused-local-typedefs"
110 # else
111 # define OSPL_GCC_ATTRIBUTE_UNUSED
112 # endif
113 # define OMG_DDS_STATIC_ASSERT_DETAIL(condition) typedef int OSPL_MACRO_CONCAT(OMG_DDS_STATIC_ASSERT_FAILED_, __LINE__)[(condition) ? 1 : -1] OSPL_GCC_ATTRIBUTE_UNUSED
114 # endif
115 #endif
116 // ==========================================================================
117 
118 // DLL Export Macros
119 #ifdef BUILD_OMG_DDS_API
120 # ifdef _WIN32 // This is defined for 32/64 bit Windows
121 # define OMG_DDS_API_DETAIL __declspec(dllexport)
122 # else
123 # define OMG_DDS_API_DETAIL
124 # endif
125 #else
126 # ifdef _WIN32 // This is defined for 32/64 bit Windows
127 # define OMG_DDS_API_DETAIL __declspec(dllimport)
128 # else
129 # define OMG_DDS_API_DETAIL
130 # endif
131 #endif
132 
133 // ==========================================================================
134 
135 // Logging Macros
136 #if 0
137 #include <dds/core/detail/maplog.hpp>
138 #define OMG_DDS_LOG_DETAIL(kind, msg) \
139  if (dds::core::detail::maplog(kind) >= os_reportVerbosity) os_report(dds::core::detail::maplog(kind),"isocpp-OMG_DDS_LOG",__FILE__,__LINE__,0,msg)
140 // std::cout << "[" << kind << "]: " << msg << std::endl;
141 // ==========================================================================
142 #endif
143 
149 #ifdef __SUNPRO_CC
150 
156 # error The ISO C++ 2 API is not supported with Solaris Studio yet. Please export INCLUDE_API_DCPS_ISOCPP2=no.
157 #endif
158 
159 // C++ 11 features
160 // Slightly pathological - we could (for example) want to use boost traits
161 // and 'STL' implementations but compile with -std=c++11, so set a macro for
162 // C++11 compile being on. This way we can always use language features
163 #if defined (OSPL_DEFAULT_TO_CXX11) || defined(OSPL_USE_CXX11)
164 # define OSPL_DDS_CXX11
165 # include <cstring>
166 #endif
167 
168 #if !defined(OSPL_DDS_FINAL) && defined (OSPL_DDS_CXX11)
169 # if defined (_MSC_VER) && ( _MSC_VER < 1700)
170 // http://msdn.microsoft.com/en-us/library/vstudio/hh567368.aspx
171 // 'Visual C++ in Visual Studio 2010 ... "final" was ... supported, but
172 // under the different spelling "sealed". The Standard spelling and
173 // semantics of "override" and "final" are now completely supported.'
174 # define OSPL_DDS_FINAL sealed
175 # else
176 # define OSPL_DDS_FINAL final
177 #endif
178 #else
179 # define OSPL_DDS_FINAL
180 #endif
181 
182 #if defined(OSPL_DDS_CXX11)
183 # if defined (_MSC_VER) && (_MSC_VER <= 1800)
184 // See: http://msdn.microsoft.com/en-us/library/vstudio/hh567368.aspx
185 // "These are now supported, but with this exception: For defaulted functions,
186 // the use of = default to request member-wise move constructors and move
187 // assignment operators is not supported."
188 // ('now' is currently VS 2013 - _MSC_VER == 1800).
189 # define OSPL_CXX11_NO_FUNCTION_DEFAULTS
190 # endif
191 #endif
192 
193 #if defined(OSPL_DDS_CXX11)
194 # if defined (_MSC_VER) && (_MSC_VER < 1800)
195 // See: http://msdn.microsoft.com/en-us/library/vstudio/hh567368.aspx
196 // "Strongly typed enums were only partially supported in VS2010, but the
197 // concept of an "enum class" was not implemented yet. So for VS2010 we
198 // will still revert to the C-style enums.
199 // ('Proper' enum classes are supported in VS 2013 - _MSC_VER == 1800).
200 # define OSPL_ENUM enum
201 # define OSPL_ENUM_LABEL(_escope,_etype,_elabel) _escope::_elabel
202 # define OSPL_UNSCOPED_ENUM_LABEL(_etype,_elabel) _elabel
203 # else
204 # define OSPL_ENUM enum class
205 # define OSPL_ENUM_LABEL(_escope,_etype,_elabel) _escope::_etype::_elabel
206 # define OSPL_UNSCOPED_ENUM_LABEL(_etype,_elabel) _etype::_elabel
207 # endif
208 #else
209 # define OSPL_ENUM enum
210 # define OSPL_ENUM_LABEL(_escope,_etype,_elabel) _escope::_elabel
211 # define OSPL_UNSCOPED_ENUM_LABEL(_etype,_elabel) _elabel
212 #endif
213 // End of implementation
214 
215 #endif /* OSPL_DDS_CORE_DETAIL_MACROS_HPP_ */