OpenBarnyard
 
Loading...
Searching...
No Matches
TFile Class Referenceabstract

#include <TFile.h>

Inheritance diagram for TFile:
TNativeFile TNullFile

Public Member Functions

 TFile (TFileSystem *a_pFS)
 
 TFile (const TFile &a_rOther)
 
virtual TSIZE Read (void *a_pDst, TSIZE a_uiSize)=0
 Reads specified number of bytes from the file into the buffer.
 
virtual TSIZE Write (const void *a_pSrc, TSIZE a_uiSize)=0
 Writes specified number of bytes to the file from the buffer.
 
virtual TBOOL Seek (TINT a_iOffset, TSEEK a_eOrigin=TSEEK_CUR)=0
 Shifts current file cursor based on the specified offset and origin.
 
virtual TSIZE Tell ()=0
 
virtual void FlushBuffers ()
 Flushes write buffers.
 
virtual TSIZE GetSize ()=0
 
virtual TUINT64 GetDate ()
 
virtual TCHAR GetCChar ()=0
 Reads one character of type TCHAR from the file.
 
virtual TWCHAR GetWChar ()=0
 Reads one character of type wchar from the file.
 
virtual TINT PutCChar (TCHAR a_cCharacter)=0
 Writes one character of type TCHAR to the file.
 
virtual TINT PutWChar (TWCHAR a_wcCharacter)=0
 Writes one character of type wchar to the file.
 
virtual TINT CPrintf (const TCHAR *a_szFormat,...)=0
 Analogue of printf but writes result to the file.
 
virtual TINT WPrintf (const TWCHAR *a_wszFormat,...)=0
 Analogue of wprintf but writes result to the file.
 
virtual ~TFile ()
 
TFileSystemGetFileSystem () const
 
void Destroy ()
 

Static Public Member Functions

static TString8 ConcatPath (const TString8 &a_rcPath1, const TString8 &a_rcPath2)
 
static TString8 SimplifyPath (const TString8 &a_rcPath)
 
static TFileCreate (const TString8 &a_rcFilename, TFILEMODE a_eMode=TFILEMODE_READ)
 

Detailed Description

Definition at line 127 of file TFile.h.

Constructor & Destructor Documentation

◆ TFile() [1/2]

TFile::TFile ( TFileSystem * a_pFS)

Definition at line 13 of file TFile.cpp.

14{
15 m_pFileSystem = pFS;
16}

◆ TFile() [2/2]

TFile::TFile ( const TFile & a_rOther)

Definition at line 18 of file TFile.cpp.

19{
20 m_pFileSystem = other.GetFileSystem();
21}

◆ ~TFile()

TFile::~TFile ( )
virtual

Definition at line 24 of file TFile.cpp.

25{
26}

Member Function Documentation

◆ ConcatPath()

TString8 TFile::ConcatPath ( const TString8 & a_rcPath1,
const TString8 & a_rcPath2 )
static

Definition at line 48 of file TFile.cpp.

49{
50 TString8 strResult;
51
52 TINT iPath1StartPos = 0;
53 TINT iPath2StartPos = 0;
54
55 // Copy filesystem/volume name from a_rcPath1 or a_rcPath2
56 // prioritizing the one in a_rcPath2
57 TINT iColonPos = a_rcPath2.FindReverse( ':' );
58
59 if ( iColonPos == -1 )
60 {
61 iColonPos = a_rcPath1.FindReverse( ':' );
62
63 if ( iColonPos > -1 )
64 {
65 // Copy volume/filesystem name from the first path
66 iPath1StartPos = iColonPos + 1;
67 strResult.Concat( a_rcPath1, iPath1StartPos );
68 }
69 }
70 else
71 {
72 // Copy volume/filesystem name from the second path
73 iPath2StartPos = iColonPos + 1;
74 strResult.Concat( a_rcPath2, iPath2StartPos );
75
76 // Ignore everything before the ':' character in the first path
77 iPath1StartPos = a_rcPath1.FindReverse( ':' ) + 1;
78 }
79
80 TINT iPath1Length = a_rcPath1.Length();
81 TINT iPath2Length = a_rcPath2.Length();
82
83 if ( iPath2StartPos < iPath2Length &&
84 ( a_rcPath2[ iPath2StartPos ] == '/' || a_rcPath2[ iPath2StartPos ] == '\\' ) )
85 {
86 // The second path starts from a filesystem/volume root so ignore the first path
87 strResult += a_rcPath2.GetString( iPath2StartPos );
88 }
89 else
90 {
91 // Concat the first path with the second one trimming parts like 'C:' or 'native:' and etc.
92 strResult += a_rcPath1.GetString( iPath1StartPos );
93 if ( iPath1StartPos < iPath1Length && iPath2StartPos < iPath2Length &&
94 a_rcPath1[ iPath1Length - 1 ] != '/' && a_rcPath1[ iPath1Length - 1 ] != '\\' )
95 {
96 strResult += "/";
97 }
98
99 strResult += a_rcPath2.GetString( iPath2StartPos );
100 }
101
102 return SimplifyPath( strResult );
103}
int TINT
Definition Typedefs.h:7
static TString8 SimplifyPath(const TString8 &a_rcPath)
Definition TFile.cpp:106
TString8 & Concat(const TString8 &str, TINT size=-1)
Definition TString8.h:66
TINT FindReverse(TCHAR a_findChar, TINT pos=-1) const
Definition TString8.cpp:234
TINT Length() const
Definition TString8.h:93
const TCHAR * GetString(TINT a_iIndex=0) const
Definition TString8.cpp:286

