Daniele Bartolini 10 лет назад
Родитель
Сommit
080ee96860
3 измененных файлов с 33 добавлено и 30 удалено
  1. 2 0
      src/core/containers/pair.h
  2. 31 0
      src/core/memory/memory.h
  3. 0 30
      src/core/types.h

+ 2 - 0
src/core/containers/pair.h

@@ -5,6 +5,8 @@
 
 #pragma once
 
+#include "memory.h"
+
 namespace crown
 {
 

+ 31 - 0
src/core/memory/memory.h

@@ -49,6 +49,36 @@ namespace memory
 	}
 } // namespace memory
 
+#define ALLOCATOR_AWARE typedef int allocator_aware
+
+/// Convert integer to type.
+template <int v>
+struct Int2Type { enum {value=v}; };
+
+/// Determines if a class is allocator aware.
+template <class T>
+struct is_allocator_aware {
+
+        template <typename C>
+        static char test_fun(typename C::allocator_aware *);
+
+        template <typename C>
+        static int test_fun(...);
+
+public:
+        enum {
+                value = (sizeof(test_fun<T>(0)) == sizeof(char))
+        };
+};
+
+#define IS_ALLOCATOR_AWARE(T) is_allocator_aware<T>::value
+#define IS_ALLOCATOR_AWARE_TYPE(T) Int2Type< IS_ALLOCATOR_AWARE(T) >
+
+/// Allocator aware constuction
+template <class T> inline T &construct(void *p, Allocator& a, Int2Type<true>) {new (p) T(a); return *(T *)p;}
+template <class T> inline T &construct(void *p, Allocator& /*a*/, Int2Type<false>) {new (p) T; return *(T *)p;}
+template <class T> inline T &construct(void *p, Allocator& a) {return construct<T>(p, a, IS_ALLOCATOR_AWARE_TYPE(T)());}
+
 namespace memory_globals
 {
 	/// Constructs the initial default allocators.
@@ -74,3 +104,4 @@ namespace memory_globals
 /// @note
 /// @a allocator must be a reference to an existing allocator.
 #define CE_DELETE(allocator, ptr) crown::memory::call_destructor_and_deallocate(allocator, ptr)
+

+ 0 - 30
src/core/types.h

@@ -6,7 +6,6 @@
 #pragma once
 
 #include "config.h"
-#include "memory_types.h"
 #include <cstddef>
 #include <stdint.h>
 #include <stdio.h>
@@ -53,35 +52,6 @@ struct StringId64
 typedef StringId64 ResourceId;
 
 #define INVALID_ID 65535
-#define ALLOCATOR_AWARE typedef int allocator_aware
-
-/// Convert integer to type.
-template <int v>
-struct Int2Type { enum {value=v}; };
-
-/// Determines if a class is allocator aware.
-template <class T>
-struct is_allocator_aware {
-
-        template <typename C>
-        static char test_fun(typename C::allocator_aware *);
-
-        template <typename C>
-        static int test_fun(...);
-
-public:
-        enum {
-                value = (sizeof(test_fun<T>(0)) == sizeof(char))
-        };
-};
-
-#define IS_ALLOCATOR_AWARE(T) is_allocator_aware<T>::value
-#define IS_ALLOCATOR_AWARE_TYPE(T) Int2Type< IS_ALLOCATOR_AWARE(T) >
-
-/// Allocator aware constuction
-template <class T> inline T &construct(void *p, Allocator& a, Int2Type<true>) {new (p) T(a); return *(T *)p;}
-template <class T> inline T &construct(void *p, Allocator& /*a*/, Int2Type<false>) {new (p) T; return *(T *)p;}
-template <class T> inline T &construct(void *p, Allocator& a) {return construct<T>(p, a, IS_ALLOCATOR_AWARE_TYPE(T)());}
 
 struct Id
 {