Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
BeTextFile Struct Reference

Reads and Writes Text Files regardless of whether they are encoded on disk as locale-encoded ASCII, UTF8, or UTF16. More...

#include <BeTextFile.h>

Inheritance diagram for BeTextFile:
RefCountedBase RefCounted< IRefCounted > IRefCounted CsvFile

Public Member Functions

void Close ()
 Closes the text file. More...
 
TextFileReadStatus GetLine (WStringR textLine)
 Reads a line from the file. More...
 
TextFileWriteStatus PutLine (WCharCP textLine, bool addCarriageReturn)
 Writes a line to the file. More...
 
WChar GetChar ()
 Reads the next character from the file. More...
 
TextFileWriteStatus PrintfTo (bool toStdOutAlso, WCharCP format,...)
 Writes formatted output to the file. More...
 
BeFileStatus Rewind ()
 Rewinds the file and prepare for reading from the beginning of the text data (i.e., just past the encoding signature, if there is one). More...
 
BeFileStatus SetPointer (UInt64 position, BeFileSeekOrigin origin)
 Moves the file read/write position. More...
 
BeFileStatus GetPointer (UInt64 &position)
 Gets the file read/write position. More...
 
- Public Member Functions inherited from RefCounted< IRefCounted >
void * operator new (size_t size)
 
void operator delete (void *rawMemory, size_t size)
 
UInt32 AddRef () const
 
UInt32 Release () const
 
 RefCounted ()
 
 RefCounted (RefCounted const &rhs)
 
RefCountedoperator= (RefCounted const &rhs)
 
UInt32 GetRefCount () const
 

Static Public Member Functions

static BeTextFilePtr Open (BeFileStatus &status, WCharCP fullFileSpec, TextFileOpenType openType, TextFileOptions options, TextFileEncoding encoding=TextFileEncoding::CurrentLocale)
 Opens a text file for reading or writing. More...
 

Static Public Attributes

static const UInt32 BUFFER_SIZE = 100
 

Protected Member Functions

 BeTextFile ()
 
 ~BeTextFile ()
 
BeFileStatus OpenFile (WCharCP fullFileSpec, TextFileOpenType openType, TextFileOptions options, TextFileEncoding encoding)
 Internal method for opening a file. Use the factory method BeTextFile::Open instead. More...
 
- Protected Member Functions inherited from RefCounted< IRefCounted >
virtual ~RefCounted ()
 
- Protected Member Functions inherited from IRefCounted
virtual ~IRefCounted ()
 
void * operator new (size_t size)
 
void operator delete (void *rawMemory, size_t size)
 

Detailed Description

Reads and Writes Text Files regardless of whether they are encoded on disk as locale-encoded ASCII, UTF8, or UTF16.

Constructor & Destructor Documentation

BeTextFile ( )
protected
~BeTextFile ( )
protected

Member Function Documentation

void Close ( )

Closes the text file.

Remarks
This call is not usually necessary, as the file is closed automatically when the reference-counted pointer is released.
WChar GetChar ( )

Reads the next character from the file.

Returns
The next character or WEOF.
TextFileReadStatus GetLine ( WStringR  textLine)

Reads a line from the file.

Parameters
[out]textLineThe buffer to read the line into.
Remarks
The line is always converted to Unicode in UTF-16.
The handling of newlines is controlled by the options when opening the file.
Returns
TextFileReadStatus::Success if the line was read successfully; otherwise TextFileReadStatus::Eof or an error code.
BeFileStatus GetPointer ( UInt64 position)

Gets the file read/write position.

Parameters
[out]positionthe current read/write position
Returns
BeFileStatus::Success if the operation was successful or non-zero if it failed.
static BeTextFilePtr Open ( BeFileStatus status,
WCharCP  fullFileSpec,
TextFileOpenType  openType,
TextFileOptions  options,
TextFileEncoding  encoding = TextFileEncoding::CurrentLocale 
)
static

Opens a text file for reading or writing.

Parameters
[out]statusBeFileStatus::Success on success or the file open error.
[in]fullFileSpecName of the file to open.
[in]openTypeWhether to open the file for read, write or append.
[in]optionsOptions controlling how newline characters are treated on read.
[in]encodingEncoding for the file; use TextFileEncoding::CurrentLocale for ASCII. This parameter is used only when openType is TextFileOpenType::Write.
Remarks
When opened for read or append, the text file encoding will be read from the beginning of the file (if it is there) and the contents will be read and converted from its encoding to Unicode.
When opened for write, the encoding argument indicates how the output is to be written. If there is an existing file with the same name, that file is replaced by a new file.
Returns
A pointer to the file. If status is not BeFileStatus::Success then the pointer will fail the IsValid() check.
BeFileStatus OpenFile ( WCharCP  fullFileSpec,
TextFileOpenType  openType,
TextFileOptions  options,
TextFileEncoding  encoding 
)
protected

Internal method for opening a file. Use the factory method BeTextFile::Open instead.

TextFileWriteStatus PrintfTo ( bool  toStdOutAlso,
WCharCP  format,
  ... 
)

Writes formatted output to the file.

Parameters
[in]toStdOutAlsoTrue to also print the information to stdout.
[in]formatThe format string; see printf for the formats.
Remarks
The format string is the same as would be used in a call to the standard C wprintf function.
TextFileWriteStatus PutLine ( WCharCP  textLine,
bool  addCarriageReturn 
)

Writes a line to the file.

Parameters
[in]textLineThe buffer to read the line into.
[in]addCarriageReturnIf true, appends a newline character to the input textLine.
Remarks
The data will be converted to the encoding specified when opening the file.
Returns
TextFileWriteStatus::Success if the line was written successfully; otherwise an error code.
BeFileStatus Rewind ( )

Rewinds the file and prepare for reading from the beginning of the text data (i.e., just past the encoding signature, if there is one).

Returns
BeFileStatus::Success if the operation was successful or non-zero if it failed.
BeFileStatus SetPointer ( UInt64  position,
BeFileSeekOrigin  origin 
)

Moves the file read/write position.

Parameters
[in]positionThe new read/write position.
[in]originThe origin mode for the move.
Returns
BeFileStatus::Success if the operation was successful or non-zero if it failed.
Remarks
Use Rewind to go to the beginning of rthe text data (rather than SetPointer (0, BeFileSeekOrigin::Begin) because Rewind accounts for the encoding signature that might be at the beginning of the file.

Member Data Documentation

const UInt32 BUFFER_SIZE = 100
static

The documentation for this struct was generated from the following file:

Copyright © 2017 Bentley Systems, Incorporated. All rights reserved.