Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 330 vs 331 for /trunk/Source Code/Hardware/Platform/Headers/PlatformDefines.h

Diff revisions: vs.
  @@ -32,6 +32,13 @@
32 32 #include <functional>
33 33 #include <atomic>
34 34
35 + #if defined ( OS_WINDOWS )
36 + #include <windows.h>
37 + #ifdef DELETE
38 + #undef DELETE
39 + #endif
40 + #endif
41 +
35 42 namespace Divide {
36 43
37 44 ///Data Types
  @@ -50,9 +57,8 @@
50 57 /// Converts an arbitrary positive integer value to a bitwise value used for masks
51 58 #define toBit(X) (1 << (X))
52 59 /// a la Boost
53 - template <class T>
54 - inline void hash_combine(std::size_t& seed, const T& v)
55 - {
60 + template<typename T>
61 + inline void hash_combine(std::size_t& seed, const T& v) {
56 62 std::hash<T> hasher;
57 63 seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
58 64 }
  @@ -194,35 +200,63 @@
194 200 packed_int b;
195 201 } P32;
196 202
197 - template <typename... Args>
203 + template<typename... Args>
198 204 auto DELEGATE_BIND(Args&&... args) -> decltype(std::bind(std::forward<Args>(args)...)) {
199 205 return std::bind(std::forward<Args>(args)...);
200 206 }
201 207
202 - template <typename... Args>
208 + template<typename... Args>
203 209 auto DELEGATE_REF(Args&&... args) -> decltype(std::bind(std::forward<Args>(args)...)) {
204 210 return std::bind(std::forward<Args>(args)...);
205 211 }
206 212
207 - template <typename... Args>
213 + template<typename... Args>
208 214 auto DELEGATE_CREF(Args&&... args) -> decltype(std::cref(std::forward<Args>(args)...)) {
209 215 return std::cref(std::forward<Args>(args)...);
210 216 }
211 217
212 - template <typename T = void>
218 + template<typename T = void>
213 219 using DELEGATE_CBK = std::function<T()>;
214 220
215 221 }; //namespace Divide
216 222
217 - void* operator new[]( size_t size, const char* pName, Divide::I32 flags, Divide::U32 debugFlags, const char* file, Divide::I32 line );
218 - void operator delete[]( void* ptr, const char* pName, Divide::I32 flags, Divide::U32 debugFlags, const char* file, Divide::I32 line );
219 - void* operator new[]( size_t size, size_t alignment, size_t alignmentOffset, const char* pName, Divide::I32 flags, Divide::U32 debugFlags, const char* file, Divide::I32 line );
220 - void operator delete[]( void* ptr, size_t alignment, size_t alignmentOffset, const char* pName, Divide::I32 flags, Divide::U32 debugFlags, const char* file, Divide::I32 line );
223 + void* operator new[](size_t size,
224 + const char* pName,
225 + Divide::I32 flags,
226 + Divide::U32 debugFlags,
227 + const char* file,
228 + Divide::I32 line);
229 +
230 + void operator delete[](void* ptr,
231 + const char* pName,
232 + Divide::I32 flags,
233 + Divide::U32 debugFlags,
234 + const char* file,
235 + Divide::I32 line);
236 +
237 + void* operator new[](size_t size,
238 + size_t alignment,
239 + size_t alignmentOffset,
240 + const char* pName,
241 + Divide::I32 flags,
242 + Divide::U32 debugFlags,
243 + const char* file,
244 + Divide::I32 line);
245 +
246 + void operator delete[](void* ptr,
247 + size_t alignment,
248 + size_t alignmentOffset,
249 + const char* pName,
250 + Divide::I32 flags,
251 + Divide::U32 debugFlags,
252 + const char* file,
253 + Divide::I32 line);
254 +
221 255 // EASTL also wants us to define this (see string.h line 197)
222 256 Divide::I32 Vsnprintf8( char* pDestination, size_t n, const char* pFormat, va_list arguments );
223 257
224 258 #if defined(NDEBUG)
225 - # define New new
259 + # define MemoryManager_NEW new
226 260 #else
227 261 void* operator new( size_t size );
228 262 void operator delete( void *p );
  @@ -234,62 +268,93 @@
