My Project
|
file object. More...
#include <ParaScriptingIO.h>
Public Member Functions | |
ParaFileObject (boost::shared_ptr< CParaFile > pFile) | |
bool | IsValid () |
whether file is valid | |
void | close () |
Close the current file. More... | |
int | SetSegment (int nFromByte, int nByteCount) |
by setting the segment, we can inform NPL that we only transmit the file content in the segment to a remote place. More... | |
const char * | GetBase64StringEx (int *pnStrLength=0) |
get base 64 string of the binary data in the current file segment. More... | |
const char * | GetBase64String () |
void | seek (int offset) |
always call seek(0) if one opens a old file for overwritten | |
void | seekRelative (int offset) |
int | getpos () |
get current reader or writer cursor position offset in bytes | |
void | SetFilePointer (int lDistanceToMove, int dwMoveMethod) |
The SetFilePointer function moves the file pointer of an open file. More... | |
bool | SetEndOfFile () |
The SetEndOfFile function moves the end-of-file (EOF) position for the specified file to the current position of the file pointer.This function can be used to truncate or extend a file. More... | |
void | writeline (const char *str) |
const char * | readline () |
read line as a string. More... | |
const char * | GetText () |
get the content of the file as text. More... | |
const std::string & | GetText2 (int fromPos, int nCount) |
get the content of the file as text between two positions. More... | |
const std::string & | ReadString (int nCount) |
read a binary string of length nCount from current position. More... | |
void | WriteString (const char *str) |
write a string to the current file. More... | |
void | WriteString2 (const char *buffer, int nSize) |
write a buffer to the current file. More... | |
void | write (const char *buffer, int nSize) |
write a buffer to the current file. More... | |
int | WriteBytes (int nSize, const object &input) |
write bytes to file; e.g. More... | |
object | ReadBytes (int nSize, const object &output) |
read bytes from file. More... | |
void | WriteFloat (float value) |
float is 32 bits | |
float | ReadFloat () |
void | WriteWord (int value) |
integer is converted 16 bits unsigned word | |
int | ReadWord () |
void | WriteDouble (double value) |
double | ReadDouble () |
void | WriteInt (int value) |
integer is 32 bits | |
int | ReadInt () |
void | WriteShort (int value) |
integer is 16 bits signed int | |
int | ReadShort () |
void | WriteUInt (unsigned int value) |
integer is 32 bits unsigned | |
unsigned int | ReadUInt () |
int | GetFileSize () |
get the file size in bytes. More... | |
Public Attributes | |
boost::shared_ptr< CParaFile > | m_pFile |
int | m_nFromByte |
int | m_nByteCount |
std::string | m_sTempBuffer |
file object.
Always call close() when finished with the file.
void ParaScripting::ParaFileObject::close | ( | ) |
Close the current file.
const char * ParaScripting::ParaFileObject::GetBase64StringEx | ( | int * | pnStrLength = 0 | ) |
get base 64 string of the binary data in the current file segment.
to change segment, use SetSegment.
pnStrLength | [out] length of the returned string. |
int ParaScripting::ParaFileObject::GetFileSize | ( | ) |
get the file size in bytes.
const char * ParaScripting::ParaFileObject::GetText | ( | ) |
get the content of the file as text.
Text encoding is escaped. If you want to get the raw file text with the heading BOM, such as utf8 (EE BB BF), use GetText2(0,-1)
const std::string & ParaScripting::ParaFileObject::GetText2 | ( | int | fromPos, |
int | nCount | ||
) |
get the content of the file as text between two positions.
fromPos | position in bytes. |
nCount | nCount in bytes. if -1, it defaults to end of file. |
read bytes from file.
e.g. local data={};local nBytes = file:ReadBytes(3, data); data[1], data[2], data[3]
nSize | number of bytes to read. if negative, it will be total file size |
output | in/out, it should be an empty table. When the function returns, it will contain an array of integers, each represents a byte if output is nil or "", the returned value will also be a string(may contain \0) of the content read |
const char * ParaScripting::ParaFileObject::readline | ( | ) |
read line as a string.
The string is guaranteed to be ended with '\0'. if end of file is reached, it will return NULL. which is nil in the script. if a line begins with "--", it is automatically recognized as a comment line and will be skipped. a blank line will also be skipped.
const std::string & ParaScripting::ParaFileObject::ReadString | ( | int | nCount | ) |
read a binary string of length nCount from current position.
nCount | nCount in bytes. if -1, it defaults to end of file. |
bool ParaScripting::ParaFileObject::SetEndOfFile | ( | ) |
The SetEndOfFile function moves the end-of-file (EOF) position for the specified file to the current position of the file pointer.This function can be used to truncate or extend a file.
If the file is extended, the contents of the file between the old EOF position and the new position are not defined.
void ParaScripting::ParaFileObject::SetFilePointer | ( | int | lDistanceToMove, |
int | dwMoveMethod | ||
) |
The SetFilePointer function moves the file pointer of an open file.
this function only works when the ParaFile object is an actual windows file, instead of a virtual file. for virtual file, use the seek and seekRelative function.
lDistanceToMove | |
dwMoveMethod | 0: FILE_BEGIN The starting point is 0 (zero) or the beginning of the file. 1: FILE_CURRENT The starting point is the current value of the file pointer. 2: FILE_END The starting point is the current end-of-file position. |
int ParaScripting::ParaFileObject::SetSegment | ( | int | nFromByte, |
int | nByteCount | ||
) |
by setting the segment, we can inform NPL that we only transmit the file content in the segment to a remote place.
it also affects the returned result of the GetBase64String.
nFromByte | from which byte |
nByteCount | number of bytes of the segment. if -1, it is end of file. |
void ParaScripting::ParaFileObject::write | ( | const char * | buffer, |
int | nSize | ||
) |
write a buffer to the current file.
int ParaScripting::ParaFileObject::WriteBytes | ( | int | nSize, |
const object & | input | ||
) |
write bytes to file; e.g.
local nBytes = file:WriteBytes(3, {[1]=255, [2]=0, [3]=128});
nSize | number of bytes to write |
input | array of integers, each represents a byte |
void ParaScripting::ParaFileObject::WriteString | ( | const char * | str | ) |
write a string to the current file.
void ParaScripting::ParaFileObject::WriteString2 | ( | const char * | buffer, |
int | nSize | ||
) |
write a buffer to the current file.