libtins  4.0
macros.h
1 /*
2  * Copyright (c) 2017, Matias Fontanini
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above
12  * copyright notice, this list of conditions and the following disclaimer
13  * in the documentation and/or other materials provided with the
14  * distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  */
29 
30 #ifndef TINS_MACROS_H
31 #define TINS_MACROS_H
32 
33 #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
34  #include <sys/param.h>
35 #endif
36 
37 #include <tins/config.h>
38 
39 // Check if this is Visual Studio
40 #ifdef _MSC_VER
41  // This is Visual Studio
42  #define TINS_BEGIN_PACK __pragma( pack(push, 1) )
43  #define TINS_END_PACK __pragma( pack(pop) )
44  #define TINS_PACKED(DECLARATION) __pragma( pack(push, 1) ) DECLARATION __pragma( pack(pop) )
45  #define TINS_DEPRECATED(func) __declspec(deprecated) func
46  #define TINS_NOEXCEPT
47  #define TINS_LIKELY(x) (x)
48  #define TINS_UNLIKELY(x) (x)
49 #else
50  // Not Visual Studio. Assume this is gcc compatible
51  #define TINS_BEGIN_PACK
52  #define TINS_END_PACK __attribute__((packed))
53  #define TINS_PACKED(DECLARATION) DECLARATION __attribute__((packed))
54  #define TINS_DEPRECATED(func) func __attribute__ ((deprecated))
55  #define TINS_NOEXCEPT noexcept
56  #define TINS_LIKELY(x) __builtin_expect((x),1)
57  #define TINS_UNLIKELY(x) __builtin_expect((x),0)
58 #endif // _MSC_VER
59 
60 // If libtins was built into a shared library
61 #if defined(_WIN32) && !defined(TINS_STATIC)
62  // Export/import symbols, depending on whether we're compiling or consuming the lib
63  #ifdef tins_EXPORTS
64  #define TINS_API __declspec(dllexport)
65  #else
66  #define TINS_API __declspec(dllimport)
67  #endif // tins_EXPORTS
68 #else
69  // Otherwise, default this to an empty macro
70  #define TINS_API
71 #endif // _WIN32 && !TINS_STATIC
72 
73 #endif // TINS_MACROS_H