Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cFileTextReader.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cFileTextReader_H
7 #define _INC_cFileTextReader_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "cFile.h"
13 #include "cStreamStack.h"
14 #include "cTextPos.h"
15 
16 namespace Gray
17 {
19  {
25 
26  cStreamInput& m_reader;
27 
28  protected:
29  cStreamTextReader(cStreamInput& reader, size_t nSizeLineMax)
30  : cStreamStackInp(&reader, nSizeLineMax)
31  , m_reader(reader)
32  {
33  // Max buffer size = max line length.
34  this->put_AutoReadCommit((ITERATE_t)(nSizeLineMax / 2)); // default = half buffer.
35  }
36 
37  protected:
38  virtual HRESULT ReadX(void* pData, size_t nDataSize) override
39  {
40  // Use ReadStringLine instead. Prevent use of this.
41  ASSERT(0);
43  UNREFERENCED_PARAMETER(nDataSize);
44  return E_NOTIMPL;
45  }
46  virtual HRESULT WriteX(const void* pData, size_t nDataSize) override
47  {
48  // Read ONLY. Prevent use of this.
49  ASSERT(0);
51  UNREFERENCED_PARAMETER(nDataSize);
52  return E_NOTIMPL;
53  }
54 
55  HRESULT ReadStringLine(OUT const char** ppszLine);
56 
57  public:
58  virtual HRESULT ReadStringLine(OUT char* pszBuffer, StrLen_t iSizeMax) override;
59 
60  virtual STREAM_SEEKRET_t Seek(STREAM_OFFSET_t iOffset, SEEK_ORIGIN_TYPE eSeekOrigin = SEEK_Set) override;
61  };
62 
63  class GRAYCORE_LINK cFileTextReader : public cStreamTextReader
64  {
69 
70  public:
71  cFile m_File; // The backing OS file.
72 
73  public:
74  cFileTextReader(size_t nSizeLineMax = cStream::k_FILE_BLOCK_SIZE * 2);
75  virtual ~cFileTextReader();
76 
77  HRESULT OpenX(const FILECHAR_t* pszName, OF_FLAGS_t uShareFlags);
78 
79  virtual STREAM_POS_t GetLength() const override
80  {
81  return m_File.GetLength();
82  }
83  virtual void Close(void)
84  {
85  m_File.Close();
86  }
87  virtual STREAM_POS_t GetPosition() const override
88  {
89  return m_File.GetPosition() - this->get_ReadQty();
90  }
91 
92  UNITTEST_FRIEND(cFileTextReader);
93  };
94 }
95 
96 #endif
#define GRAYCORE_LINK
Definition: GrayCore.h:47
#define UNREFERENCED_PARAMETER(P)
< _WIN32 type thing. get rid of stupid warning.
Definition: SysTypes.h:299
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
#define ASSERT(exp)
Definition: cDebugAssert.h:87
#define UNITTEST_FRIEND(n)
Define this in the class body to be unit tested. Allow the unit test to access private/protected stuf...
Definition: cUnitTestDecl.h:17
static const size_t k_FILE_BLOCK_SIZE
default arbitrary transfer block size. more than this is NOT more efficient.
Definition: cStream.h:89
Definition: cStream.h:306
Definition: cStreamStack.h:17
Definition: cFileTextReader.h:19
virtual HRESULT WriteX(const void *pData, size_t nDataSize) override
Definition: cFileTextReader.h:46
cStreamTextReader(cStreamInput &reader, size_t nSizeLineMax)
Definition: cFileTextReader.h:29
virtual HRESULT ReadX(void *pData, size_t nDataSize) override
Definition: cFileTextReader.h:38
< The main namespace for all Core functions.
Definition: GrayCore.cpp:14
LONG_PTR STREAM_OFFSET_t
Might be 64 or 32 bit. TODO SET USE_FILE_POS64.
Definition: cOSHandle.h:52
int StrLen_t
the length of a string in chars (bytes for UTF8, wchar_t for UNICODE). or offset in characters....
Definition: StrConst.h:32
UINT32 OF_FLAGS_t
Mask of file open flags OF_FLAGS_TYPE_.
Definition: cFile.h:77
LONG_PTR STREAM_SEEKRET_t
return from Seek()
Definition: cOSHandle.h:53
int ITERATE_t
like size_t but signed
Definition: Index.h:28
char FILECHAR_t
a UTF8 char in a file name. like TCHAR
Definition: FileName.h:22
ULONG_PTR STREAM_POS_t
NOT same as FILE_SIZE_t in 32 bit. Why not ?
Definition: cOSHandle.h:54
SEEK_ORIGIN_TYPE
Definition: cOSHandle.h:34
@ SEEK_Set
SEEK_SET = FILE_BEGIN = STREAM_SEEK_SET = 0 = relative to the start of the file.
Definition: cOSHandle.h:39