tamlWriteNode.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 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 _TAML_WRITE_NODE_H_
  23. #define _TAML_WRITE_NODE_H_
  24. #ifndef _TAML_CUSTOM_H_
  25. #include "persistence/taml/tamlCustom.h"
  26. #endif
  27. #ifndef _SIMBASE_H_
  28. #include "sim/simBase.h"
  29. #endif
  30. #ifndef _VECTOR_H_
  31. #include "collection/vector.h"
  32. #endif
  33. //-----------------------------------------------------------------------------
  34. class TamlCallbacks;
  35. //-----------------------------------------------------------------------------
  36. /// @ingroup tamlGroup
  37. /// @see tamlGroup
  38. class TamlWriteNode
  39. {
  40. public:
  41. class FieldValuePair
  42. {
  43. public:
  44. FieldValuePair( StringTableEntry name, const char* pValue )
  45. {
  46. // Set the field name.
  47. mName = name;
  48. // Allocate and copy the value.
  49. mpValue = new char[ dStrlen(pValue)+1 ];
  50. dStrcpy( (char *)mpValue, pValue );
  51. }
  52. StringTableEntry mName;
  53. const char* mpValue;
  54. };
  55. public:
  56. TamlWriteNode()
  57. {
  58. // NOTE: This MUST be done before the state is reset otherwise we'll be touching uninitialized stuff.
  59. mRefToNode = NULL;
  60. mpSimObject = NULL;
  61. mpTamlCallbacks = NULL;
  62. mpObjectName = NULL;
  63. mChildren = NULL;
  64. resetNode();
  65. }
  66. void set( SimObject* pSimObject )
  67. {
  68. // Sanity!
  69. AssertFatal( pSimObject != NULL, "Cannot set a write node with a NULL sim object." );
  70. // Reset the node.
  71. resetNode();
  72. // Set sim object.
  73. mpSimObject = pSimObject;
  74. // Fetch name.
  75. const char* pObjectName = pSimObject->getName();
  76. // Assign name usage.
  77. if ( pObjectName != NULL &&
  78. pObjectName != StringTable->EmptyString &&
  79. dStrlen( pObjectName ) > 0 )
  80. {
  81. mpObjectName = pObjectName;
  82. }
  83. // Find Taml callbacks.
  84. mpTamlCallbacks = dynamic_cast<TamlCallbacks*>( mpSimObject );
  85. }
  86. void resetNode( void );
  87. U32 mRefId;
  88. TamlWriteNode* mRefToNode;
  89. SimObject* mpSimObject;
  90. TamlCallbacks* mpTamlCallbacks;
  91. const char* mpObjectName;
  92. Vector<TamlWriteNode::FieldValuePair*> mFields;
  93. Vector<TamlWriteNode*>* mChildren;
  94. TamlCustomNodes mCustomNodes;
  95. };
  96. #endif // _TAML_WRITE_NODE_H_