2006-02-26 06:27:51 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-03-13 16:37:25 +00:00
|
|
|
#include "StrFormat.h"
|
|
|
|
|
2006-02-26 06:27:51 +00:00
|
|
|
// Memory Text File _________________________________________________________
|
|
|
|
|
|
|
|
class MemoryTextFile_t
|
|
|
|
{
|
2014-08-14 19:29:01 +00:00
|
|
|
std::vector<char > m_vBuffer;
|
|
|
|
std::vector<char *> m_vLines ; // array of pointers to start of lines
|
2006-02-26 06:27:51 +00:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2019-09-06 16:34:25 +00:00
|
|
|
bool Read( const std::string & pFileName );
|
2006-02-26 06:27:51 +00:00
|
|
|
void Reset()
|
|
|
|
{
|
2022-03-12 11:19:34 +00:00
|
|
|
m_vBuffer.clear();
|
|
|
|
m_vLines.clear();
|
2006-02-26 06:27:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
2022-03-13 16:37:25 +00:00
|
|
|
void PushLine( const char *pLine );
|
|
|
|
void PushLineFormat( const char *pFormat, ... ) ATTRIBUTE_FORMAT_PRINTF(2, 3); // 1 is "this"
|
2006-02-26 06:27:51 +00:00
|
|
|
};
|
|
|
|
|