FileBuffer.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. class TFileBuffer
  12. {
  13. public:
  14. __fastcall TFileBuffer();
  15. virtual __fastcall ~TFileBuffer();
  16. void __fastcall Convert(char * Source, char * Dest, int Params, bool & Token);
  17. void __fastcall Convert(TEOLType Source, TEOLType Dest, int Params, bool & Token);
  18. void __fastcall Convert(char * Source, TEOLType Dest, int Params, bool & Token);
  19. void __fastcall Convert(TEOLType Source, char * Dest, int Params, bool & Token);
  20. void __fastcall Insert(int Index, const char * Buf, int Len);
  21. void __fastcall Delete(int Index, int Len);
  22. DWORD __fastcall LoadStream(TStream * Stream, const DWORD Len, bool ForceLen);
  23. DWORD __fastcall ReadStream(TStream * Stream, const DWORD Len, bool ForceLen);
  24. void __fastcall WriteToStream(TStream * Stream, const DWORD Len);
  25. __property TMemoryStream * Memory = { read=FMemory, write=SetMemory };
  26. __property char * Data = { read=GetData };
  27. __property int Size = { read=FSize, write=SetSize };
  28. __property int Position = { read=GetPosition, write=SetPosition };
  29. private:
  30. TMemoryStream * FMemory;
  31. int FSize;
  32. void __fastcall SetMemory(TMemoryStream * value);
  33. char * __fastcall GetData() const { return (char *)FMemory->Memory; }
  34. void __fastcall SetSize(int value);
  35. void __fastcall SetPosition(int value);
  36. int __fastcall GetPosition() const;
  37. };
  38. //---------------------------------------------------------------------------
  39. class TSafeHandleStream : public THandleStream
  40. {
  41. public:
  42. __fastcall TSafeHandleStream(int AHandle);
  43. virtual int __fastcall Read(void * Buffer, int Count);
  44. virtual int __fastcall Write(const void * Buffer, int Count);
  45. virtual int __fastcall Read(System::DynamicArray<System::Byte> Buffer, int Offset, int Count);
  46. virtual int __fastcall Write(const System::DynamicArray<System::Byte> Buffer, int Offset, int Count);
  47. };
  48. //---------------------------------------------------------------------------
  49. char * __fastcall EOLToStr(TEOLType EOLType);
  50. //---------------------------------------------------------------------------
  51. #endif