enginePrimitives.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _ENGINEPRIMITIVES_H_
  23. #define _ENGINEPRIMITIVES_H_
  24. #ifndef _ENGINETYPES_H_
  25. #include "console/engineTypes.h"
  26. #endif
  27. /// @file
  28. /// Definitions for the core primitive types used in the
  29. /// exposed engine API.
  30. DECLARE_PRIMITIVE_R( bool );
  31. DECLARE_PRIMITIVE_R(S8);
  32. DECLARE_PRIMITIVE_R(U8);
  33. DECLARE_PRIMITIVE_R(S32);
  34. DECLARE_PRIMITIVE_R(U32);
  35. DECLARE_PRIMITIVE_R(F32);
  36. DECLARE_PRIMITIVE_R(F64);
  37. DECLARE_PRIMITIVE_R(U64);
  38. DECLARE_PRIMITIVE_R(S64);
  39. DECLARE_PRIMITIVE_R(void*);
  40. //FIXME: this allows String to be used as a struct field type
  41. // String is special in the way its data is exchanged through the API. Through
  42. // calls, strings are passed as plain, null-terminated UTF-16 character strings.
  43. // In addition, strings passed back as return values from engine API functions
  44. // are considered to be owned by the API layer itself. The rule here is that such
  45. // a string is only valid until the next API call is made. Usually, control layers
  46. // will immediately copy and convert strings to their own string type.
  47. _DECLARE_TYPE_R(String);
  48. template<>
  49. struct EngineTypeTraits< String > : public _EnginePrimitiveTypeTraits< String >
  50. {
  51. typedef const UTF16* ArgumentValueType;
  52. typedef const UTF16* ReturnValueType;
  53. //FIXME: this needs to be sorted out; for now, we store default value literals in ASCII
  54. typedef const char* DefaultArgumentValueStoreType;
  55. static const UTF16* ReturnValue( const String& str )
  56. {
  57. static String sTemp;
  58. sTemp = str;
  59. return sTemp.utf16();
  60. }
  61. };
  62. // For struct fields, String cannot be used directly but "const UTF16*" must be used
  63. // instead. Make sure this works with the template machinery by redirecting the type
  64. // back to String.
  65. template<> struct EngineTypeTraits< const UTF16* > : public EngineTypeTraits< String > {};
  66. template<> inline const EngineTypeInfo* TYPE< const UTF16* >() { return TYPE< String >(); }
  67. inline const EngineTypeInfo* TYPE( const UTF16*& ) { return TYPE< String >(); }
  68. #endif // !_ENGINEPRIMITIVES_H_