◆ CPrintf()

virtual TINT TFile::CPrintf ( const TCHAR * a_szFormat,
... )
pure virtual

Analogue of printf but writes result to the file.

Returns
number of characters written

Implemented in TNativeFile.

◆ Create()

TFile * TFile::Create ( const TString8 & a_rcFilename,
TFILEMODE a_eMode = TFILEMODE_READ )
static

Definition at line 29 of file TFile.cpp.

30{
31 TASSERT( filename.IsIndexValid( 0 ), "filename is empty" );
32
33 TFile* pFile = TFileManager::GetSingletonSafe()->CreateFile( filename, mode );
34
35 if ( pFile != TNULL )
36 {
37 TTRACE( "TFile::Create - Created file %s with mode %hu\n", filename.GetString(), mode );
38 }
39 else
40 {
41 TTRACE( "TFile::Create - Failed to create file %s with mode %hu\n", filename.GetString(), mode );
42 }
43
44 return pFile;
45}
#define TASSERT(X,...)
Definition Defines.h:138
#define TTRACE(...)
Definition Defines.h:155
#define TNULL
Definition Typedefs.h:23
TFile(TFileSystem *a_pFS)
Definition TFile.cpp:13
TFile * CreateFile(const TString8 &a_strName, TFILEMODE flags)
static TFORCEINLINE TFileManager * GetSingletonSafe()
Definition TSingleton.h:37

◆ Destroy()

void TFile::Destroy ( )

Definition at line 184 of file TFile.cpp.

185{
186 TVALIDPTR( m_pFileSystem );
187 m_pFileSystem->DestroyFile( this );
188}
#define TVALIDPTR(PTR)
Definition Defines.h:139

◆ FlushBuffers()

virtual void TFile::FlushBuffers ( )
inlinevirtual

Flushes write buffers.

Reimplemented in TNativeFile.

Definition at line 165 of file TFile.h.

165{}

◆ GetCChar()

virtual TCHAR TFile::GetCChar ( )
pure virtual

Reads one character of type TCHAR from the file.

Returns
the read character

Implemented in TNativeFile.

◆ GetDate()

virtual TUINT64 TFile::GetDate ( )
inlinevirtual
Returns
last write time

Reimplemented in TNativeFile.

Definition at line 176 of file TFile.h.

176{ return 0; }

◆ GetFileSystem()

TFileSystem * TFile::GetFileSystem ( ) const
inline

Definition at line 216 of file TFile.h.

217 {
218 return m_pFileSystem;
219 }

◆ GetSize()

virtual TSIZE TFile::GetSize ( )
pure virtual
Returns
size of the file

Implemented in TNativeFile.

◆ GetWChar()

virtual TWCHAR TFile::GetWChar ( )
pure virtual

Reads one character of type wchar from the file.

Returns
the read character

Implemented in TNativeFile.

◆ PutCChar()

virtual TINT TFile::PutCChar ( TCHAR a_cCharacter)
pure virtual

Writes one character of type TCHAR to the file.

Returns
code of the written character

Implemented in TNativeFile.

◆ PutWChar()

