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.

287 lines
7.7 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1992.
  5. //
  6. // File: dffuncs.hxx
  7. //
  8. // Contents: CDocFile inline functions
  9. // In a separate file to avoid circular dependencies
  10. //
  11. // History: 06-Nov-92 DrewB Created
  12. //
  13. //----------------------------------------------------------------------------
  14. #ifndef __DFFUNCS_HXX__
  15. #define __DFFUNCS_HXX__
  16. #include <dfbasis.hxx>
  17. #include <cdocfile.hxx>
  18. #include <sstream.hxx>
  19. //+--------------------------------------------------------------
  20. //
  21. // Member: CDocFile::operator new, public
  22. //
  23. // Synopsis: Unreserved object allocator
  24. //
  25. // Arguments: [size] -- byte count to allocate
  26. // [pMalloc] -- allocator
  27. //
  28. // History: 25-May-93 AlexT Created
  29. //
  30. //---------------------------------------------------------------
  31. inline void *CDocFile::operator new(size_t size, IMalloc * const pMalloc)
  32. {
  33. return(CMallocBased::operator new(size, pMalloc));
  34. }
  35. //+--------------------------------------------------------------
  36. //
  37. // Member: CDocFile::operator new, public
  38. //
  39. // Synopsis: Reserved object allocator
  40. //
  41. // Arguments: [size] -- byte count to allocate
  42. // [pdfb] -- basis
  43. //
  44. // History: 25-May-93 AlexT Created
  45. //
  46. //---------------------------------------------------------------
  47. inline void *CDocFile::operator new(size_t size, CDFBasis * const pdfb)
  48. {
  49. olAssert(size == sizeof(CDocFile));
  50. return pdfb->GetFreeList(CDFB_DIRECTDOCFILE)->GetReserved();
  51. }
  52. //+--------------------------------------------------------------
  53. //
  54. // Member: CDocFile::ReturnToReserve, public
  55. //
  56. // Synopsis: Reserved object return
  57. //
  58. // Arguments: [pdfb] -- basis
  59. //
  60. // History: 25-May-93 AlexT Created
  61. //
  62. //---------------------------------------------------------------
  63. inline void CDocFile::ReturnToReserve(CDFBasis * const pdfb)
  64. {
  65. CDocFile::~CDocFile();
  66. pdfb->GetFreeList(CDFB_DIRECTDOCFILE)->ReturnToReserve(this);
  67. }
  68. //+--------------------------------------------------------------
  69. //
  70. // Member: CDocFile::Reserve, public
  71. //
  72. // Synopsis: Reserve instances
  73. //
  74. // Arguments: [cItems] -- count of items
  75. // [pdfb] -- basis
  76. //
  77. // History: 25-May-93 AlexT Created
  78. //
  79. //---------------------------------------------------------------
  80. inline SCODE CDocFile::Reserve(UINT cItems, CDFBasis * const pdfb)
  81. {
  82. return pdfb->Reserve(cItems, CDFB_DIRECTDOCFILE);
  83. }
  84. //+--------------------------------------------------------------
  85. //
  86. // Member: CDocFile::Unreserve, public
  87. //
  88. // Synopsis: Unreserve instances
  89. //
  90. // Arguments: [cItems] -- count of items
  91. // [pdfb] -- basis
  92. //
  93. // History: 25-May-93 AlexT Created
  94. //
  95. //---------------------------------------------------------------
  96. inline void CDocFile::Unreserve(UINT cItems, CDFBasis * const pdfb)
  97. {
  98. pdfb->Unreserve(cItems, CDFB_DIRECTDOCFILE);
  99. }
  100. //+--------------------------------------------------------------
  101. //
  102. // Member: CDocFile::CDocFile, public
  103. //
  104. // Synopsis: Empty object ctor
  105. //
  106. // Arguments: [dl] - LUID
  107. // [pdfb] - Basis
  108. //
  109. // History: 30-Mar-92 DrewB Created
  110. //
  111. //---------------------------------------------------------------
  112. inline CDocFile::CDocFile(DFLUID dl, CDFBasis *pdfb)
  113. : PDocFile(dl), _pdfb(P_TO_BP(CBasedDFBasisPtr, pdfb))
  114. {
  115. _cReferences = 0;
  116. _sig = CDOCFILE_SIG;
  117. }
  118. //+--------------------------------------------------------------
  119. //
  120. // Member: CDocFile::CDocFile, public
  121. //
  122. // Synopsis: Handle-setting construction
  123. //
  124. // Arguments: [pms] - MultiStream to use
  125. // [sid] - SID to use
  126. // [dl] - LUID
  127. // [pdfb] - Basis
  128. //
  129. // History: 29-Jan-92 DrewB Created
  130. //
  131. //---------------------------------------------------------------
  132. inline CDocFile::CDocFile(CMStream *pms,
  133. SID sid,
  134. DFLUID dl,
  135. CDFBasis *pdfb)
  136. : PDocFile(dl), _pdfb(P_TO_BP(CBasedDFBasisPtr, pdfb))
  137. {
  138. _stgh.Init(pms, sid);
  139. _cReferences = 0;
  140. _sig = CDOCFILE_SIG;
  141. }
  142. //+--------------------------------------------------------------
  143. //
  144. // Member: CDocFile::~CDocFile, public
  145. //
  146. // Synopsis: Destructor
  147. //
  148. // History: 19-Dec-91 DrewB Created
  149. //
  150. //---------------------------------------------------------------
  151. inline CDocFile::~CDocFile(void)
  152. {
  153. olAssert(_cReferences == 0);
  154. _sig = CDOCFILE_SIGDEL;
  155. if (_stgh.IsValid())
  156. {
  157. if (_stgh.IsRoot())
  158. DllReleaseMultiStream(_stgh.GetMS());
  159. }
  160. }
  161. //+---------------------------------------------------------------------------
  162. //
  163. // Member: CDocFile::GetReservedDocfile, public
  164. //
  165. // Synopsis: Gets a previously reserved object
  166. //
  167. // History: 09-Nov-92 DrewB Created
  168. //
  169. //----------------------------------------------------------------------------
  170. inline CDocFile *CDocFile::GetReservedDocfile(DFLUID luid)
  171. {
  172. CDFBasis *pdfb = BP_TO_P(CDFBasis *, _pdfb);
  173. return new(pdfb) CDocFile(luid, pdfb);
  174. }
  175. //+---------------------------------------------------------------------------
  176. //
  177. // Member: CDocFile::GetReservedStream, public
  178. //
  179. // Synopsis: Gets a previously reserved object
  180. //
  181. // History: 09-Nov-92 DrewB Created
  182. //
  183. //----------------------------------------------------------------------------
  184. inline CDirectStream *CDocFile::GetReservedStream(DFLUID luid)
  185. {
  186. return new(_pdfb) CDirectStream(luid);
  187. }
  188. //+--------------------------------------------------------------
  189. //
  190. // Member: CDocFile::GetHandle, public
  191. //
  192. // Synopsis: Returns the handle
  193. //
  194. // History: 05-Aug-92 DrewB Created
  195. //
  196. //---------------------------------------------------------------
  197. inline CStgHandle *CDocFile::GetHandle(void)
  198. {
  199. return &_stgh;
  200. }
  201. //+---------------------------------------------------------------------------
  202. //
  203. // Member: CDocFile::DecRef, public
  204. //
  205. // Synopsis: Decrements the ref count
  206. //
  207. // History: 23-Nov-92 DrewB Created
  208. //
  209. //----------------------------------------------------------------------------
  210. inline void CDocFile::DecRef(void)
  211. {
  212. AtomicDec(&_cReferences);
  213. }
  214. //+---------------------------------------------------------------------------
  215. //
  216. // Member: CDocFile::ReturnDocFile, public
  217. //
  218. // Synopsis: Returns a child to the freelist
  219. //
  220. // Arguments: [pdf] - Docfile
  221. //
  222. // History: 23-Nov-92 DrewB Created
  223. //
  224. //----------------------------------------------------------------------------
  225. inline void CDocFile::ReturnDocFile(CDocFile *pdf)
  226. {
  227. olDebugOut((DEB_ITRACE, "In CDocFile::ReturnDocFile:%p(%p)\n",
  228. this, pdf));
  229. // Force ref count to zero without freeing memory
  230. pdf->DecRef();
  231. pdf->ReturnToReserve(BP_TO_P(CDFBasis *, _pdfb));
  232. olDebugOut((DEB_ITRACE, "Out CDocFile::ReturnDocFile\n"));
  233. }
  234. //+---------------------------------------------------------------------------
  235. //
  236. // Member: CDocFile::ReturnStream, public
  237. //
  238. // Synopsis: Returns a stream to the freelist
  239. //
  240. // Arguments: [pstm] - Stream
  241. //
  242. // History: 23-Nov-92 DrewB Created
  243. //
  244. //----------------------------------------------------------------------------
  245. inline void CDocFile::ReturnStream(CDirectStream *pstm)
  246. {
  247. olDebugOut((DEB_ITRACE, "In CDocFile::ReturnStream:%p(%p)\n",
  248. this, pstm));
  249. // Force ref count to zero without freeing memory
  250. pstm->DecRef();
  251. pstm->ReturnToReserve(BP_TO_P(CDFBasis *, _pdfb));
  252. olDebugOut((DEB_ITRACE, "Out CDocFile::ReturnStream\n"));
  253. }
  254. #endif // #ifndef __DFFUNCS_HXX__