forked from AppleWin/AppleWin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtil_MemoryTextFile.h
More file actions
48 lines (37 loc) · 957 Bytes
/
Copy pathUtil_MemoryTextFile.h
File metadata and controls
48 lines (37 loc) · 957 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#pragma once
// Memory Text File _________________________________________________________
class MemoryTextFile_t
{
std::vector<char > m_vBuffer;
std::vector<char *> m_vLines ; // array of pointers to start of lines
bool m_bDirty ; // line pointers not up-to-date
void GetLinePointers();
public:
MemoryTextFile_t()
// : m_nSize( 0 )
// , m_pBuffer( 0 )
// , m_nLines( 0 )
: m_bDirty( false )
{
m_vBuffer.reserve( 2048 );
m_vLines.reserve( 128 );
}
bool Read( TCHAR *pFileName );
void Reset()
{
m_vBuffer.erase( m_vBuffer.begin(), m_vBuffer.end() );
m_vLines.erase( m_vLines.begin(), m_vLines.end() );
}
inline int GetNumLines()
{
if (m_bDirty)
GetLinePointers();
return m_vLines.size();
}
inline char *GetLine( const int iLine ) const
{
return m_vLines.at( iLine );
}
void GetLine( const int iLine, char *pLine, const int n );
void PushLine( char *pLine );
};