replicode
types.h
Go to the documentation of this file.
1 /*
2  * HUMANOBS - mBrane
3  *
4  * Eric Nivel
5  * Center for Analysis and Design of Intelligent Agents
6  * Reykjavik University, Menntavegur 1, 101 Reykjavik, Iceland
7  * http://cadia.ru.is
8  * Copyright(c)2012
9  *
10  * This software was developed by the above copyright holder as part of
11  * the HUMANOBS EU research project, in collaboration with the
12  * following parties:
13  *
14  * Autonomous Systems Laboratory
15  * Technical University of Madrid, Spain
16  * http://www.aslab.org/
17  *
18  * Communicative Machines
19  * Edinburgh, United Kingdom
20  * http://www.cmlabs.com/
21  *
22  * Istituto Dalle Molle di Studi sull'Intelligenza Artificiale
23  * University of Lugano and SUPSI, Switzerland
24  * http://www.idsia.ch/
25  *
26  * Institute of Cognitive Sciences and Technologies
27  * Consiglio Nazionale delle Ricerche, Italy
28  * http://www.istc.cnr.it/
29  *
30  * Dipartimento di Ingegneria Informatica
31  * University of Palermo, Italy
32  * http://roboticslab.dinfo.unipa.it/index.php/Main/HomePage
33  *
34  *
35  * --- HUMANOBS Open-Source BSD License, with CADIA Clause v 1.0 ---
36  *
37  * Redistribution and use in source and binary forms, with or without
38  * modification, is permitted provided that the following conditions
39  * are met:
40  *
41  * - Redistributions of source code must retain the above copyright
42  * and collaboration notice, this list of conditions and the
43  * following disclaimer.
44  *
45  * - Redistributions in binary form must reproduce the above copyright
46  * notice, this list of conditions and the following
47  * disclaimer in the documentation and/or other materials provided
48  * with the distribution.
49  *
50  * - Neither the name of its copyright holders nor the names of its
51  * contributors may be used to endorse or promote products
52  * derived from this software without specific prior written permission.
53  *
54  * - CADIA Clause: The license granted in and to the software under this
55  * agreement is a limited-use license. The software may not be used in
56  * furtherance of:
57  * (i) intentionally causing bodily injury or severe emotional distress
58  * to any person;
59  * (ii) invading the personal privacy or violating the human rights of
60  * any person; or
61  * (iii) committing or preparing for any act of war.
62  *
63  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
64  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
65  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
66  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
67  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
68  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
69  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
70  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
71  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
72  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
73  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
74  */
75 
76 #ifndef core_types_h
77 #define core_types_h
78 
79 #include <cstddef>
80 
81 #if defined(WIN32)
82 #define WINDOWS
83 #define ARCH_32
84 #elif defined(WIN64)
85 #define WINDOWS
86 #define ARCH_64
87 #elif defined(__GNUC__)
88 
89 //#if __GNUC__ == 4
90 //#if __GNUC_MINOR__ < 3
91 //#error "GNU C++ 4.3 or later is required to compile this program"
92 //#endif /* __GNUC_MINOR__ */
93 //#endif /* __GNUC__ */
94 
95 #if defined(__x86_64)
96 #define ARCH_64
97 #elif defined(__i386)
98 #define ARCH_32
99 #endif
100 #if defined(__linux)
101 #define LINUX
102 #endif
103 #endif
104 
105 #if defined WINDOWS
106 
107 #define WIN32_LEAN_AND_MEAN
108 #define _WIN32_WINNT 0x0501 // i.e. win xp sp2
109 #include <windows.h>
110 #ifndef AF_MAX
111 #include <winsock2.h>
112 #endif
113 
114 #include <vector>
115 #include <unordered_set>
116 #include <unordered_map>
117 #define UNORDERED_MAP std::tr1::unordered_map
118 #define UNORDERED_SET std::tr1::unordered_set
119 #define UNORDERED_MULTIMAP std::tr1::unordered_multimap
120 #define UNORDERED_MULTISET std::tr1::unordered_multiset
121 
122 #if defined CORELIBRARY_EXPORTS
123 #define core_dll __declspec(dllexport)
124 #else
125 #define core_dll __declspec(dllimport)
126 #endif
127 #define dll_export __declspec(dllexport)
128 #define dll_import __declspec(dllimport)
129 
130 #pragma warning(disable: 4530) // warning: exception disabled
131 #pragma warning(disable: 4996) // warning: this function may be unsafe
132 #pragma warning(disable: 4800) // warning: forcing value to bool
133 #pragma warning(disable: 4251) // warning: class xxx needs to have dll-interface to be used by clients of class yyy
134 
135 #if( _SECURE_SCL != 0 )
136 #pragma message( "Warning: _SECURE_SCL != 0. You _will_ get either slowness or runtime errors." )
137 #endif
138 
139 #if( _HAS_ITERATOR_DEBUGGING != 0 )
140 #pragma message( "Warning: _HAS_ITERATOR_DEBUGGING != 0. You _will_ get either slowness or runtime errors." )
141 #endif
142 
143 #elif defined LINUX
144 #define core_dll
145 #include <iostream>
146 #include <string>
147 #include <pthread.h>
148 #include <semaphore.h>
149 #include <signal.h>
150 #include <limits.h>
151 
152 #include <vector>
153 #include <unordered_map>
154 #include <unordered_set>
155 #define UNORDERED_MAP std::unordered_map
156 #define UNORDERED_SET std::unordered_set
157 #define UNORDERED_MULTIMAP std::unordered_multimap
158 #define UNORDERED_MULTISET std::unordered_multiset
159 
160 #define dll_export __attribute((visibility("default")))
161 #define dll_import __attribute((visibility("default")))
162 #define cdecl
163 
164 #include <sys/socket.h>
165 #include <netinet/in.h>
166 #include <netinet/ip.h>
167 #include <arpa/inet.h>
168 #define SOCKET_ERROR -1
169 #define INVALID_SOCKET -1
170 #define closesocket(X) close(X)
171 #else
172 #error "This is a new platform"
173 #endif
174 
175 #define NEWLINE '\n'
176 
177 namespace core
178 {
179 
180 #define WORD32_MASK 0xFFFFFFFF
181 
182 #if defined ARCH_32
183 
184 #define HALF_WORD_SHIFT 16
185 #define HALF_WORD_HIGH_MASK 0xFFFF0000
186 #define HALF_WORD_LOW_MASK 0x0000FFFF
187 #define WORD_MASK 0xFFFFFFFF
188 
189 #elif defined ARCH_64
190 // UPS!
191 // typedef unsigned long uint64;
192 
193 #define HALF_WORD_SHIFT 32
194 #define HALF_WORD_HIGH_MASK 0xFFFFFFFF00000000
195 #define HALF_WORD_LOW_MASK 0x00000000FFFFFFFF
196 #define WORD_MASK 0xFFFFFFFFFFFFFFFF
197 
198 #endif
199 
200 #if defined WINDOWS
201 typedef HINSTANCE shared_object;
202 typedef HANDLE thread;
203 #define thread_ret uint32
204 #define thread_ret_val(ret) return ret;
205 typedef LPTHREAD_START_ROUTINE thread_function;
206 #define thread_function_call WINAPI
207 typedef SOCKET socket;
208 typedef HANDLE semaphore;
209 typedef HANDLE mutex;
210 typedef CRITICAL_SECTION critical_section;
211 typedef HANDLE timer;
212 typedef HANDLE event;
213 #define signal_handler_function_call WINAPI
214 typedef PHANDLER_ROUTINE signal_handler;
215 #elif defined LINUX
216 typedef void *shared_object;
217 typedef pthread_t thread;
218 #define thread_ret void *
219 #define thread_ret_val(ret) pthread_exit((thread_ret)ret);
220 typedef thread_ret(*thread_function)(void *);
221 #define thread_function_call
222 typedef int socket;
223 typedef struct sockaddr SOCKADDR;
224 typedef sem_t semaphore;
225 typedef pthread_mutex_t mutex;
226 typedef pthread_mutex_t critical_section;
227 typedef timer_t timer;
228 #define signal_handler_function_call
229 typedef sighandler_t signal_handler;
230 #define stricmp strcasecmp
231 #endif
232 
233 }
234 
235 
236 #endif
Definition: base.cpp:81
std::thread thread
Definition: RR.h:320