FileBuffer.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //---------------------------------------------------------------------------
  2. #ifndef FileBufferH
  3. #define FileBufferH
  4. #include <classes.hpp>
  5. //---------------------------------------------------------------------------
  6. extern const wchar_t * EOLTypeNames;
  7. enum TEOLType { eolLF /* \n */, eolCRLF /* \r\n */, eolCR /* \r */ };
  8. const int cpRemoveCtrlZ = 0x01;
  9. const int cpRemoveBOM = 0x02;
  10. //---------------------------------------------------------------------------
  11. typedef void __fastcall (__closure *TTransferOutEvent)(TObject * Sender, const unsigned char * Data, size_t Len);
  12. typedef size_t __fastcall (__closure *TTransferInEvent)(TObject * Sender, unsigned char * Data, size_t Len);
  13. //---------------------------------------------------------------------------
  14. class TFileBuffer
  15. {
  16. public:
  17. __fastcall TFileBuffer();
  18. virtual __fastcall ~TFileBuffer();
  19. void __fastcall Convert(char * Source, char * Dest, int Params, bool & Token);
  20. void __fastcall Convert(TEOLType Source, TEOLType Dest, int Params, bool & Token);
  21. void __fastcall Convert(char * Source, TEOLType Dest, int Params, bool & Token);
  22. void __fastcall Convert(TEOLType Source, char * Dest, int Params, bool & Token);
  23. void __fastcall Insert(int Index, const char * Buf, int Len);
  24. void __fastcall Delete(int Index, int Len);
  25. DWORD __fastcall LoadStream(TStream * Stream, const DWORD Len, bool ForceLen);
  26. DWORD __fastcall ReadStream(TStream * Stream, const DWORD Len, bool ForceLen);
  27. DWORD __fastcall LoadFromIn(TTransferInEvent OnTransferIn, TObject * Sender, DWORD Len);
  28. void __fastcall WriteToStream(TStream * Stream, const DWORD Len);
  29. void __fastcall WriteToOut(TTransferOutEvent OnTransferOut, TObject * Sender, const DWORD Len);
  30. void Reset();
  31. __property TMemoryStream * Memory = { read=FMemory };
  32. __property char * Data = { read=GetData };
  33. __property int Size = { read=FSize, write=SetSize };
  34. private:
  35. TMemoryStream * FMemory;
  36. int FSize;
  37. char * __fastcall GetData() const { return (char *)FMemory->Memory; }
  38. char * __fastcall GetPointer() const { return GetData() + GetPosition(); }
  39. void NeedSpace(DWORD Size);
  40. void __fastcall SetSize(int value);
  41. int __fastcall GetPosition() const { return (int)FMemory->Position; }
  42. void __fastcall ProcessRead(DWORD Len, DWORD Result);
  43. };
  44. //---------------------------------------------------------------------------
  45. class TSafeHandleStream : public THandleStream
  46. {
  47. public:
  48. __fastcall TSafeHandleStream(int AHandle);
  49. __fastcall TSafeHandleStream(THandleStream * Source, bool Own);
  50. static TSafeHandleStream * CreateFromFile(const UnicodeString & FileName, unsigned short Mode);
  51. virtual __fastcall ~TSafeHandleStream();
  52. virtual int __fastcall Read(void * Buffer, int Count);
  53. virtual int __fastcall Write(const void * Buffer, int Count);
  54. virtual int __fastcall Read(System::DynamicArray<System::Byte> Buffer, int Offset, int Count);
  55. virtual int __fastcall Write(const System::DynamicArray<System::Byte> Buffer, int Offset, int Count);
  56. private:
  57. THandleStream * FSource;
  58. bool FOwned;
  59. };
  60. //---------------------------------------------------------------------------
  61. char * __fastcall EOLToStr(TEOLType EOLType);
  62. //---------------------------------------------------------------------------
  63. #endif