uLib-0.2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Macros.h
Go to the documentation of this file.
1 /*//////////////////////////////////////////////////////////////////////////////
2 // CMT Cosmic Muon Tomography project //////////////////////////////////////////
4 
5  Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
6  All rights reserved
7 
8  Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
9 
10  ------------------------------------------------------------------
11  This library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU Lesser General Public
13  License as published by the Free Software Foundation; either
14  version 3.0 of the License, or (at your option) any later version.
15 
16  This library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  Lesser General Public License for more details.
20 
21  You should have received a copy of the GNU Lesser General Public
22  License along with this library.
23 
25 
26 
27 
28 #ifndef U_CORE_MACROS_H
29 #define U_CORE_MACROS_H
30 
31 //#ifndef HAVE_CONFIG_H
32 // #include "config.h"
33 //#endif
34 
35 #include <assert.h>
36 
37 #define uLibAssert(condition) assert(condition)
38 
39 
40 // Symbols visibility attribute, see: http://gcc.gnu.org/wiki/Visibility //
41 // http://stackoverflow.com/questions/5116333/dynamic-cast-failed-when-hidding-symbol //
42 #if defined _WIN32 || defined __CYGWIN__
43  #ifdef BUILDING_DLL
44  #ifdef __GNUC__
45  #define DLL_PUBLIC __attribute__ ((dllexport))
46  #else
47  #define DLL_PUBLIC __declspec(dllexport) // Note: actually gcc seems to also supports this syntax.
48  #endif
49  #else
50  #ifdef __GNUC__
51  #define DLL_PUBLIC __attribute__ ((dllimport))
52  #else
53  #define DLL_PUBLIC __declspec(dllimport) // Note: actually gcc seems to also supports this syntax.
54  #endif
55  #endif
56  #define DLL_LOCAL
57 #else
58  #if __GNUC__ >= 4
59  #define DLL_PUBLIC __attribute__ ((visibility ("default")))
60  #define DLL_LOCAL __attribute__ ((visibility ("hidden")))
61  #else
62  #define DLL_PUBLIC
63  #define DLL_LOCAL
64  #endif
65 #endif
66 
67 
68 
69 // foreach Qt style
70 #ifndef foreach
71 #include "boost/foreach.hpp"
72 #define foreach(ref, list) BOOST_FOREACH(ref,list)
73 #endif
74 
75 
76 
77 #define uLibVGetMacro(name,type) \
78  virtual inline const type Get##name() const = 0;
79 
80 #define uLibVSetMacro(name,type) \
81  virtual inline void Set##name(const type name) = 0;
82 
83 #define uLibVGetSetMacro(name,type) \
84  uLibVGet(name,type); \
85  uLibVSet(name,type);
86 
87 #define uLibVRefMacro(name,type) \
88  virtual inline type & name() = 0;
89 
90 
91 
92 #define uLibGetMacro(name,type) \
93  inline type Get##name() const { return this->m_##name; }
94 
95 #define uLibConstRefMacro(name,type) \
96  inline const type & name() const { return this->m_##name; }
97 
98 // verificare necessita' di typecast //
99 #define uLibSetMacro(name,type) \
100  inline void Set##name(type name) { this->m_##name = name; }
101 
102 #define uLibGetSetMacro(name,type) \
103  inline type Get##name() const { return this->m_##name; } \
104  uLibSetMacro(name,type);
105 
106 #define uLibRefMacro(name,type) \
107  inline type & name() { return this->m_##name; }
108 
109 
110 /* Following macros override usual branch prediction of compiler
111  * These are to be used in conditional statement whose result might
112  * be Bayesian biased:
113  *
114  * // previous_line
115  * if (likely(a>1)) { // block_1 }
116  * else { block_2 }
117  *
118  * will write the block_1 code right after previous line, without using
119  * compiler branch prediction for results. Otherwise
120  *
121  * // previous_line
122  * if (unlikely(a>1)) { // block_1 }
123  * else { block_2 }
124  *
125  * will write block_2 after previous_line, leaving block_1 after
126  * (usually after the end of the whole function! Use with care!)
127  */
128 
129 #define unlikely(expr) __builtin_expect(!!(expr), 0)
130 
131 #define likely(expr) __builtin_expect(!!(expr), 1)
132 
133 #endif // MACROS_H