Source code of Windows XP (NT5)
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.

186 lines
3.1 KiB

  1. /**********************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1987-1999 **/
  4. /**********************************************************************/
  5. /*
  6. buffer.hxx
  7. MIDL Compiler Buffer Manager Definition
  8. This class manages two-way infinite buffer of string pointers.
  9. */
  10. /*
  11. FILE HISTORY :
  12. DonnaLi 09-11-1990 Created.
  13. */
  14. #ifndef __BUFFER_HXX__
  15. #define __BUFFER_HXX__
  16. #include "stream.hxx"
  17. class BufferElement
  18. {
  19. public:
  20. BufferElement * pPrev;
  21. BufferElement * pNext;
  22. char ** pBuffer;
  23. BufferElement(
  24. BufferElement * pPrevElem,
  25. BufferElement * pNextElem,
  26. char ** pNewBuf)
  27. {
  28. pPrev = pPrevElem;
  29. pNext = pNextElem;
  30. pBuffer = pNewBuf;
  31. }
  32. ~BufferElement()
  33. {
  34. delete pBuffer;
  35. }
  36. BufferElement * ExtendPrev(char ** pNewBuf)
  37. {
  38. if (pPrev)
  39. {
  40. return pPrev;
  41. }
  42. else
  43. {
  44. return pPrev = new BufferElement(NULL, this, pNewBuf);
  45. }
  46. }
  47. BufferElement * ExtendNext(char ** pNewBuf)
  48. {
  49. if (pNext)
  50. {
  51. return pNext;
  52. }
  53. else
  54. {
  55. return pNext = new BufferElement(this, NULL, pNewBuf);
  56. }
  57. }
  58. BufferElement * GetPrev()
  59. {
  60. return pPrev;
  61. }
  62. BufferElement * GetNext()
  63. {
  64. return pNext;
  65. }
  66. };
  67. class BufferManager
  68. {
  69. char ** pszTable;
  70. unsigned short usTabSize;
  71. unsigned short usBufSize;
  72. BufferElement * pSave;
  73. BufferElement * pHead;
  74. BufferElement * pTail;
  75. unsigned short iHead;
  76. unsigned short iTail;
  77. public:
  78. BufferManager(unsigned short);
  79. BufferManager(unsigned short, unsigned short, const char * []);
  80. ~BufferManager()
  81. {
  82. BufferElement * pCur = pHead;
  83. BufferElement * pNext;
  84. while ( pCur )
  85. {
  86. pNext = pCur->pNext;
  87. delete pCur;
  88. pCur = pNext;
  89. }
  90. }
  91. void Clear()
  92. {
  93. if ( pHead != pTail )
  94. {
  95. BufferElement * pCur = pHead;
  96. BufferElement * pNext;
  97. while ( pCur )
  98. {
  99. pNext = pCur->pNext;
  100. if ( pCur != pSave )
  101. delete pCur;
  102. pCur = pNext;
  103. }
  104. }
  105. pHead = pTail = pSave;
  106. pSave->pNext = NULL;
  107. pSave->pPrev = NULL;
  108. iHead = iTail = unsigned short( usBufSize - 2 );
  109. }
  110. void Print(ISTREAM *);
  111. void ConcatHead(char * psz)
  112. {
  113. BufferElement * pTemp;
  114. if (iHead == 0)
  115. {
  116. pTemp = pHead->ExtendPrev(new (char *[usBufSize]));
  117. iHead = unsigned short( usBufSize-1 );
  118. pHead = pTemp;
  119. pHead->pBuffer[iHead] = psz;
  120. }
  121. else
  122. {
  123. pHead->pBuffer[--iHead] = psz;
  124. }
  125. }
  126. void ConcatHead(unsigned short iIndex)
  127. {
  128. MIDL_ASSERT( iIndex < usTabSize );
  129. ConcatHead( pszTable[iIndex] );
  130. }
  131. void ConcatTail(char * psz)
  132. {
  133. BufferElement * pTemp;
  134. if (iTail == usBufSize)
  135. {
  136. pTemp = pTail->ExtendNext(new (char *[usBufSize]));
  137. iTail = 0;
  138. pTail = pTemp;
  139. pTail->pBuffer[iTail++] = psz;
  140. }
  141. else
  142. {
  143. pTail->pBuffer[iTail++] = psz;
  144. }
  145. }
  146. void ConcatTail(unsigned short iIndex)
  147. {
  148. MIDL_ASSERT( iIndex < usTabSize );
  149. ConcatTail( pszTable[iIndex] );
  150. }
  151. };
  152. #endif // __BUFFER_HXX__