2
0

tamlWriteNode.h 3.5 KB

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