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.

131 lines
2.8 KiB

  1. /*++
  2. Copyright (C) 1995-2001 Microsoft Corporation
  3. Module Name:
  4. DataSrc.H
  5. Abstract:
  6. Declares DataSrc objects.
  7. History:
  8. a-davj 21-Dec-99 Created.
  9. --*/
  10. #ifndef _DataSrc_H_
  11. #define _DataSrc_H_
  12. #include "stdio.h"
  13. #include <helper.h>
  14. /*-----------------------------------------------------------------------
  15. GenericException
  16. -----------------------------------------------------------------------*/
  17. class GenericException
  18. {
  19. DWORD m_errorCode;
  20. public:
  21. GenericException() : m_errorCode(GetLastError()) {}
  22. GenericException( DWORD errorCode ) : m_errorCode(errorCode) {}
  23. DWORD GetErrorCode() const { return m_errorCode; }
  24. HRESULT GetHRESULT() const {return HRESULT_FROM_WIN32(m_errorCode);}
  25. };
  26. class DataSrc
  27. {
  28. public:
  29. DataSrc(): m_iPos(0), m_iSize(0), m_iStatus(0){};
  30. virtual ~DataSrc(){return;};
  31. virtual wchar_t GetAt(int nOffset) = 0;
  32. virtual void Move(int n) = 0;
  33. int GetPos(){return m_iPos;};
  34. int GetStatus(){return m_iStatus;};
  35. bool PastEnd(){return m_iPos >= m_iSize;};
  36. bool WouldBePastEnd(int iOffset){return (m_iPos+iOffset) >= m_iSize;};
  37. virtual int MoveToStart() = 0;
  38. virtual int MoveToPos(int iPos)=0;
  39. virtual TCHAR * GetFileName(){ return NULL; };
  40. protected:
  41. int m_iPos;
  42. int m_iSize;
  43. int m_iStatus;
  44. };
  45. class FileDataSrc : public DataSrc
  46. {
  47. public:
  48. FileDataSrc(TCHAR * pFileName);
  49. ~FileDataSrc();
  50. wchar_t GetAt(int nOffset);
  51. void Move(int n);
  52. int MoveToStart();
  53. int MoveToPos(int iPos);
  54. TCHAR * GetFileName(){ return m_pFileName; };
  55. private:
  56. void UpdateBuffer();
  57. FILE * m_fp;
  58. TCHAR * m_pFileName;
  59. int m_iFilePos;
  60. int m_iToFar;
  61. wchar_t m_Buff[10000];
  62. };
  63. #ifdef USE_MMF_APPROACH
  64. class FileDataSrc1 : public DataSrc
  65. {
  66. public:
  67. FileDataSrc1(TCHAR * pFileName);
  68. ~FileDataSrc1();
  69. wchar_t GetAt(int nOffset);
  70. void Move(int n);
  71. int MoveToStart();
  72. int MoveToPos(int iPos);
  73. TCHAR * GetFileName(){ return m_pFileName; };
  74. private:
  75. HANDLE m_hFile;
  76. HANDLE m_hFileMapSrc;
  77. WCHAR * m_pData;
  78. TCHAR * m_pFileName;
  79. };
  80. #endif
  81. class BufferDataSrc : public DataSrc
  82. {
  83. public:
  84. BufferDataSrc(long lSize, char * pMemSrc);
  85. ~BufferDataSrc();
  86. wchar_t GetAt(int nOffset);
  87. void Move(int n);
  88. int MoveToStart();
  89. int MoveToPos(int iPos){m_iPos = iPos; return iPos;};
  90. private:
  91. wchar_t * m_Data; // only used if type is BUFFER
  92. };
  93. class BMOFDataSrc : public DataSrc
  94. {
  95. private:
  96. TCHAR m_FileName[MAX_PATH+1];
  97. public:
  98. BMOFDataSrc(TCHAR * szFileName){ StringCchCopy(m_FileName,LENGTH_OF(m_FileName),szFileName); };
  99. TCHAR * GetFileName(){ return &m_FileName[0]; };
  100. wchar_t GetAt(int nOffset){ return 0; };
  101. void Move(int n){ };
  102. int MoveToStart(){ return 0; };
  103. int MoveToPos(int iPos){ return 0; };
  104. };
  105. #endif