234 268 void* operator new[]( size_t size, char* zFile, Divide::I32 nLine );
235 269 void operator delete[]( void *ptr, char* zFile, Divide::I32 nLine );
236 270
237 - # define New new(__FILE__, __LINE__)
271 + # define MemoryManager_NEW new(__FILE__, __LINE__)
238 272 #endif
239 273
240 274 namespace Divide {
241 275 namespace MemoryManager {
242 276
243 - template<class T>
277 + template<typename T>
244 278 inline void SAFE_FREE(T*& ptr){
245 279 if (ptr) {
246 280 free(ptr);
247 281 ptr = nullptr;
248 282 }
249 283 }
250 - template<class T>
251 - /// Deletes and nullifies the specified pointer only if it's not null
252 - inline void SAFE_DELETE( T*& ptr ) {
253 - if ( ptr ) {
254 - delete ptr;
255 - ptr = nullptr;
256 - }
284 +
285 + /// Deletes and nullifies the specified pointer
286 + template<typename T>
287 + inline void DELETE( T*& ptr ) {
288 + delete ptr;
289 + ptr = nullptr;
257 290 }
258 - # define SET_SAFE_DELETE_FRIEND template<class T> friend void MemoryManager::SAFE_DELETE( T*& ptr );
259 - template<class T>
260 - /// Deletes and nullifies the specified array pointer only if it's not null
261 - inline void SAFE_DELETE_ARRAY( T*& ptr ) {
262 - if ( ptr ) {
263 - delete[] ptr;
264 - ptr = nullptr;
265 - }
291 + # define SET_DELETE_FRIEND template<typename T> \
292 + friend void MemoryManager::DELETE( T*& ptr );
293 +
294 + /// Deletes and nullifies the specified pointer
295 + template<typename T>
296 + inline void SAFE_DELETE(T*& ptr) {
297 + DIVIDE_ASSERT(ptr != nullptr, "SAFE_DELETE: null pointer received");
298 +
299 + delete ptr;
300 + ptr = nullptr;
301 + }
302 + # define SET_SAFE_DELETE_FRIEND template<typename T> \
303 + friend void MemoryManager::DELETE( T*& ptr );
304 +
305 + /// Deletes and nullifies the specified array pointer
306 + template<typename T>
307 + inline void DELETE_ARRAY( T*& ptr ) {
308 + delete[] ptr;
309 + ptr = nullptr;
266 310 }
267 - # define SET_SAFE_DELETE_ARRAY_FRIEND template<class T> friend void MemoryManager::SAFE_DELETE_ARRAY( T*& ptr );
268 - template<class T>
269 - /// Deletes and nullifies the specified pointer only if it's not null. Returns "true" if deletion was successful
270 - inline bool SAFE_DELETE_CHECK( T*& ptr ) {
271 - if ( ptr ) {
272 - delete ptr;
273 - ptr = nullptr;
274 - return true;
311 + # define SET_DELETE_ARRAY_FRIEND template<typename T> \
312 + friend void MemoryManager::DELETE_ARRAY( T*& ptr );
313 +
314 + /// Deletes and nullifies the specified array pointer
315 + template<typename T>
316 + inline void SAFE_DELETE_ARRAY(T*& ptr) {
317 + DIVIDE_ASSERT(ptr != nullptr, "SAFE_DELETE_ARRAY: null pointer received");
318 +
319 + delete[] ptr;
320 + ptr = nullptr;
321 + }
322 + # define SET_SAFE_DELETE_ARRAY_FRIEND template<typename T> \
323 + friend void MemoryManager::DELETE_ARRAY( T*& ptr );
324 +
325 + /// Deletes and nullifies the specified pointer. Returns "false" if the pointer was already null
326 + template<typename T>
327 + inline bool DELETE_CHECK( T*& ptr ) {
328 + if ( ptr == nullptr) {
329 + return false;
275 330 }
276 - return false;
331 +
332 + delete ptr;
333 + ptr = nullptr;
334 +
335 + return true;
277 336 }
278 - # define SET_SAFE_DELETE_CHECK_FRIEND template<class T> friend void MemoryManager::SAFE_DELETE_CHECK( T*& ptr );
279 - template<class T>
280 - /// Deletes and nullifies the specified array pointer only if it's not null. Returns "true" if deletion was successful
281 - inline bool SAFE_DELETE_ARRAY_CHECK( T*& ptr ) {
282 - if ( ptr ) {
283 - delete[] ptr;
284 - ptr = nullptr;
285 - return true;
337 + # define SET_DELETE_CHECK_FRIEND template<typename T> \
338 + friend void MemoryManager::DELETE_CHECK( T*& ptr );
339 +
340 + /// Deletes and nullifies the specified array pointer. Returns "false" if the pointer was already null
341 + template<typename T>
342 + inline bool DELETE_ARRAY_CHECK( T*& ptr ) {
343 + if (ptr == nullptr) {
344 + return false;
286 345 }
287 - return false;
346 +
347 + delete[] ptr;
348 + ptr = nullptr;
349 +
350 + return true;
288 351 }
289 - # define SET_SAFE_DELETE_ARRAY_CHECK_FRIEND template<class T> friend void MemoryManager::SAFE_DELETE_ARRAY_CHECK( T*& ptr );
290 - template<class T>
352 +
353 + # define SET_DELETE_ARRAY_CHECK_FRIEND template<typename T> \
354 + friend void MemoryManager::DELETE_ARRAY_CHECK( T*& ptr );
291 355 /// Deletes every element from the vector and clears it at the end
292 - inline void SAFE_DELETE_VECTOR( vectorImpl<T*>& vec ) {
356 + template<typename T>
357 + inline void DELETE_VECTOR( vectorImpl<T*>& vec ) {
293 358 if ( !vec.empty() ) {
294 359 for ( T* iter : vec ) {
295 360 delete iter;
  @@ -297,30 +362,45 @@
297 362 vec.clear();
298 363 }
299 364 }
300 - # define SET_SAFE_DELETE_VECTOR_FRIEND template<class T> friend void MemoryManager::SAFE_DELETE_VECTOR( vectorImpl<T*>& vec );
301 - template<class T, class U>
365 + # define SET_DELETE_VECTOR_FRIEND template<typename T> \
366 + friend void MemoryManager::DELETE_VECTOR( vectorImpl<T*>& vec );
367 +
368 + /// Deletes every element from the map and clears it at the end
369 + template<typename K, typename V, typename HashFun = hashAlg::hash<K> >
370 + inline void DELETE_HASHMAP(hashMapImpl<K, V, HashFun>& map) {
371 + if (!map.empty()) {
372 + for (hashMapImpl<K, V, HashFun>::value_type& iter : map) {
373 + delete iter.second;
374 + }
375 + hashAlg::fastClear(map);
376 + }
377 + }
378 + # define SET_DELETE_HASHMAP_FRIEND template<typename K, typename V, typename HashFun = hashAlg::hash<K> > \
379 + friend void MemoryManager::DELETE_HASHMAP( hashMapImpl<K, V, HashFun>& map );
380 +
302 381 /// Deletes the object pointed to by "OLD" and redirects that pointer to the object pointed by "NEW"
303 382 /// "NEW" must be a derived (or same) class of OLD
304 - inline void SAFE_UPDATE( T*& OLD, U* const NEW ) {
305 - static_assert( std::is_base_of<T, U>::value, "SAFE_UPDATE error: T must be a descendant of U" );
306 - if ( OLD ) {
307 - delete OLD;
308 - }
383 + template<typename Base, typename Derived>
384 + inline void SAFE_UPDATE(Base*& OLD, Derived* const NEW) {
385 + static_assert(std::is_base_of<Base, Derived>::value, "SAFE_UPDATE error: New must be a descendant of Old");
386 +
387 + delete OLD;
309 388 OLD = NEW;
310 389 }
311 - # define SET_SAFE_UPDATE_FRIEND template<class T, class U> friend void MemoryManager::SAFE_UPDATE( T*& OLD, U* const NEW );
390 + # define SET_SAFE_UPDATE_FRIEND template<typename Base, typename Derived> \
391 + friend void MemoryManager::SAFE_UPDATE( Base*& OLD, Derived* const NEW );
312 392
313 393 }; //namespace MemoryManager
314 394 }; //namespace Divide
315 395 #if defined(_MSC_VER)
316 396
317 - # pragma warning(disable:4103) ///<Boost alignment shouts
397 + # pragma warning(disable:4103) //< Boost alignment shouts
318 398 # pragma warning(disable:4244)
319 - # pragma warning(disable:4996) ///< strcpy
320 - # pragma warning(disable:4201) ///<nameless struct
321 - # pragma warning(disable:4100) ///<unreferenced formal param
322 - # pragma warning(disable:4505) ///<unreferenced local function removal
323 - # pragma warning(disable:4127) ///<Constant conditional expressions
399 + # pragma warning(disable:4996) //< strcpy
400 + # pragma warning(disable:4201) //< nameless struct
401 + # pragma warning(disable:4100) //< unreferenced formal param
402 + # pragma warning(disable:4505) //< unreferenced local function removal
403 + # pragma warning(disable:4127) //< Constant conditional expressions
324 404 #elif defined(__GNUC__)
325 405 //# pragma GCC diagnostic ignored "-Wall"
326 406 #endif