My Project
Public Member Functions | Public Attributes | List of all members
ParaScripting::ParaFileObject Class Reference

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< CParaFilem_pFile
 
int m_nFromByte
 
int m_nByteCount
 
std::string m_sTempBuffer
 

Detailed Description

file object.

Always call close() when finished with the file.

Member Function Documentation

§ close()

void ParaScripting::ParaFileObject::close ( )

Close the current file.

§ GetBase64StringEx()

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.

Parameters
pnStrLength[out] length of the returned string.
Returns
pOutString: a static global buffer containing the string. it ends with '\0'. it is NULL, if file is invalid.

§ GetFileSize()

int ParaScripting::ParaFileObject::GetFileSize ( )

get the file size in bytes.

§ GetText()

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)

§ GetText2()

const std::string & ParaScripting::ParaFileObject::GetText2 ( int  fromPos,
int  nCount 
)

get the content of the file as text between two positions.

Parameters
fromPosposition in bytes.
nCountnCount in bytes. if -1, it defaults to end of file.

§ ReadBytes()

object ParaScripting::ParaFileObject::ReadBytes ( int  nSize,
const object output 
)

read bytes from file.

e.g. local data={};local nBytes = file:ReadBytes(3, data); data[1], data[2], data[3]

Parameters
nSizenumber of bytes to read. if negative, it will be total file size
outputin/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
Returns
string or a table array

§ readline()

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.

§ ReadString()

const std::string & ParaScripting::ParaFileObject::ReadString ( int  nCount)

read a binary string of length nCount from current position.

Parameters
nCountnCount in bytes. if -1, it defaults to end of file.

§ SetEndOfFile()

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.

Returns

§ SetFilePointer()

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.

Parameters
lDistanceToMove
dwMoveMethod0: 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.

§ SetSegment()

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.

Parameters
nFromBytefrom which byte
nByteCountnumber of bytes of the segment. if -1, it is end of file.
Returns
: return the number of bytes in the segment. it is usually the same as nByteCount, unless nBytesCount exceeds the file length.

§ write()

void ParaScripting::ParaFileObject::write ( const char *  buffer,
int  nSize 
)

write a buffer to the current file.

§ WriteBytes()

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});

Parameters
nSizenumber of bytes to write
inputarray of integers, each represents a byte
Returns
: number of bytes written

§ WriteString()

void ParaScripting::ParaFileObject::WriteString ( const char *  str)

write a string to the current file.

§ WriteString2()

void ParaScripting::ParaFileObject::WriteString2 ( const char *  buffer,
int  nSize 
)

write a buffer to the current file.


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