tamlWriteNode.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. dsize_t valueLen = dStrlen(pValue) + 1;
  48. mpValue = new char[ valueLen ];
  49. dStrcpy( (char *)mpValue, pValue, valueLen );
  50. }
  51. StringTableEntry mName;
  52. const char* mpValue;
  53. };
  54. public:
  55. TamlWriteNode()
  56. {
  57. // NOTE: This MUST be done before the state is reset otherwise we'll be touching uninitialized stuff.
  58. mRefToNode = NULL;
  59. mpSimObject = NULL;
  60. mpTamlCallbacks = NULL;
  61. mpObjectName = NULL;
  62. mChildren = NULL;
  63. resetNode();
  64. }
  65. void set( SimObject* pSimObject )
  66. {
  67. // Sanity!
  68. AssertFatal( pSimObject != NULL, "Cannot set a write node with a NULL sim object." );
  69. // Reset the node.
  70. resetNode();
  71. // Set sim object.
  72. mpSimObject = pSimObject;
  73. // Fetch name.
  74. const char* pObjectName = pSimObject->getName();
  75. // Assign name usage.
  76. if ( pObjectName != NULL &&
  77. pObjectName != StringTable->EmptyString() &&
  78. dStrlen( pObjectName ) > 0 )
  79. {
  80. mpObjectName = pObjectName;
  81. }
  82. // Find Taml callbacks.
  83. mpTamlCallbacks = dynamic_cast<TamlCallbacks*>( mpSimObject );
  84. }
  85. void resetNode( void );
  86. U32 mRefId;
  87. TamlWriteNode* mRefToNode;
  88. SimObject* mpSimObject;
  89. TamlCallbacks* mpTamlCallbacks;
  90. const char* mpObjectName;
  91. Vector<TamlWriteNode::FieldValuePair*> mFields;
  92. Vector<TamlWriteNode*>* mChildren;
  93. TamlCustomNodes mCustomNodes;
  94. };
  95. #endif // _TAML_WRITE_NODE_H_