enginePrimitives.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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( bool );
  31. DECLARE_PRIMITIVE( S8 );
  32. DECLARE_PRIMITIVE( U8 );
  33. DECLARE_PRIMITIVE( S32 );
  34. DECLARE_PRIMITIVE( U32 );
  35. DECLARE_PRIMITIVE( F32 );
  36. DECLARE_PRIMITIVE( F64 );
  37. DECLARE_PRIMITIVE( void* );
  38. //FIXME: this allows String to be used as a struct field type
  39. // String is special in the way its data is exchanged through the API. Through
  40. // calls, strings are passed as plain, null-terminated UTF-16 character strings.
  41. // In addition, strings passed back as return values from engine API functions
  42. // are considered to be owned by the API layer itself. The rule here is that such
  43. // a string is only valid until the next API call is made. Usually, control layers
  44. // will immediately copy and convert strings to their own string type.
  45. _DECLARE_TYPE( String );
  46. template<>
  47. struct EngineTypeTraits< String > : public _EnginePrimitiveTypeTraits< String >
  48. {
  49. typedef const UTF16* ArgumentValueType;
  50. typedef const UTF16* ReturnValueType;
  51. //FIXME: this needs to be sorted out; for now, we store default value literals in ASCII
  52. typedef const char* DefaultArgumentValueStoreType;
  53. static const UTF16* ReturnValue( const String& str )
  54. {
  55. static String sTemp;
  56. sTemp = str;
  57. return sTemp.utf16();
  58. }
  59. };
  60. // For struct fields, String cannot be used directly but "const UTF16*" must be used
  61. // instead. Make sure this works with the template machinery by redirecting the type
  62. // back to String.
  63. template<> struct EngineTypeTraits< const UTF16* > : public EngineTypeTraits< String > {};
  64. template<> inline const EngineTypeInfo* TYPE< const UTF16* >() { return TYPE< String >(); }
  65. inline const EngineTypeInfo* TYPE( const UTF16*& ) { return TYPE< String >(); }
  66. #endif // !_ENGINEPRIMITIVES_H_