| 1 | #pragma once
|
|---|
| 2 |
|
|---|
| 3 | /**
|
|---|
| 4 | * MI Library
|
|---|
| 5 | */
|
|---|
| 6 | #include "PrecompiledHeaders.h"
|
|---|
| 7 | #include "Environment.h"
|
|---|
| 8 |
|
|---|
| 9 | #include "FilterException.h"
|
|---|
| 10 |
|
|---|
| 11 | #ifdef MIL_OS_WINDOWS
|
|---|
| 12 | #include "os-windows/Os.h"
|
|---|
| 13 | #else
|
|---|
| 14 | #include "os-unix/Os.h"
|
|---|
| 15 | #endif
|
|---|
| 16 |
|
|---|
| 17 | #ifdef MIL_UI_WINDOWS
|
|---|
| 18 | #include "ui-windows/UI.h"
|
|---|
| 19 | #elif defined(MIL_UI_COCOA)
|
|---|
| 20 | #include "ui-cocoa/UI.h"
|
|---|
| 21 | #else
|
|---|
| 22 | #include "ui-cocoa/UI.h"
|
|---|
| 23 | #endif
|
|---|
| 24 |
|
|---|
| 25 | #include "MscCrt.h"
|
|---|
| 26 | #include "Debug.h"
|
|---|
| 27 |
|
|---|
| 28 | #ifndef decltype
|
|---|
| 29 | # define decltype(expression) BOOST_TYPEOF(expression)
|
|---|
| 30 | #endif
|
|---|
| 31 |
|
|---|
| 32 | #ifndef likely
|
|---|
| 33 | #ifdef HAVE_BUILTIN_EXPECT
|
|---|
| 34 | #define likely(expression) __builtin_expect((!!(expression)), (true))
|
|---|
| 35 | #define unlikely(expression) __builtin_expect((!!(expression)), (false))
|
|---|
| 36 | #else
|
|---|
| 37 | #define likely(expression) (expression)
|
|---|
| 38 | #define unlikely(expression) (expression)
|
|---|
| 39 | #endif
|
|---|
| 40 | #endif
|
|---|
| 41 |
|
|---|
| 42 | namespace mil {
|
|---|
| 43 | //inline static void yield();
|
|---|
| 44 | //inline static bool execute_in_single_processor();
|
|---|
| 45 | /*
|
|---|
| 46 |
|
|---|
| 47 | template <
|
|---|
| 48 | int T,
|
|---|
| 49 | int V = ((T <= sizeof(void*) * 3) ? sizeof(void*) * 3 :
|
|---|
| 50 | ((T <= sizeof(void*) * 6) ? sizeof(void*) * 6 :
|
|---|
| 51 | ((T <= sizeof(void*) * 16) ? sizeof(void*) * 16 :
|
|---|
| 52 | ((T <= sizeof(void*) * 48) ? sizeof(void*) * 48 :
|
|---|
| 53 | // ((T <= 1024) ? 1024 :
|
|---|
| 54 | 0))))
|
|---|
| 55 | //)
|
|---|
| 56 | >
|
|---|
| 57 | struct SizeFixer {
|
|---|
| 58 | static const int SIZE = V;
|
|---|
| 59 | };
|
|---|
| 60 |
|
|---|
| 61 | template <int T>
|
|---|
| 62 | struct MyPool {
|
|---|
| 63 | enum { SIZE = SizeFixer<sizeof(T)>::SIZE };
|
|---|
| 64 | static void* malloc() {
|
|---|
| 65 | if (SIZE == 0) {
|
|---|
| 66 | return std::malloc(sizeof(T));
|
|---|
| 67 | }
|
|---|
| 68 | return boost::singleton_pool<int, SIZE>::malloc();
|
|---|
| 69 | }
|
|---|
| 70 | static void free(void* memory) {
|
|---|
| 71 | if (SIZE == 0) {
|
|---|
| 72 | return std::free(memory);
|
|---|
| 73 | }
|
|---|
| 74 | boost::singleton_pool<int, SIZE>::free(memory);
|
|---|
| 75 | }
|
|---|
| 76 | };
|
|---|
| 77 | */
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | namespace mil {
|
|---|
| 81 | /*
|
|---|
| 82 | template <class T>
|
|---|
| 83 | struct PoolSizeSelector {
|
|---|
| 84 | enum {
|
|---|
| 85 | SIZE = (sizeof(T) >= 1024 ? 0 :
|
|---|
| 86 | (sizeof(T) >= 192 ? 192 :
|
|---|
| 87 | (sizeof(T) >= 64 ? 64 :
|
|---|
| 88 | (sizeof(T) >= 16 ? 16 : 4))))
|
|---|
| 89 | };
|
|---|
| 90 | };
|
|---|
| 91 | */
|
|---|
| 92 | typedef int SFINAE_CONDITION;
|
|---|
| 93 | const int SFINAE_DUMMY_VALUE = (0);
|
|---|
| 94 |
|
|---|
| 95 | template <class from>
|
|---|
| 96 | struct auto_cast_temp {
|
|---|
| 97 | from& f;
|
|---|
| 98 | auto_cast_temp(from f_) : f(f_) {}
|
|---|
| 99 | template <class to> operator to() {
|
|---|
| 100 | return (to)f;
|
|---|
| 101 | }
|
|---|
| 102 | };
|
|---|
| 103 |
|
|---|
| 104 | template <class from>
|
|---|
| 105 | auto_cast_temp<from> auto_cast(from f) {
|
|---|
| 106 | return auto_cast_temp<from>(f);
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | template <class To, class From>
|
|---|
| 110 | To memcpy_cast(From f) {
|
|---|
| 111 | To t;
|
|---|
| 112 | memset(&t, 0, sizeof(t));
|
|---|
| 113 | size_t size = 0;
|
|---|
| 114 | if (sizeof(From) > sizeof(To)) {
|
|---|
| 115 | size = sizeof(To);
|
|---|
| 116 | } else {
|
|---|
| 117 | size = sizeof(From);
|
|---|
| 118 | }
|
|---|
| 119 | memcpy(&t, &f, size);
|
|---|
| 120 | return t;
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | struct AutoFree {
|
|---|
| 124 | void* ptr;
|
|---|
| 125 | AutoFree(void* ptr) : ptr(ptr) {
|
|---|
| 126 | }
|
|---|
| 127 | ~AutoFree() {
|
|---|
| 128 | free(ptr);
|
|---|
| 129 | }
|
|---|
| 130 | };
|
|---|
| 131 |
|
|---|
| 132 | #ifdef MIL_OS_WINDOWS
|
|---|
| 133 | #if defined(UNICODE) || defined(_UNICODE)
|
|---|
| 134 | const size_t STACKABLE_MAX_PATH = 2000;
|
|---|
| 135 | #else
|
|---|
| 136 | const size_t STACKABLE_MAX_PATH = MAX_PATH;
|
|---|
| 137 | #endif
|
|---|
| 138 | #else
|
|---|
| 139 | #ifdef MAX_PATH
|
|---|
| 140 | const size_t STACKABLE_MAX_PATH = MAX_PATH;
|
|---|
| 141 | #else
|
|---|
| 142 | const size_t STACKABLE_MAX_PATH = 2000;
|
|---|
| 143 | #endif
|
|---|
| 144 | #endif
|
|---|
| 145 |
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | #define MIL_MODULE_GET_SUPER_CHILD(o) ((o).getChild().getChild().getChild().getChild().getChild().getChild().getChild().getChild().getChild().getChild().getChild())
|
|---|
| 149 | #define MIL_MODULE_SUPER_CHILD_TYPE(t) typename t::ChildType::ChildType::ChildType::ChildType::ChildType::ChildType::ChildType::ChildType::ChildType::ChildType::ChildType
|
|---|
| 150 |
|
|---|
| 151 | #define MIL_CRTP_CLASS_MEMBERS Child& getChild(){return *static_cast<Child*>(this);} typedef Child ChildType;
|
|---|
| 152 |
|
|---|
| 153 | //#ifdef __OBJC__
|
|---|
| 154 | //#include "ObjCExceptionFix.h"
|
|---|
| 155 | //#endif
|
|---|
| 156 |
|
|---|