Open CASCADE Technology  7.1.0.beta
Public Member Functions | Protected Attributes
OSD_File Class Reference

Basic tools to manage files Warning: 'ProgramError' is raised when somebody wants to use the methods Read, Write, Seek, Close when File is not open. More...

#include <OSD_File.hxx>

Inheritance diagram for OSD_File:
Inheritance graph
[legend]

Public Member Functions

 OSD_File ()
 Creates File object. More...
 
 OSD_File (const OSD_Path &Name)
 Instantiates the object file, storing its name. More...
 
 ~OSD_File ()
 Unlocks and closes a file, deletes a descriptor and destructs a file object. More...
 
void Build (const OSD_OpenMode Mode, const OSD_Protection &Protect)
 CREATES a file if it doesn't already exists or empties an existing file. After 'Build', the file is open. If no name was given, ProgramError is raised. More...
 
void Open (const OSD_OpenMode Mode, const OSD_Protection &Protect)
 Opens a File with specific attributes This works only on already existing file. If no name was given, ProgramError is raised. More...
 
void Append (const OSD_OpenMode Mode, const OSD_Protection &Protect)
 Appends data to an existing file. If file doesn't exist, creates it first. After 'Append', the file is open. If no name was given, ProgramError is raised. More...
 
void Read (TCollection_AsciiString &Buffer, const Standard_Integer Nbyte)
 Attempts to read Nbyte bytes from the file associated with the object file. Upon successful completion, Read returns the number of bytes actually read and placed in the Buffer. This number may be less than Nbyte if the number of bytes left in the file is less than Nbyte bytes. In this case only number of read bytes will be placed in the buffer. More...
 
void ReadLine (TCollection_AsciiString &Buffer, const Standard_Integer NByte, Standard_Integer &NbyteRead)
 Reads bytes from the data pointed to by the object file into the buffer <Buffer>. Data is read until <NByte-1> bytes have been read, until a newline character is read and transferred into <Buffer>, or until an EOF (End-of-File) condition is encountered. Upon successful completion, Read returns the number of bytes actually read into <NByteRead> and placed into the Buffer <Buffer>. More...
 
Standard_Integer ReadLine (TCollection_AsciiString &Buffer, const Standard_Integer NByte)
 Reads bytes from the data pointed to by the object file into the buffer <Buffer>. Data is read until <NByte-1> bytes have been read, until a newline character is read and transferred into <Buffer>, or until an EOF (End-of-File) condition is encountered. Upon successful completion, Read returns the number of bytes actually read and placed into the Buffer <Buffer>. More...
 
void Read (const Standard_Address Buffer, const Standard_Integer Nbyte, Standard_Integer &Readbyte)
 Attempts to read Nbyte bytes from the files associated with the object File. Upon successful completion, Read returns the number of bytes actually read and placed in the Buffer. This number may be less than Nbyte if the number of bytes left in the file is less than Nbyte bytes. For this reason the output parameter Readbyte will contain the number of read bytes. More...
 
void Write (const TCollection_AsciiString &Buffer, const Standard_Integer Nbyte)
 Attempts to write Nbyte bytes from the AsciiString to the file associated to the object File. More...
 
void Write (const Standard_Address Buffer, const Standard_Integer Nbyte)
 Attempts to write Nbyte bytes from the buffer pointed to by Buffer to the file associated to the object File. More...
 
void Seek (const Standard_Integer Offset, const OSD_FromWhere Whence)
 Sets the seek pointer associated with the open file. More...
 
void Close ()
 Closes the file (and deletes a descriptor) More...
 
Standard_Boolean IsAtEnd ()
 Returns TRUE if the seek pointer is at end of file. More...
 
OSD_KindFile KindOfFile () const
 Returns the kind of file. A file can be a file, a directory or a link. More...
 
void BuildTemporary ()
 Makes a temporary File This temporary file is already open ! More...
 
void SetLock (const OSD_LockType Lock)
 Locks current file. More...
 
void UnLock ()
 Unlocks current file. More...
 
OSD_LockType GetLock ()
 Returns the current lock state. More...
 
Standard_Boolean IsLocked ()
 Returns TRUE if this file is locked. More...
 
Standard_Size Size ()
 Returns actual number of bytes of <me>. More...
 
Standard_Boolean IsOpen () const
 Returns TRUE if <me> is open. More...
 
Standard_Boolean IsReadable ()
 returns TRUE if the file exists and if the user has the autorization to read it. More...
 
Standard_Boolean IsWriteable ()
 returns TRUE if the file can be read and overwritten. More...
 