virtual TINT TFile::PutWChar ( TWCHAR a_wcCharacter)
pure virtual

Writes one character of type wchar to the file.

Returns
number of written bytes

Implemented in TNativeFile.

◆ Read()

virtual TSIZE TFile::Read ( void * a_pDst,
TSIZE a_uiSize )
pure virtual

Reads specified number of bytes from the file into the buffer.

Parameters
a_pDstdestination buffer
a_uiSizenumber of bytes to read
Returns
the number of read bytes

Implemented in TNativeFile.

◆ Seek()

virtual TBOOL TFile::Seek ( TINT a_iOffset,
TSEEK a_eOrigin = TSEEK_CUR )
pure virtual

Shifts current file cursor based on the specified offset and origin.

Parameters
a_iOffsetnumber of characters to shift the position
a_eOriginposition to which a_iOffset is added
Returns
TTRUE if succeeded

Implemented in TNativeFile.

◆ SimplifyPath()

TString8 TFile::SimplifyPath ( const TString8 & a_rcPath)
static

Definition at line 106 of file TFile.cpp.

107{
108 TString8 strPath = a_rcPath;
109 FixPathSlashesBack( strPath );
110
111 TINT iPos = 0;
112 TString8 strResult;
113
114 // Keep filesystem/volume/protocol name in the simplified path and leave it as it is
115 TINT iColonPos = strPath.FindReverse( ':' );
116 if ( iColonPos > -1 )
117 {
118 iPos = iColonPos + 1;
119 strResult.Concat( strPath, iPos );
120 }
121
122 if ( strPath[ iPos ] == '/' )
123 {
124 iPos += 1;
125 strResult += "/";
126 }
127
128 TINT iInitialResultLength = strResult.Length();
129 TINT iResultLength = iInitialResultLength;
130
131 strPath += "/";
132 TINT iSlashPos = strPath.Find( '/', iPos );
133
134 do
135 {
136 // Is the path over?
137 if ( iSlashPos < 0 )
138 {
139 if ( iInitialResultLength < strResult.Length() )
140 {
141 strResult.Truncate( strResult.Length() - 1 );
142 }
143
144 return strResult;
145 }
146
147 if ( !strncmp( strPath.GetString( iPos ), "../", 3 ) )
148 {
149 if ( iResultLength == strResult.Length() )
150 {
151 // Can't go back to a previous dir since it's the only one
152 strResult += "../";
153 iResultLength += 3;
154 }
155 else
156 {
157 // Truncate the path removing the current dir
158 TINT iTruncateTo;
159
160 if ( strResult.Length() > 1 && ( iTruncateTo = strResult.FindReverse( '/', strResult.Length() - 2 ), iResultLength <= iTruncateTo ) )
161 {
162 strResult.Truncate( iTruncateTo + 1 );
163 }
164 else
165 {
166 strResult.Truncate( iResultLength );
167 }
168 }
169 }
170 // Add anything except './'
171 else if ( strncmp( strPath.GetString( iPos ), "./", 2 ) != 0 )
172 {
173 strResult.Concat( strPath.GetString( iPos ), ( iSlashPos - iPos ) + 1 );
174 }
175
176 iPos = iSlashPos + 1;
177 iSlashPos = strPath.Find( '/', iPos );
178
179 } while ( TTRUE );
180}
void FixPathSlashesBack(TString8 &a_rPath)
#define TTRUE
Definition Typedefs.h:25
TINT Find(TCHAR character, TINT pos=0) const
Definition TString8.cpp:107
void Truncate(TINT length)
Definition TString8.cpp:257

◆ Tell()

virtual TSIZE TFile::Tell ( )
pure virtual
Returns
current position of the file cursor

Implemented in TNativeFile.

◆ WPrintf()

virtual TINT TFile::WPrintf ( const TWCHAR * a_wszFormat,
... )
pure virtual

Analogue of wprintf but writes result to the file.

Returns
number of characters written

Implemented in TNativeFile.

◆ Write()

virtual TSIZE TFile::Write ( const void * a_pSrc,
TSIZE a_uiSize )
pure virtual

Writes specified number of bytes to the file from the buffer.

Parameters
a_pSrcsourde buffer
a_uiSizenumber of bytes to write
Returns
the number of written bytes

Implemented in TNativeFile.


The documentation for this class was generated from the following files: