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.

64 lines
1.7 KiB

  1. #ifndef _CSTREAM_INCLUDED
  2. #define _CSTREAM_INCLUDED
  3. static const UINT CSTREAM_BUF_SIZE = (64 * 1024);
  4. static const UINT HFILE_NOTREAD = ((UINT) -2);
  5. static const UINT DUAL_CSTREAM_BUF_SIZE = (8 * 1024);
  6. #define chEOF ((unsigned char) 255)
  7. class CStream
  8. {
  9. public:
  10. CStream(PCSTR pszFileName);
  11. ~CStream(void);
  12. int STDCALL seek(int pos, SEEK_TYPE seek = SK_SET);
  13. int Remaining() { return (int)(pEndBuf - pCurBuf); };
  14. #ifndef _DEBUG
  15. char cget() {
  16. if (pCurBuf < pEndBuf)
  17. return (char) *pCurBuf++;
  18. else if (pEndBuf < pbuf + cbBuf) {
  19. m_fEndOfFile = TRUE;
  20. return chEOF; // WARNING! check m_fEndOfFile to confirm return of chEOF is valid
  21. }
  22. else
  23. return ReadBuf();
  24. };
  25. #else
  26. char cget();
  27. #endif
  28. int tell(void) const { return lFileBuf + (int)(pCurBuf - pbuf); };
  29. BOOL STDCALL doRead(void* pbDst, int cbBytes) {
  30. return (read(pbDst, cbBytes) == (UINT) cbBytes);
  31. }
  32. UINT STDCALL read(void* pbDst, int cbBytes);
  33. char ReadBuf(void);
  34. friend DWORD WINAPI ReadAhead(LPVOID pv);
  35. void Cleanup(void);
  36. BOOL fInitialized;
  37. PBYTE pCurBuf; // current position in the buffer
  38. PBYTE pEndBuf; // last position in buffer
  39. BOOL m_fEndOfFile;
  40. HFILE hfile; // file handle
  41. protected:
  42. void WaitForReadAhead(void);
  43. int lFilePos; // position in the file
  44. int lFileBuf; // file position at first of buffer
  45. PBYTE pbuf; // address of allocated buffer
  46. PSTR pszFile; // copy of the filename
  47. int cbBuf; // buffer size
  48. int cThrdRead; // result from read-ahead thread
  49. HANDLE hthrd;
  50. DWORD idThrd;
  51. BOOL fDualCPU;
  52. };
  53. #endif // _CSTREAM_INCLUDED