adesk.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2015 Autodesk, Inc. All rights reserved.
  4. //
  5. // Use of this software is subject to the terms of the Autodesk license
  6. // agreement provided at the time of installation or download, or which
  7. // otherwise accompanies this software in either electronic or hard copy form.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. //
  11. // DESCRIPTION:
  12. //
  13. // This file contains the extension to the standard set of primitive-
  14. // type names that should be shared by all Autodesk developers, both
  15. // in-house and third-party. All new code and modules written in C++
  16. // should use these type names along with those supplied by C++ itself
  17. // (for example, int, long, float, double, etc.)
  18. //
  19. // Note that C++ 11 (and VC11) now provide standard fixed size integer types
  20. // such as int16_t, int32_t, etc, and those are now used here. Developers
  21. // are encouraged to migrate over to using the standard C++ types and
  22. // the Adesk::Int* and UInt* types may eventually be deprecated.
  23. //
  24. // See adeskabb.h for abbreviations of the following names.
  25. #ifndef _ADESK_H
  26. #define _ADESK_H
  27. #include <stdint.h> // int16_t, uint32_t, etc
  28. #include "AdAChar.h" // ACHAR typedef
  29. #if __LP64__
  30. // We need this defined on the 64-bit OS X builds to avoid
  31. // method overloading conficts between Adesk::Int32 and
  32. // Adesk::Boolean.
  33. //
  34. // We also receive better type checking when Boolean is bool
  35. #define Adesk_Boolean_is_bool 1
  36. #define Adesk_Int32_is_int 1
  37. #endif
  38. #pragma pack (push, 8)
  39. #if defined(_MSC_VER)
  40. // Use _MSC_VER to detect that we are building on Windows. This
  41. // test will need to be updated a bit when we start supporting the Intel
  42. // compiler.
  43. //
  44. #define _ADESK_WINDOWS_ 1
  45. #ifndef stdgnu
  46. #define stdgnu std
  47. #endif
  48. #ifndef stdtr1
  49. #define stdtr1 std::tr1
  50. #endif
  51. #elif defined(__APPLE__) && defined(__MACH__)
  52. #define _ADESK_MAC_ 1
  53. #define __w64
  54. #if __LP64__
  55. #define _AC64
  56. #endif //__LP64__
  57. #ifdef _LIBCPP_VERSION
  58. //Clang libc++
  59. #ifndef stdgnu
  60. #define stdgnu std
  61. #endif
  62. #ifndef stdtr1
  63. #define stdtr1 std
  64. #endif
  65. #else
  66. //GCC libstdc++
  67. #define _GCCSTDLIB_
  68. #ifndef stdgnu
  69. #define stdgnu __gnu_cxx
  70. #endif
  71. #ifndef stdtr1
  72. #define stdtr1 std::tr1
  73. #endif
  74. #endif
  75. #endif //defined(__APPLE__) && defined(__MACH__)
  76. struct Adesk
  77. {
  78. // The types Int8, Int16 and Int32 will be conditionally compiled
  79. // to guarantee that each one represents an integer type of exactly
  80. // 8, 16 and 32 bits respectively. These are to be used only when
  81. // the EXACT size of the integer is critical.
  82. //
  83. // We also need to be sure to use the Adesk::Int32 and Adesk::UInt32
  84. // datatypes rather than a long now that we support OSX 64-bit builds.
  85. //
  86. // Unlike Windows-64, on OSX-64 , a long is 64-bits. Any code that
  87. // assumes sizeof(int) == sizeof(long) will potentially have bugs. The
  88. // fix is to consistently use Adesk::Int32 and Adesk::UInt32 in place
  89. // of longs so we can normalize this all between the two platforms.
  90. //
  91. typedef int8_t Int8;
  92. typedef int16_t Int16;
  93. //
  94. // The unsigned versions of the above types.
  95. //
  96. typedef uint8_t UInt8;
  97. typedef uint16_t UInt16;
  98. #ifdef Adesk_Int32_is_int
  99. typedef int32_t Int32;
  100. typedef uint32_t UInt32;
  101. #ifndef Adesk_Boolean_is_bool
  102. #error Boolean_is_bool must be defined if Int32_is_int
  103. #endif
  104. #else
  105. // can't use int if Adesk::Boolean is already using it..
  106. typedef unsigned long UInt32;
  107. typedef long Int32;
  108. #endif
  109. typedef int64_t Int64;
  110. typedef uint64_t UInt64;
  111. // Convenient abbreviations (use optionally).
  112. // Todo: consider removing these from adesk.h
  113. //
  114. typedef unsigned char uchar;
  115. typedef unsigned short ushort;
  116. typedef unsigned int uint;
  117. // integer/unsigned integers that can hold a pointer value.
  118. // These change size depending on the platform and should NEVER
  119. // be streamed out to permanent storage.
  120. #if !defined(_WIN64) && !defined (_AC64)
  121. static_assert(sizeof(long) == 4, "long size in 32-bit windows build?");
  122. static_assert(sizeof(void *) == 4, "ptr size in 32-bit windows build?");
  123. // Using __w64 let's us catch potential errors at compile time
  124. // when /Wp64 is enabled. Also, we use long, instead of int,
  125. // in the 32-bit build. That's for compatibility with the Int32
  126. // and UInt32 types.
  127. //
  128. typedef __w64 long LongPtr;
  129. typedef __w64 unsigned long ULongPtr;
  130. //
  131. typedef __w64 int IntPtr;
  132. typedef __w64 unsigned int UIntPtr;
  133. #else // _WIN64 || _AC64
  134. static_assert(sizeof(void *) == 8, "ptr size in 64-bit build?");
  135. typedef int64_t LongPtr;
  136. typedef uint64_t ULongPtr;
  137. typedef int64_t IntPtr;
  138. typedef uint64_t UIntPtr;
  139. #endif // _WIN64 || _AC64
  140. typedef LongPtr IntDbId;
  141. typedef IntPtr GsMarker;
  142. // Logical type (Note: never use int when Boolean is intended!)
  143. // Please transition from Boolean type to native bool..
  144. //
  145. #ifdef Adesk_Boolean_is_bool
  146. typedef bool Boolean;
  147. static const bool kFalse = false;
  148. static const bool kTrue = true;
  149. #else
  150. typedef int Boolean;
  151. enum { kFalse = 0, kTrue = 1 };
  152. #endif
  153. };
  154. // Please transition from NULL macro to native nullptr..
  155. #undef NULL
  156. #define NULL 0
  157. #ifdef _ADESK_MAC_
  158. #ifdef nil
  159. #undef nil
  160. #endif
  161. #define nil __DARWIN_NULL
  162. #endif
  163. #pragma pack (pop)
  164. // Use ADESK_NO_VTABLE on base classes which:
  165. // 1. have virtual methods
  166. // 2. are never instantiated
  167. // 3. have a ctor and/or a dtor
  168. // 4. do not call any virtual methods in the ctor or dtor
  169. // This allows the compiler to avoid assigning a vtable pointer at
  170. // the top of the base class's ctor and dtor. So the vtable itself
  171. // and any methods it points to which aren't used elsewhere can be
  172. // omitted by the linker and reduce overall space.
  173. //
  174. // Make sure though that the base class is never instantiated. Making
  175. // the ctor protected or using pure virtual methods can help with this.
  176. //
  177. #if defined(_MSC_VER)
  178. #define ADESK_NO_VTABLE __declspec(novtable)
  179. #define ADESK_STDCALL __stdcall
  180. #define ADESK_DEPRECATED __declspec(deprecated)
  181. #define ADESK_DEPRECATED_MSG(MSG) __declspec(deprecated(MSG))
  182. #define ADESK_DATA_IMPORT __declspec(dllimport)
  183. #else
  184. #define ADESK_NO_VTABLE
  185. // The GCC 4.0 compiler doesn't seem to support the stdcall attribute
  186. // for 64-bit builds. If we use it, we just get a ton of warnings
  187. // from the compiler mentioning that it isn't supported.
  188. #if defined(__LP64__) || defined(_ADESK_IOS_)
  189. #define ADESK_STDCALL
  190. #else
  191. #define ADESK_STDCALL __attribute__((stdcall))
  192. #endif // __LP64__
  193. #define ADESK_DEPRECATED __attribute__((__deprecated__))
  194. #define ADESK_DEPRECATED_MSG(MSG) __attribute__((__deprecated__))
  195. #define ADESK_DATA_IMPORT extern
  196. // Redefine __declspec(method) for gcc
  197. #define __declspec(method) __declspec_##method
  198. #define _declspec(method) __declspec_##method
  199. #define __declspec_selectany __attribute__ ((__weak__))
  200. #define __declspec_dllexport __attribute__ ((__visibility__("default")))
  201. #define __declspec_dllimport
  202. #define __declspec_noinline __attribute__ ((__noinline__))
  203. #define __declspec_noreturn __attribute__ ((__noreturn__))
  204. #define __declspec_deprecated __attribute__ ((__deprecated__))
  205. #define __declspec_novtable
  206. #define __declspec_allocate(name) __attribute__ ((section("__DATA," name)))
  207. #endif //_MSC_VER
  208. #ifdef _MSC_EXTENSIONS
  209. #define ADESK_OVERRIDE override
  210. #if defined(_MSC_VER) && (_MSC_VER <= 1600) //VS2010 and earlier
  211. #define ADESK_SEALED sealed
  212. #else
  213. #define ADESK_SEALED final
  214. #endif
  215. #else //_MSC_EXTENSIONS
  216. #define ADESK_OVERRIDE
  217. #define ADESK_SEALED
  218. #endif //_MSC_EXTENSIONS
  219. #define MIGRATION_ERRORS
  220. #if defined(_MSC_VER) && defined (MIGRATION_ERRORS)
  221. #define ADESK_SEALED_VIRTUAL virtual
  222. #if !defined(ADESK_SEALED)
  223. #define ADESK_SEALED sealed
  224. #endif //ADESK_SEALED
  225. #else //MIGRATION_ERRORS
  226. #define ADESK_SEALED_VIRTUAL
  227. #define ADESK_SEALED
  228. #endif //MIGRATION_ERRORS
  229. //
  230. // Compiler indentification
  231. //
  232. #if defined(__INTEL_COMPILER) || defined (_MSC_VER)
  233. #define ADESK_FORCE_INLINE __forceinline
  234. #else //__INTEL_COMPILER || _MSC_VER
  235. #define ADESK_FORCE_INLINE inline
  236. #endif //__INTEL_COMPILER || _MSC_VER
  237. #ifdef _ADESK_WINDOWS_
  238. #define VA_ARG_WCHAR(ap, t) va_arg(ap, wchar_t)
  239. #else
  240. #define VA_ARG_WCHAR(ap, t) va_arg(ap, int)
  241. #endif
  242. #ifdef _ADESK_UNITTEST_
  243. #ifdef ADESK_SEALED
  244. #undef ADESK_SEALED
  245. #endif
  246. #define ADESK_SEALED
  247. #endif
  248. #endif //_ADESK_H