Standard_Boolean IsExecutable ()
 returns TRUE if the file can be executed. More...
 
Standard_Boolean ReadLastLine (TCollection_AsciiString &aLine, const Standard_Integer aDelay, const Standard_Integer aNbTries)
 Enables to emulate unix "tail -f" command. If a line is available in the file <me> returns it. Otherwise attemps to read again aNbTries times in the file waiting aDelay seconds between each read. If meanwhile the file increases returns the next line, otherwise returns FALSE. More...
 
Standard_Boolean Edit ()
 find an editor on the system and edit the given file More...
 
void Rewind ()
 Set file pointer position to the beginning of the file. More...
 
int Capture (int theDescr)
 Redirect a standard handle (fileno(stdout), fileno(stdin) or fileno(stderr) to this OSD_File and return the copy of the original standard handle. Example: OSD_File aTmp; aTmp.BuildTemporary(); int stdfd = _fileno(stdout);. More...
 
- Public Member Functions inherited from OSD_FileNode
void Path (OSD_Path &Name) const
 Gets file name and path. More...
 
void SetPath (const OSD_Path &Name)
 Sets file name and path. If a name is not found, it raises a program error. More...
 
Standard_Boolean Exists ()
 Returns TRUE if <me> exists. More...
 
void Remove ()
 Erases the FileNode from directory. More...
 
void Move (const OSD_Path &NewPath)
 Moves <me> into another directory. More...
 
void Copy (const OSD_Path &ToPath)
 Copies <me> to another FileNode. More...
 
OSD_Protection Protection ()
 Returns access mode of <me>. More...
 
void SetProtection (const OSD_Protection &Prot)
 Changes protection of the FileNode. More...
 
Quantity_Date AccessMoment ()
 Returns last write access. On UNIX, AccessMoment and CreationMoment return the same value. More...
 
Quantity_Date CreationMoment ()
 Returns creation date. On UNIX, AccessMoment and CreationMoment return the same value. More...
 
Standard_Boolean Failed () const
 Returns TRUE if an error occurs. More...
 
void Reset ()
 Resets error counter to zero. More...
 
void Perror ()
 Raises OSD_Error. More...
 
Standard_Integer Error () const
 Returns error number if 'Failed' is TRUE. More...
 

Protected Attributes

Standard_Integer myIO
 
Standard_Address myFILE
 
Standard_Integer myFileChannel
 
Standard_Address myFileHandle
 
- Protected Attributes inherited from OSD_FileNode
OSD_Path myPath
 
OSD_Error myError
 

Additional Inherited Members

- Protected Member Functions inherited from OSD_FileNode
 OSD_FileNode ()
 Creates FileNode object This is to be used with SetPath . Allocate space for the file name and initializes this name to an empty name. More...
 
 OSD_FileNode (const OSD_Path &Name)
 Instantiates the object FileNode storing its name. If a name is not found, it raises a program error. More...
 
 ~OSD_FileNode ()
 Destructor is protected for safer inheritance. More...
 

Detailed Description

Basic tools to manage files Warning: 'ProgramError' is raised when somebody wants to use the methods Read, Write, Seek, Close when File is not open.

Constructor & Destructor Documentation

OSD_File::OSD_File ( )

Creates File object.

OSD_File::OSD_File ( const OSD_Path Name)

Instantiates the object file, storing its name.

OSD_File::~OSD_File ( )

Unlocks and closes a file, deletes a descriptor and destructs a file object.

Member Function Documentation

void OSD_File::Append ( const OSD_OpenMode  Mode,
const OSD_Protection Protect 
)

Appends data to an existing file. If file doesn't exist, creates it first. After 'Append', the file is open. If no name was given, ProgramError is raised.

void OSD_File::Build ( const OSD_OpenMode  Mode,
const OSD_Protection Protect 
)

CREATES a file if it doesn't already exists or empties an existing file. After 'Build', the file is open. If no name was given, ProgramError is raised.

void OSD_File::BuildTemporary ( )

Makes a temporary File This temporary file is already open !

int OSD_File::Capture ( int  theDescr)

Redirect a standard handle (fileno(stdout), fileno(stdin) or fileno(stderr) to this OSD_File and return the copy of the original standard handle. Example: OSD_File aTmp; aTmp.BuildTemporary(); int stdfd = _fileno(stdout);.

int oldout = aTmp.Capture(stdfd); cout << "Some output to the file" << endl; cout << flush; fflush(stdout);

_dup2(oldout, stdfd); // Restore standard output aTmp.Close();

void OSD_File::Close ( )

Closes the file (and deletes a descriptor)

Standard_Boolean OSD_File::Edit ( )

find an editor on the system and edit the given file

OSD_LockType OSD_File::GetLock ( )

Returns the current lock state.

Standard_Boolean OSD_File::IsAtEnd ( )

Returns TRUE if the seek pointer is at end of file.

Standard_Boolean OSD_File::IsExecutable ( )

returns TRUE if the file can be executed.

Standard_Boolean OSD_File::IsLocked ( )

Returns TRUE if this file is locked.

Standard_Boolean OSD_File::IsOpen ( ) const

Returns TRUE if <me> is open.

Standard_Boolean OSD_File::IsReadable ( )

returns TRUE if the file exists and if the user has the autorization to read it.

Standard_Boolean OSD_File::IsWriteable ( )

returns TRUE if the file can be read and overwritten.

OSD_KindFile OSD_File::KindOfFile ( ) const

Returns the kind of file. A file can be a file, a directory or a link.

void OSD_File::Open ( const OSD_OpenMode  Mode,
const OSD_Protection Protect 
)

Opens a File with specific attributes This works only on already existing file. If no name was given, ProgramError is raised.

void OSD_File::Read ( TCollection_AsciiString Buffer,
const Standard_Integer  Nbyte 
)

Attempts to read Nbyte bytes from the file associated with the object file. Upon successful completion, Read returns the number of bytes actually read and placed in the Buffer. This number may be less than Nbyte if the number of bytes left in the file is less than Nbyte bytes. In this case only number of read bytes will be placed in the buffer.

void OSD_File::Read ( const Standard_Address  Buffer,
const Standard_Integer  Nbyte,
Standard_Integer Readbyte 
)

Attempts to read Nbyte bytes from the files associated with the object File. Upon successful completion, Read returns the number of bytes actually read and placed in the Buffer. This number may be less than Nbyte if the number of bytes left in the file is less than Nbyte bytes. For this reason the output parameter Readbyte will contain the number of read bytes.

Standard_Boolean OSD_File::ReadLastLine ( TCollection_AsciiString aLine,
const Standard_Integer  aDelay,
const Standard_Integer  aNbTries 
)

Enables to emulate unix "tail -f" command. If a line is available in the file <me> returns it. Otherwise attemps to read again aNbTries times in the file waiting aDelay seconds between each read. If meanwhile the file increases returns the next line, otherwise returns FALSE.

void OSD_File::ReadLine ( TCollection_AsciiString Buffer,
const Standard_Integer  NByte,
Standard_Integer NbyteRead 
)

Reads bytes from the data pointed to by the object file into the buffer <Buffer>. Data is read until <NByte-1> bytes have been read, until a newline character is read and transferred into <Buffer>, or until an EOF (End-of-File) condition is encountered. Upon successful completion, Read returns the number of bytes actually read into <NByteRead> and placed into the Buffer <Buffer>.

Standard_Integer OSD_File::ReadLine ( TCollection_AsciiString Buffer,
const Standard_Integer  NByte 
)
inline

Reads bytes from the data pointed to by the object file into the buffer <Buffer>. Data is read until <NByte-1> bytes have been read, until a newline character is read and transferred into <Buffer>, or until an EOF (End-of-File) condition is encountered. Upon successful completion, Read returns the number of bytes actually read and placed into the Buffer <Buffer>.

void OSD_File::Rewind ( )

Set file pointer position to the beginning of the file.

void OSD_File::Seek ( const Standard_Integer  Offset,
const OSD_FromWhere  Whence 
)

Sets the seek pointer associated with the open file.

void OSD_File::SetLock ( const OSD_LockType  Lock)

Locks current file.

Standard_Size OSD_File::Size ( )

Returns actual number of bytes of <me>.

void OSD_File::UnLock ( )

Unlocks current file.

void OSD_File::Write ( const TCollection_AsciiString Buffer,
const Standard_Integer  Nbyte 
)

Attempts to write Nbyte bytes from the AsciiString to the file associated to the object File.

void OSD_File::Write ( const Standard_Address  Buffer,
const Standard_Integer  Nbyte 
)

Attempts to write Nbyte bytes from the buffer pointed to by Buffer to the file associated to the object File.

Field Documentation

Standard_Address OSD_File::myFILE
protected
Standard_Integer OSD_File::myFileChannel
protected
Standard_Address OSD_File::myFileHandle
protected
Standard_Integer OSD_File::myIO
protected

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