Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
4.5 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "toolutils/attributeelementchoicelist.h"
  9. #include "datamodel/dmelement.h"
  10. #include "datamodel/dmattributevar.h"
  11. typedef CUtlRBTree< CDmElement *, int > ElementDict_t;
  12. //-----------------------------------------------------------------------------
  13. // returns the choice string that AddElementsRecursively would have returned
  14. //-----------------------------------------------------------------------------
  15. const char *GetChoiceString( CDmElement *pElement )
  16. {
  17. return pElement->GetName();
  18. }
  19. //-----------------------------------------------------------------------------
  20. // Recursively adds all elements referred to this element into the list of elements
  21. //-----------------------------------------------------------------------------
  22. void AddElementsRecursively_R( CDmElement *pElement, ElementChoiceList_t &list, ElementDict_t &dict, const char *pElementType )
  23. {
  24. if ( !pElement )
  25. return;
  26. if ( dict.Find( pElement ) != dict.InvalidIndex() )
  27. return;
  28. dict.Insert( pElement );
  29. if ( pElement->IsA( pElementType ) )
  30. {
  31. int nIndex = list.AddToTail( );
  32. ElementChoice_t &entry = list[nIndex];
  33. entry.m_pValue = pElement;
  34. entry.m_pChoiceString = GetChoiceString( pElement );
  35. }
  36. for ( CDmAttribute *pAttribute = pElement->FirstAttribute(); pAttribute; pAttribute = pAttribute->NextAttribute() )
  37. {
  38. char const *attributeName = pAttribute->GetName( );
  39. DmAttributeType_t attrType = pAttribute->GetType( );
  40. if ( attrType == AT_ELEMENT )
  41. {
  42. CDmElement *pChild = pElement->GetValueElement< CDmElement >( attributeName );
  43. AddElementsRecursively_R( pChild, list, dict, pElementType );
  44. }
  45. else if ( attrType == AT_ELEMENT_ARRAY )
  46. {
  47. const CDmrElementArray<CDmElement> children( pElement, attributeName );
  48. uint n = children.Count();
  49. for ( uint i = 0; i < n; ++i )
  50. {
  51. CDmElement *pChild = children[ i ];
  52. AddElementsRecursively_R( pChild, list, dict, pElementType );
  53. }
  54. }
  55. }
  56. }
  57. //-----------------------------------------------------------------------------
  58. // Recursively adds all elements referred to this element into the list of elements
  59. //-----------------------------------------------------------------------------
  60. void AddElementsRecursively_R( CDmElement *pElement, DmeHandleVec_t &list, ElementDict_t &dict, const char *pElementType )
  61. {
  62. if ( !pElement )
  63. return;
  64. if ( dict.Find( pElement ) != dict.InvalidIndex() )
  65. return;
  66. dict.Insert( pElement );
  67. if ( pElement->IsA( pElementType ) )
  68. {
  69. int nIndex = list.AddToTail( );
  70. list[nIndex] = pElement;
  71. }
  72. for ( CDmAttribute *pAttribute = pElement->FirstAttribute(); pAttribute; pAttribute = pAttribute->NextAttribute() )
  73. {
  74. char const *attributeName = pAttribute->GetName( );
  75. DmAttributeType_t attrType = pAttribute->GetType( );
  76. if ( attrType == AT_ELEMENT )
  77. {
  78. CDmElement *pChild = pElement->GetValueElement< CDmElement >( attributeName );
  79. AddElementsRecursively_R( pChild, list, dict, pElementType );
  80. }
  81. else if ( attrType == AT_ELEMENT_ARRAY )
  82. {
  83. const CDmrElementArray<CDmElement> children( pElement, attributeName );
  84. uint n = children.Count();
  85. for ( uint i = 0; i < n; ++i )
  86. {
  87. CDmElement *pChild = children[ i ];
  88. AddElementsRecursively_R( pChild, list, dict, pElementType );
  89. }
  90. }
  91. }
  92. }
  93. //-----------------------------------------------------------------------------
  94. // Recursively adds all elements referred to this element into the list of elements
  95. //-----------------------------------------------------------------------------
  96. void AddElementsRecursively( CDmElement *obj, ElementChoiceList_t &list, const char *pElementType )
  97. {
  98. if ( !pElementType )
  99. {
  100. pElementType = CDmElement::GetStaticTypeSymbol().String();
  101. }
  102. ElementDict_t dict( 0, 0, DefLessFunc( CDmElement * ) );
  103. AddElementsRecursively_R( obj, list, dict, pElementType );
  104. }
  105. //-----------------------------------------------------------------------------
  106. // Recursively adds all elements of the specified type under pElement into the vector
  107. //-----------------------------------------------------------------------------
  108. void AddElementsRecursively( CDmElement *pElement, DmeHandleVec_t &list, const char *pElementType )
  109. {
  110. if ( !pElementType )
  111. {
  112. pElementType = CDmElement::GetStaticTypeSymbol().String();
  113. }
  114. ElementDict_t dict( 0, 0, DefLessFunc( CDmElement * ) );
  115. AddElementsRecursively_R( pElement, list, dict, pElementType );
  116. }