coral
A C++ library for distributed co-simulation
config.h
1 /*
2 Copyright 2013-2017, SINTEF Ocean and the Coral contributors.
3 This Source Code Form is subject to the terms of the Mozilla Public
4 License, v. 2.0. If a copy of the MPL was not distributed with this
5 file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 NOTE TO USERS:
8 This header file is meant for internal use in this library, and should
9 normally not be included directly by client code. Its purpose is to
10 aid in maintaining a cross-platform code base.
11 
12 NOTE TO CONTRIBUTORS:
13 This file intentionally has a ".h" extension, as it is supposed to
14 be a valid C header. C++-specific code should therefore be placed in
15 #ifdef __cplusplus blocks.
16 */
17 #ifndef CORAL_CONFIG_H
18 #define CORAL_CONFIG_H
19 
20 // Program name and version number
21 #define CORAL_PROGRAM_NAME "Coral"
22 
23 #define CORAL_VERSION_MAJOR 0
24 #define CORAL_VERSION_MINOR 8
25 #define CORAL_VERSION_PATCH 0
26 
27 #define CORAL_VERSION_STRINGIFY(a, b, c) #a "." #b "." #c
28 #define CORAL_VERSION_STRINGIFY_EXPAND(a, b, c) CORAL_VERSION_STRINGIFY(a, b, c)
29 #define CORAL_VERSION_STRING CORAL_VERSION_STRINGIFY_EXPAND( \
30  CORAL_VERSION_MAJOR, CORAL_VERSION_MINOR, CORAL_VERSION_PATCH)
31 
32 #define CORAL_PROGRAM_NAME_VERSION CORAL_PROGRAM_NAME " " CORAL_VERSION_STRING
33 
34 // Unified GCC version macro
35 #ifdef __GNUC__
36 # ifdef __GNUC_PATCHLEVEL__
37 # define CORAL_GNUC_VERSION (__GNUC__*100000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__)
38 # else
39 # define CORAL_GNUC_VERSION (__GNUC__*100000 + __GNUC_MINOR__*100)
40 # endif
41 #endif
42 
43 // Microsoft Visual C++ version macros
44 #ifdef _MSC_VER
45 # define CORAL_MSC10_VER 1600 // VS 2010
46 # define CORAL_MSC11_VER 1700 // VS 2012
47 # define CORAL_MSC12_VER 1800 // VS 2013
48 # define CORAL_MSC14_VER 1900 // VS 2015
49 #endif
50 
51 // Support for 'noexcept' (C++11) was introduced in Visual Studio 2015
52 #ifdef __cplusplus
53 # if defined(_MSC_VER) && (_MSC_VER < CORAL_MSC14_VER)
54 # define CORAL_NOEXCEPT throw()
55 # else
56 # define CORAL_NOEXCEPT noexcept
57 # endif
58 #endif
59 
60 // Visual Studio does not support the 'noreturn' attribute
61 #ifdef __cplusplus
62 # ifdef _MSC_VER
63 # define CORAL_NORETURN __declspec(noreturn)
64 # else
65 # define CORAL_NORETURN [[noreturn]]
66 # endif
67 #endif
68 
69 // Visual Studio (2013 and 2015, at the time of writing) supports C++11's
70 // explicitly defaulted and deleted functions, BUT with the exception that
71 // it cannot generate default memberwise move constructors and move assignment
72 // operators (cf. https://msdn.microsoft.com/en-us/library/dn457344.aspx).
73 //
74 // Therefore, we define a macro to generate memberwise move operations for
75 // classes where such are appropriate. For compilers that *do* have full
76 // support for these, the macro will just expand to the C++11 "=default"
77 // syntax.
78 //
79 // Usage is as follows:
80 //
81 // class MyClass {
82 // int x;
83 // SomeNonCopyableType y;
84 // CORAL_DEFINE_DEFAULT_MOVE(MyClass, x, y)
85 // }
86 //
87 // It is crucial that *all* members be included as arguments to the macro,
88 // or they will simply not be moved.
89 #ifdef __cplusplus
90 # if defined(_MSC_VER)
91  // This is a slightly modified version of a trick which is explained
92  // in detail here: http://stackoverflow.com/a/16683147
93 # define CORAL_EVALUATE_MACRO(code) code
94 # define CORAL_CONCATENATE_MACROS(A, B) A ## B
95 # define CORAL_BUILD_MACRO_NAME(PREFIX, SUFFIX) CORAL_CONCATENATE_MACROS(PREFIX ## _, SUFFIX)
96 # define CORAL_VA_SHIFT(_1, _2, _3, _4, _5, _6, _7, _8, _9, thats_the_one, ...) thats_the_one
97 # define CORAL_VA_SIZE(...) CORAL_EVALUATE_MACRO(CORAL_VA_SHIFT(__VA_ARGS__, 9, 8, 7, 6, 5, 4, 3, 2, 1))
98 # define CORAL_SELECT(PREFIX, ...) CORAL_BUILD_MACRO_NAME(PREFIX, CORAL_VA_SIZE(__VA_ARGS__))(__VA_ARGS__)
99 
100 # define CORAL_MOVE_CTOR_INITIALISER(...) CORAL_SELECT(CORAL_MOVE_CTOR_INITIALISER, __VA_ARGS__)
101 # define CORAL_MOVE_CTOR_INITIALISER_1(m) m(std::move(other.m))
102 # define CORAL_MOVE_CTOR_INITIALISER_2(m1, m) CORAL_MOVE_CTOR_INITIALISER_1(m1), m(std::move(other.m))
103 # define CORAL_MOVE_CTOR_INITIALISER_3(m1, m2, m) CORAL_MOVE_CTOR_INITIALISER_2(m1, m2), m(std::move(other.m))
104 # define CORAL_MOVE_CTOR_INITIALISER_4(m1, m2, m3, m) CORAL_MOVE_CTOR_INITIALISER_3(m1, m2, m3), m(std::move(other.m))
105 # define CORAL_MOVE_CTOR_INITIALISER_5(m1, m2, m3, m4, m) CORAL_MOVE_CTOR_INITIALISER_4(m1, m2, m3, m4), m(std::move(other.m))
106 # define CORAL_MOVE_CTOR_INITIALISER_6(m1, m2, m3, m4, m5, m) CORAL_MOVE_CTOR_INITIALISER_5(m1, m2, m3, m4, m5), m(std::move(other.m))
107 # define CORAL_MOVE_CTOR_INITIALISER_7(m1, m2, m3, m4, m5, m6, m) CORAL_MOVE_CTOR_INITIALISER_6(m1, m2, m3, m4, m5, m6), m(std::move(other.m))
108 # define CORAL_MOVE_CTOR_INITIALISER_8(m1, m2, m3, m4, m5, m6, m7, m) CORAL_MOVE_CTOR_INITIALISER_7(m1, m2, m3, m4, m5, m6, m7), m(std::move(other.m))
109 # define CORAL_MOVE_CTOR_INITIALISER_9(m1, m2, m3, m4, m5, m6, m7, m8, m) CORAL_MOVE_CTOR_INITIALISER_8(m1, m2, m3, m4, m5, m6, m7, m8), m(std::move(other.m))
110 
111 # define CORAL_MOVE_OPER_ASSIGNMENT(...) CORAL_SELECT(CORAL_MOVE_OPER_ASSIGNMENT, __VA_ARGS__)
112 # define CORAL_MOVE_OPER_ASSIGNMENT_1(m) m = std::move(other.m);
113 # define CORAL_MOVE_OPER_ASSIGNMENT_2(m1, m) CORAL_MOVE_OPER_ASSIGNMENT_1(m1) m = std::move(other.m);
114 # define CORAL_MOVE_OPER_ASSIGNMENT_3(m1, m2, m) CORAL_MOVE_OPER_ASSIGNMENT_2(m1, m2) m = std::move(other.m);
115 # define CORAL_MOVE_OPER_ASSIGNMENT_4(m1, m2, m3, m) CORAL_MOVE_OPER_ASSIGNMENT_3(m1, m2, m3) m = std::move(other.m);
116 # define CORAL_MOVE_OPER_ASSIGNMENT_5(m1, m2, m3, m4, m) CORAL_MOVE_OPER_ASSIGNMENT_4(m1, m2, m3, m4) m = std::move(other.m);
117 # define CORAL_MOVE_OPER_ASSIGNMENT_6(m1, m2, m3, m4, m5, m) CORAL_MOVE_OPER_ASSIGNMENT_5(m1, m2, m3, m4, m5) m = std::move(other.m);
118 # define CORAL_MOVE_OPER_ASSIGNMENT_7(m1, m2, m3, m4, m5, m6, m) CORAL_MOVE_OPER_ASSIGNMENT_6(m1, m2, m3, m4, m5, m6) m = std::move(other.m);
119 # define CORAL_MOVE_OPER_ASSIGNMENT_8(m1, m2, m3, m4, m5, m6, m7, m) CORAL_MOVE_OPER_ASSIGNMENT_7(m1, m2, m3, m4, m5, m6, m7) m = std::move(other.m);
120 # define CORAL_MOVE_OPER_ASSIGNMENT_9(m1, m2, m3, m4, m5, m6, m7, m8, m) CORAL_MOVE_OPER_ASSIGNMENT_8(m1, m2, m3, m4, m5, m6, m7, m8) m = std::move(other.m);
121 
122 # define CORAL_DEFINE_DEFAULT_MOVE_CONSTRUCTOR(ClassName, ...) \
123  ClassName(ClassName&& other) CORAL_NOEXCEPT : CORAL_MOVE_CTOR_INITIALISER(__VA_ARGS__) { }
124 # define CORAL_DEFINE_DEFAULT_MOVE_ASSIGNMENT(ClassName, ...) \
125  ClassName& operator=(ClassName&& other) CORAL_NOEXCEPT { CORAL_MOVE_OPER_ASSIGNMENT(__VA_ARGS__) return *this; }
126 
127 # else
128 # define CORAL_DEFINE_DEFAULT_MOVE_CONSTRUCTOR(ClassName, ...) \
129  ClassName(ClassName&&) = default;
130 # define CORAL_DEFINE_DEFAULT_MOVE_ASSIGNMENT(ClassName, ...) \
131  ClassName& operator=(ClassName&&) = default;
132 # endif
133 # define CORAL_DEFINE_DEFAULT_MOVE(ClassName, /* all members: */ ...) \
134  CORAL_DEFINE_DEFAULT_MOVE_CONSTRUCTOR(ClassName, __VA_ARGS__) \
135  CORAL_DEFINE_DEFAULT_MOVE_ASSIGNMENT(ClassName, __VA_ARGS__)
136 #endif
137 
138 
139 #ifdef __cplusplus
140 # define CORAL_DEFINE_BITWISE_ENUM_OPERATORS(EnumName) \
141  inline EnumName operator|(EnumName a, EnumName b) { \
142  return static_cast<EnumName>(static_cast<int>(a) | static_cast<int>(b)); } \
143  inline EnumName operator&(EnumName a, EnumName b) { \
144  return static_cast<EnumName>(static_cast<int>(a) & static_cast<int>(b)); } \
145  inline EnumName& operator|=(EnumName& a, EnumName b) { \
146  *reinterpret_cast<int*>(&a) |= static_cast<int>(b); \
147  return a; } \
148  inline EnumName& operator&=(EnumName& a, EnumName b) { \
149  *reinterpret_cast<int*>(&a) &= static_cast<int>(b); \
150  return a; }
151 #endif
152 
153 // This is as good a place as any to put top-level documentation.
172 #endif // header guard