Leaked source code of windows server 2003
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.

152 lines
4.5 KiB

  1. //+-------------------------------------------------------------------------
  2. // Microsoft OLE
  3. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  4. // All rights reserved.
  5. //
  6. // File: chancend.cxx
  7. //
  8. // Contents: Implementation for ChanceNode objects.
  9. //
  10. // Classes: ChanceNode
  11. //
  12. // Functions: ChanceNode
  13. // ~ChanceNode
  14. // AppendChildStorage
  15. // AppendSisterStorage
  16. //
  17. // History: DeanE 12-Mar-96 Created
  18. //--------------------------------------------------------------------------
  19. #include <dfheader.hxx>
  20. #pragma hdrstop
  21. // Debug object declaration
  22. //
  23. DH_DECLARE;
  24. //+--------------------------------------------------------------------------
  25. // Member: ChanceNode::ChanceNode, public
  26. //
  27. // Synopsis: Constructor. Initializes object with the values passed.
  28. //
  29. // Arguments: [cStg] - Number of direct child storages of this node
  30. // [cStm] - Number of streams to create in this node
  31. // [cbStmMin] - Minimum number of bytes/stream.
  32. // [cbStmMax] - Maximum number of bytes/stream.
  33. //
  34. // Returns: Nothing.
  35. //
  36. // History: DeanE 12-Mar-96 Created
  37. //---------------------------------------------------------------------------
  38. ChanceNode::ChanceNode(
  39. ULONG cStg,
  40. ULONG cStm,
  41. ULONG cbStmMin,
  42. ULONG cbStmMax) : _pcnChild(NULL),
  43. _pcnSister(NULL),
  44. _pcnParent(NULL),
  45. _cStorages(cStg),
  46. _cStreams(cStm),
  47. _cbMinStream(cbStmMin),
  48. _cbMaxStream(cbStmMax)
  49. {
  50. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("ChanceNode ctor"));
  51. DH_ASSERT(cbStmMin <= cbStmMax);
  52. }
  53. //+--------------------------------------------------------------------------
  54. // Member: ChanceNode::~ChanceNode, public
  55. //
  56. // Synopsis: Destructor. Deletes any children and sisters.
  57. //
  58. // Arguments: None.
  59. //
  60. // Returns: Nothing.
  61. //
  62. // History: DeanE 12-Mar-96 Created
  63. //---------------------------------------------------------------------------
  64. ChanceNode::~ChanceNode()
  65. {
  66. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("ChanceNode dtor"));
  67. delete _pcnChild;
  68. delete _pcnSister;
  69. }
  70. //+--------------------------------------------------------------------------
  71. // Member: ChanceNode::AppendChildStorage, public
  72. //
  73. // Synopsis: Appends the node passed to the end of this nodes' child
  74. // node chain.
  75. //
  76. // Arguments: [pcnNew] - The new node to append.
  77. //
  78. // Returns: S_OK for success or an error code.
  79. //
  80. // History: DeanE 12-Mar-96 Created
  81. //---------------------------------------------------------------------------
  82. HRESULT ChanceNode::AppendChildStorage(ChanceNode *pcnNew)
  83. {
  84. ChanceNode *pcnTrav = this;
  85. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("ChanceNode::AppendChildStorage"));
  86. // Find the last child in the structure
  87. //
  88. while (NULL != pcnTrav->_pcnChild)
  89. {
  90. pcnTrav = pcnTrav->_pcnChild;
  91. }
  92. // Append the new node as a child of the last node,
  93. // increase the number of storages of the last node,
  94. // and make the new node point to the last node as it's parent
  95. //
  96. pcnTrav->_pcnChild = pcnNew;
  97. pcnTrav->_cStorages++;
  98. pcnNew->_pcnParent = pcnTrav;
  99. return(S_OK);
  100. }
  101. //+--------------------------------------------------------------------------
  102. // Member: ChanceNode::AppendSisterStorage, public
  103. //
  104. // Synopsis: Appends the node passed to the end of this nodes' sister
  105. // node chain.
  106. //
  107. // Arguments: [pcnNew] - The new node to append.
  108. //
  109. // Returns: S_OK for success or an error code.
  110. //
  111. // History: DeanE 12-Mar-96 Created
  112. //---------------------------------------------------------------------------
  113. HRESULT ChanceNode::AppendSisterStorage(ChanceNode *pcnNew)
  114. {
  115. ChanceNode *pcnTrav = this;
  116. DH_FUNCENTRY(NULL, DH_LVL_DFLIB, _TEXT("ChanceNode::AppendSisterStorage"));
  117. // Find the last sister of this node
  118. //
  119. while (NULL != pcnTrav->_pcnSister)
  120. {
  121. pcnTrav = pcnTrav->_pcnSister;
  122. }
  123. // Append the new node as a sister of the last node,
  124. // increase the number of storages of this nodes' parent,
  125. // and make the new node point to this nodes parent as it's parent
  126. //
  127. pcnTrav->_pcnSister = pcnNew;
  128. pcnTrav->_pcnParent->_cStorages++;
  129. pcnNew->_pcnParent = pcnTrav->_pcnParent;
  130. return(S_OK);
  131. }