BsStdHeaders.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #pragma once
  2. #ifdef __BORLANDC__
  3. #define __STD_ALGORITHM
  4. #endif
  5. #include <cassert>
  6. #include <cstdio>
  7. #include <cstdlib>
  8. #include <ctime>
  9. #include <cstring>
  10. #include <cstdarg>
  11. #include <cmath>
  12. #include <memory>
  13. // STL containers
  14. #include <vector>
  15. #include <stack>
  16. #include <map>
  17. #include <string>
  18. #include <set>
  19. #include <list>
  20. #include <deque>
  21. #include <queue>
  22. #include <bitset>
  23. #include <array>
  24. // Note - not in the original STL, but exists in SGI STL and STLport
  25. // For gcc 4.3 see http://gcc.gnu.org/gcc-4.3/changes.html
  26. #if (BS_COMPILER == BS_COMPILER_GNUC)
  27. # if BS_COMP_VER >= 430
  28. # include <tr1/unordered_map>
  29. # include <tr1/unordered_set>
  30. # else
  31. # include <ext/hash_map>
  32. # include <ext/hash_set>
  33. # endif
  34. #else
  35. # if (BS_COMPILER == BS_COMPILER_MSVC) && BS_COMP_VER >= 1600 // VC++ 10.0
  36. # include <unordered_map>
  37. # include <unordered_set>
  38. # else
  39. # include <hash_set>
  40. # include <hash_map>
  41. # endif
  42. #endif
  43. // STL algorithms & functions
  44. #include <algorithm>
  45. #include <functional>
  46. #include <limits>
  47. // C++ Stream stuff
  48. #include <fstream>
  49. #include <iostream>
  50. #include <iomanip>
  51. #include <sstream>
  52. #ifdef __BORLANDC__
  53. namespace BansheeEngine
  54. {
  55. using namespace std;
  56. }
  57. #endif
  58. extern "C" {
  59. # include <sys/types.h>
  60. # include <sys/stat.h>
  61. }
  62. #if BS_PLATFORM == BS_PLATFORM_WIN32
  63. # undef min
  64. # undef max
  65. # if !defined(NOMINMAX) && defined(_MSC_VER)
  66. # define NOMINMAX // required to stop windows.h messing up std::min
  67. # endif
  68. # if defined( __MINGW32__ )
  69. # include <unistd.h>
  70. # endif
  71. #endif
  72. #if BS_PLATFORM == BS_PLATFORM_LINUX
  73. extern "C" {
  74. # include <unistd.h>
  75. # include <dlfcn.h>
  76. }
  77. #endif
  78. #if BS_PLATFORM == BS_PLATFORM_APPLE
  79. extern "C" {
  80. # include <unistd.h>
  81. # include <sys/param.h>
  82. # include <CoreFoundation/CoreFoundation.h>
  83. }
  84. #endif
  85. namespace BansheeEngine
  86. {
  87. // Standard containers, for easier access in my own namespace
  88. template <typename T, typename A = StdAlloc<T>>
  89. using Deque = std::deque<T, A>;
  90. template <typename T, typename A = StdAlloc<T>>
  91. using Vector = std::vector<T, A>;
  92. template <typename T, typename A = StdAlloc<T>>
  93. using List = std::list<T, A>;
  94. template <typename T, typename A = StdAlloc<T>>
  95. using Stack = std::stack<T, std::deque<T, A>>;
  96. template <typename T, typename A = StdAlloc<T>>
  97. using Queue = std::queue<T, std::deque<T, A>>;
  98. template <typename T, typename P = std::less<T>, typename A = StdAlloc<T>>
  99. using Set = std::set<T, P, A>;
  100. template <typename K, typename V, typename P = std::less<K>, typename A = StdAlloc<std::pair<const K, V>>>
  101. using Map = std::map<K, V, P, A>;
  102. template <typename K, typename V, typename P = std::less<K>, typename A = StdAlloc<std::pair<const K, V>>>
  103. using MultiMap = std::multimap<K, V, P, A>;
  104. template <typename T, typename H = std::hash<T>, typename C = std::equal_to<T>, typename A = StdAlloc<T>>
  105. using UnorderedSet = std::unordered_set<T, H, C, A>;
  106. template <typename K, typename V, typename H = std::hash<K>, typename C = std::equal_to<K>, typename A = StdAlloc<std::pair<const K, V>>>
  107. using UnorderedMap = std::unordered_map<K, V, H, C, A>;
  108. template <typename K, typename V, typename H = std::hash<K>, typename C = std::equal_to<K>, typename A = StdAlloc<std::pair<const K, V>>>
  109. using UnorderedMultimap = std::unordered_multimap<K, V, H, C, A>;
  110. template <typename T>
  111. using SPtr = std::shared_ptr<T>;
  112. /**
  113. * @brief Create a new shared pointer using a custom allocator category.
  114. */
  115. template<class Type, class AllocCategory, class... Args>
  116. std::shared_ptr<Type> bs_shared_ptr_new(Args &&... args)
  117. {
  118. return std::allocate_shared<Type>(StdAlloc<Type, AllocCategory>(), std::forward<Args>(args)...);
  119. }
  120. /**
  121. * @brief Create a new shared pointer using the default allocator category.
  122. */
  123. template<class Type, class... Args>
  124. std::shared_ptr<Type> bs_shared_ptr_new(Args &&... args)
  125. {
  126. return std::allocate_shared<Type>(StdAlloc<Type, GenAlloc>(), std::forward<Args>(args)...);
  127. }
  128. /**
  129. * @brief Create a new shared pointer from a previously constructed object.
  130. * Pointer specific data will be allocated using the provided allocator category.
  131. */
  132. template<class Type, class MainAlloc = GenAlloc, class PtrDataAlloc = GenAlloc>
  133. std::shared_ptr<Type> bs_shared_ptr(Type* data)
  134. {
  135. return std::shared_ptr<Type>(data, &bs_delete<Type, MainAlloc>, StdAlloc<Type, PtrDataAlloc>());
  136. }
  137. }