/Rainman2/binaryattrib.h

http://modstudio2.googlecode.com/ · C Header · 51 lines · 12 code · 2 blank · 37 comment · 0 complexity · 56a7e84440d2acbbab7bf01f3915cee7 MD5 · raw file

  1. /*
  2. Copyright (c) 2008 Peter "Corsix" Cawley
  3. Permission is hereby granted, free of charge, to any person
  4. obtaining a copy of this software and associated documentation
  5. files (the "Software"), to deal in the Software without
  6. restriction, including without limitation the rights to use,
  7. copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the
  9. Software is furnished to do so, subject to the following
  10. conditions:
  11. The above copyright notice and this permission notice shall be
  12. included in all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  14. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  15. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  16. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  17. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  18. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. #pragma once
  23. #include "attributes.h"
  24. //! Semantic method for linking types and their equivalent codes in binary attrib files
  25. /*!
  26. All types which can be found in binary attrib files have a code associated with them,
  27. which usually precedes the actual value. Having these codes done in this form allows
  28. for things like BinaryAttribDataTypeCode<char*>::code to be placed into source files,
  29. rather than the meaningless `3`.
  30. */
  31. template <class T> struct BinaryAttribDataTypeCode {};
  32. template <> struct BinaryAttribDataTypeCode<float> {static const long code = 0;};
  33. template <> struct BinaryAttribDataTypeCode<long> {static const long code = 1;};
  34. template <> struct BinaryAttribDataTypeCode<bool> {static const long code = 2;};
  35. template <> struct BinaryAttribDataTypeCode<char*> {static const long code = 3;};
  36. template <> struct BinaryAttribDataTypeCode<wchar_t*> {static const long code = 4;};
  37. template <> struct BinaryAttribDataTypeCode<IAttributeTable> {static const long code = 100;};
  38. //! Semantic method for converting between boolean values and their encoded form in binary attrib files
  39. /*!
  40. true and false are represented by a single byte 1 and 0 respectively. Having this
  41. information in the form below allows things like BinaryAttribBooleanEncoding<true>::value
  42. to be placed into source files, rather than the ambiguous `1`.
  43. */
  44. template <bool b> struct BinaryAttribBooleanEncoding {};
  45. template <> struct BinaryAttribBooleanEncoding<true> {static const unsigned char value = 1;};
  46. template <> struct BinaryAttribBooleanEncoding<false> {static const unsigned char value = 0;};