PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Core.hpp

https://gitlab.com/ayufan/ayuine2b
C++ Header | 201 lines | 126 code | 37 blank | 38 comment | 5 complexity | d79506129f920848665d69b45c008cf8 MD5 | raw file
  1. //------------------------------------//
  2. //
  3. // Core.hpp
  4. //
  5. // Author: ayufan (ayufan[at]o2.pl)
  6. // Project: ayuine2
  7. // Date: 2006-7-31
  8. //
  9. //------------------------------------//
  10. #pragma once
  11. //------------------------------------//
  12. // disable warnings
  13. #ifdef _MSC_VER
  14. #pragma warning(disable : 4251 4275)
  15. #endif
  16. /// DOXYS_OFF
  17. //------------------------------------//
  18. // c base includes
  19. #include <cstdio>
  20. #include <cstdlib>
  21. #include <cstdarg>
  22. #include <cstring>
  23. #include <cctype>
  24. #include <cmath>
  25. #include <cfloat>
  26. #include <cassert>
  27. #include <ctime>
  28. //------------------------------------//
  29. // stl base includes
  30. #include <string>
  31. #include <map>
  32. #include <algorithm>
  33. namespace ayuine
  34. {
  35. //------------------------------------//
  36. // Define
  37. #define OffsetOf(Type,Of) ((u32)&((Type*)nullptr)->Of)
  38. #define CountOf(x) (sizeof(x)/sizeof((x)[0]))
  39. //#define TypeOf(x) x::id()
  40. //------------------------------------//
  41. // Base Types
  42. // bool
  43. typedef char c8;
  44. typedef signed char s8;
  45. typedef signed short s16;
  46. typedef signed int s32;
  47. typedef signed long long s64;
  48. typedef unsigned char u8;
  49. typedef unsigned short u16;
  50. typedef unsigned int u32;
  51. typedef unsigned long long u64;
  52. typedef float f32;
  53. typedef double f64;
  54. using namespace std;
  55. #ifdef _W64
  56. typedef u64 size;
  57. #else
  58. typedef u32 size;
  59. #endif
  60. //------------------------------------//
  61. // Exception defines
  62. #define newExceptionTrace() ExceptionTrace(__FUNCTION__, __FILE__, __LINE__)
  63. #define Throw(e) Exception::ThrowException(e, newExceptionTrace())
  64. #define Guard try {
  65. #define Unguard } catch(Exception &e) { e.CallStack.push(newExceptionTrace()); throw; } catch(...) { Throw(UnhandledException()); }
  66. #define Assert(x) if(!(x)) { Throw(AssertException(#x)); }
  67. #ifdef _DEBUG
  68. #define dGuard Guard
  69. #define dUnguard Unguard
  70. #define dAssert(x) Assert(x)
  71. #else
  72. #define dGuard
  73. #define dUnguard
  74. #define dAssert(x) (x)
  75. #endif
  76. //------------------------------------//
  77. // Consts
  78. const u32 nullptr = 0;
  79. //------------------------------------//
  80. // Limits
  81. const u32 u32Max = UINT_MAX;
  82. const u32 u32Min = 0;
  83. const s32 s32Max = INT_MAX;
  84. const s32 s32Min = INT_MIN;
  85. //------------------------------------//
  86. // Functions
  87. static string fa(const c8 **format, ...) {
  88. c8 temp[4000];
  89. va_list args;
  90. // Pobierz argumenty i utwуrz tekst
  91. va_start(args, *format);
  92. #ifdef _MSC_VER
  93. vsprintf_s(temp, sizeof(temp), *format, args);
  94. #else
  95. vsnprintf(temp, sizeof(temp), *format, args);
  96. #endif
  97. va_end(args);
  98. // Zwrуж utworzony tekst
  99. return temp;
  100. }
  101. static string va(const c8 *format, ...) {
  102. return fa(&format);
  103. }
  104. static u32 hash(const string &text) {
  105. u32 h = (u32)text.length();
  106. for(string::const_iterator i = text.begin(); i != text.end(); i++)
  107. h ^= (h << 2) + (h >> 5) + *i;
  108. return h;
  109. }
  110. static u32 hashi(const string &text) {
  111. u32 h = (u32)text.length();
  112. for(string::const_iterator i = text.begin(); i != text.end(); i++)
  113. h ^= (h << 2) + (h >> 5) + *i;
  114. return h;
  115. }
  116. template<typename Type>
  117. static Type &offset(void *data, u32 count, u32 size = sizeof(Type)) {
  118. return *(Type*)((u8*)data + count * size);
  119. }
  120. template<typename Type>
  121. static Type &next(Type *&data, u32 stride, u32 index = 1) {
  122. return *(Type*)((u8*&)data += index * stride);
  123. }
  124. //------------------------------------//
  125. // Memory functions
  126. AYUAPI void *alloc(size_t size);
  127. AYUAPI void free(void *data);
  128. };
  129. //------------------------------------//
  130. // Operators
  131. static void *operator new (size_t size) {
  132. return ayuine::alloc(size);
  133. }
  134. static void *operator new[] (size_t size) {
  135. return ayuine::alloc(size);
  136. }
  137. static void operator delete (void *data) {
  138. ayuine::free(data);
  139. }
  140. static void operator delete[] (void *data) {
  141. ayuine::free(data);
  142. }
  143. #undef min
  144. #undef max
  145. //------------------------------------//
  146. // Includes
  147. #include "TypeInfo.hpp"
  148. #include "Allocator.hpp"
  149. #include "Array.hpp"
  150. #include "List.hpp"
  151. #include "SmartPtr.hpp"
  152. #include "Delegate.hpp"
  153. #include "Object.hpp"
  154. #include "Exception.hpp"
  155. #include "MathLib.hpp"
  156. #include "File.hpp"
  157. #include "Collection.hpp"
  158. #include "Property.hpp"
  159. #include "Reader.hpp"
  160. #include "Config.hpp"
  161. #include "Log.hpp"
  162. #include "Stats.hpp"
  163. #include "VFS.hpp"
  164. #include "Time.hpp"