propertyParsing.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 _PROPERTYPARSING_H_
  23. #define _PROPERTYPARSING_H_
  24. class ColorI;
  25. class LinearColorF;
  26. class Point2I;
  27. class Point2F;
  28. class Point3F;
  29. class Point4F;
  30. class Point3I;
  31. class Point4I;
  32. class RectI;
  33. class RectF;
  34. class Box3I;
  35. class Box3F;
  36. class MatrixF;
  37. class AngAxisF;
  38. class QuatF;
  39. class String;
  40. class FileName;
  41. class SimObject;
  42. class SimObjectType;
  43. template<class T> class Vector;
  44. //-----------------------------------------------------------------------------
  45. // String scan/print methods
  46. //
  47. // Macros in propertyImplementation.h point the ConcretePropertyDefinition scan/print delegates to these functions.
  48. //
  49. namespace PropertyInfo
  50. {
  51. // String
  52. bool default_scan(const String &data, String & result);
  53. bool default_print(String & result, const String & data);
  54. // Bool
  55. bool default_scan(const String &data, bool & result);
  56. bool default_print(String & result, const bool & data);
  57. // S32/F32/U32
  58. bool default_scan(const String &data, F32 & result);
  59. bool default_print(String & result, const F32 & data);
  60. bool default_scan(const String &data, U32 & result);
  61. bool default_print(String & result, const U32 & data);
  62. bool default_scan(const String &data, S32 & result);
  63. bool default_print(String & result, const S32 & data);
  64. // Vector<S32/F32/U32>
  65. bool default_scan(const String &data, Vector<F32> & result);
  66. bool default_print(String & result, const Vector<F32> & data);
  67. bool default_scan(const String &data, Vector<U32> & result);
  68. bool default_print(String & result, const Vector<U32> & data);
  69. bool default_scan(const String &data, Vector<S32> & result);
  70. bool default_print(String & result, const Vector<S32> & data);
  71. // Math Points
  72. bool default_scan(const String &data, Point2F & result);
  73. bool default_print(String & result, const Point2F & data);
  74. bool default_scan(const String &data, Point2I & result);
  75. bool default_print(String & result, const Point2I & data);
  76. bool default_scan(const String &data, Point3F & result);
  77. bool default_print(String & result, const Point3F & data);
  78. bool default_scan(const String &data, Point3I & result);
  79. bool default_print(String & result, const Point3I & data);
  80. bool default_scan(const String &data, Point4F & result);
  81. bool default_print(String & result, const Point4F & data);
  82. bool default_scan(const String &data, Point4I & result);
  83. bool default_print(String & result, const Point4I & data);
  84. // Math Boxs & Rectangles
  85. bool default_scan(const String &data, RectI & result);
  86. bool default_print(String & result, const RectI & data);
  87. bool default_scan(const String &data, RectF & result);
  88. bool default_print(String & result, const RectF & data);
  89. bool default_scan(const String &data, Box3I & result);
  90. bool default_print(String & result, const Box3I & data);
  91. bool default_scan(const String &data, Box3F & result);
  92. bool default_print(String & result, const Box3F & data);
  93. //-----------------------------------------------------------------------------
  94. bool default_scan( const String &data, AngAxisF & result );
  95. bool default_print( String & result, const AngAxisF & data );
  96. bool default_scan( const String &data, QuatF & result );
  97. bool default_print( String & result, const QuatF & data );
  98. bool default_scan( const String &data, MatrixF & result );
  99. bool default_print( String & result, const MatrixF & data );
  100. // Colors
  101. bool default_scan(const String &data, LinearColorF & result);
  102. bool default_print(String & result, const LinearColorF & data);
  103. bool default_scan(const String &data, ColorI & result);
  104. bool default_print(String & result, const ColorI & data);
  105. // filename handler
  106. bool default_scan(const String &data, FileName & result);
  107. bool default_print(String & result, const FileName & data);
  108. // SimObjectType
  109. bool default_scan(const String &data, SimObjectType & result);
  110. bool default_print(String & result, SimObjectType const & data);
  111. // SimObject
  112. bool default_scan(const String &data, SimObject * & result);
  113. bool default_print(String & result, SimObject * const & data);
  114. template<class T>
  115. inline bool typed_simobject_scan(const String &data, T * & result)
  116. {
  117. SimObject * obj;
  118. result = default_scan(data,obj)? dynamic_cast<T*>(obj) : NULL;
  119. return result;
  120. }
  121. template<class T>
  122. inline bool typed_simobject_print(String & result, T * const & data)
  123. {
  124. return default_print(result,data);
  125. }
  126. bool hex_scan(const String & string, U32 & hex);
  127. bool hex_print(String & string, const U32 & hex);
  128. bool hex_scan(const String & string, S32 & hex);
  129. bool hex_print(String & string, const S32 & hex);
  130. bool hex_scan(const String & string, U16 & hex);
  131. bool hex_print(String & string, const U16 & hex);
  132. bool hex_scan(const String & string, S16 & hex);
  133. bool hex_print(String & string, const S16 & hex);
  134. bool hex_scan(const String & string, U8 & hex);
  135. bool hex_print(String & string, const U8 & hex);
  136. bool hex_scan(const String & string, S8 & hex);
  137. bool hex_print(String & string, const S8 & hex);
  138. bool default_print(String & result, SimObjectType * const & data);
  139. }
  140. // Default Scan/print definition
  141. #define DEFINE_PROPERTY_DEFAULT_PRINT(dataType) bool PropertyInfo::default_print(String & resultString, dataType const & dataTyped)
  142. #define DEFINE_PROPERTY_DEFAULT_SCAN(dataType) bool PropertyInfo::default_scan(const String &dataString, dataType & resultTyped)
  143. #endif // _PROPERTYPARSING_H_