OCCT3D OCCT 8.0.1
OCCT documentation

Search guides and API reference

Enter at least two characters.

    Open CASCADE Technology Reference Manual 8.0.1
    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:

    Public Member Functions

     OSD_File ()
     Creates File object.
     OSD_File (const OSD_Path &Name)
     Instantiates the object file, storing its name.
     ~OSD_File ()
     Unlocks and closes a file, deletes a descriptor and destructs a file object.
    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.
    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.
    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.
    void Read (TCollection_AsciiString &Buffer, const int 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 ReadLine (TCollection_AsciiString &Buffer, const int NByte, int &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>.
    int ReadLine (TCollection_AsciiString &Buffer, const int 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>.
    void Read (void *const Buffer, const int Nbyte, int &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.
    void Write (const TCollection_AsciiString &theBuffer, const int theNbBytes)
     Attempts to write theNbBytes bytes from the AsciiString to the file.
    void Write (void *const theBuffer, const int theNbBytes)
     Attempts to write theNbBytes bytes from the buffer pointed to by theBuffer to the file associated to the object File.
    void Seek (const int Offset, const OSD_FromWhere Whence)
     Sets the seek pointer associated with the open file.
    void Close ()
     Closes the file (and deletes a descriptor).
    bool IsAtEnd ()
     Returns TRUE if the seek pointer is at end of file.
    OSD_KindFile KindOfFile () const
     Returns the kind of file. A file can be a file, a directory or a link.
    void BuildTemporary ()
     Makes a temporary File This temporary file is already open !
    void SetLock (const OSD_LockType Lock)
     Locks current file.
    void UnLock ()
     Unlocks current file.
    OSD_LockType GetLock () const
     Returns the current lock state.
    bool IsLocked () const
     Returns TRUE if this file is locked.
    size_t Size ()
     Returns actual number of bytes of <me>.
    bool IsOpen () const
     Returns TRUE if <me> is open.
    bool IsReadable ()
     returns TRUE if the file exists and if the user has the authorization to read it.
    bool IsWriteable ()
     returns TRUE if the file can be read and overwritten.
    bool IsExecutable ()
     returns TRUE if the file can be executed.
    bool ReadLastLine (TCollection_AsciiString &aLine, const int aDelay, const int aNbTries)
     Enables to emulate unix "tail -f" command. If a line is available in the file <me> returns it. Otherwise attempts 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.
    bool Edit ()
     find an editor on the system and edit the given file
    void Rewind ()
     Set file pointer position to the beginning of the file.
    Public Member Functions inherited from OSD_FileNode
    void Path (OSD_Path &Name) const
     Gets file name and path.
    void SetPath (const OSD_Path &Name)
     Sets file name and path. If a name is not found, it raises a program error.
    bool Exists ()
     Returns TRUE if <me> exists.
    void Remove ()
     Erases the FileNode from directory.
    void Move (const OSD_Path &NewPath)
     Moves <me> into another directory.
    void Copy (const OSD_Path &ToPath)
     Copies <me> to another FileNode.
    OSD_Protection Protection ()
     Returns access mode of <me>.
    void SetProtection (const OSD_Protection &Prot)
     Changes protection of the FileNode.
    Quantity_Date AccessMoment ()
     Returns last write access. On UNIX, AccessMoment and CreationMoment return the same value.
    Quantity_Date CreationMoment ()
     Returns creation date. On UNIX, AccessMoment and CreationMoment return the same value.
    bool Failed () const
     Returns TRUE if an error occurs.
    void Reset ()
     Resets error counter to zero.
    void Perror ()
     Raises OSD_Error.
    int Error () const
     Returns error number if 'Failed' is TRUE.

    Protected Attributes

    int myFileChannel
    voidmyFILE
    int myIO
    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.
     OSD_FileNode (const OSD_Path &Name)
     Instantiates the object FileNode storing its name. If a name is not found, it raises a program error.
     ~OSD_FileNode ()=default
     Destructor is protected for safer inheritance.

    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() [1/2]

    OSD_File::OSD_File ( )

    Creates File object.

    ◆ OSD_File() [2/2]

    OSD_File::OSD_File ( const OSD_Path & Name)

    Instantiates the object file, storing its name.

    ◆ ~OSD_File()

    OSD_File::~OSD_File ( )

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

    Member Function Documentation

    ◆ Append()

    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.

    ◆ Build()

    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.

    ◆ BuildTemporary()

    void OSD_File::BuildTemporary ( )

    Makes a temporary File This temporary file is already open !

    ◆ Close()

    void OSD_File::Close ( )

    Closes the file (and deletes a descriptor).

    ◆ Edit()

    bool OSD_File::Edit ( )

    find an editor on the system and edit the given file

    ◆ GetLock()

    OSD_LockType OSD_File::GetLock ( ) const
    inline

    Returns the current lock state.

    ◆ IsAtEnd()

    bool OSD_File::IsAtEnd ( )

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

    ◆ IsExecutable()

    bool OSD_File::IsExecutable ( )

    returns TRUE if the file can be executed.

    ◆ IsLocked()

    bool OSD_File::IsLocked ( ) const
    inline

    Returns TRUE if this file is locked.

    ◆ IsOpen()

    bool OSD_File::IsOpen ( ) const

    Returns TRUE if <me> is open.

    ◆ IsReadable()

    bool OSD_File::IsReadable ( )

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

    ◆ IsWriteable()

    bool OSD_File::IsWriteable ( )

    returns TRUE if the file can be read and overwritten.

    ◆ KindOfFile()

    OSD_KindFile OSD_File::KindOfFile ( ) const

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

    ◆ Open()

    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.

    ◆ Read() [1/2]

    void OSD_File::Read ( TCollection_AsciiString & Buffer,
    const int 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.

    ◆ Read() [2/2]

    void OSD_File::Read ( void *const Buffer,
    const int Nbyte,
    int & 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.

    ◆ ReadLastLine()

    bool OSD_File::ReadLastLine ( TCollection_AsciiString & aLine,
    const int aDelay,
    const int aNbTries )

    Enables to emulate unix "tail -f" command. If a line is available in the file <me> returns it. Otherwise attempts 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.

    ◆ ReadLine() [1/2]

    int OSD_File::ReadLine ( TCollection_AsciiString & Buffer,
    const int 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>.

    ◆ ReadLine() [2/2]

    void OSD_File::ReadLine ( TCollection_AsciiString & Buffer,
    const int NByte,
    int & 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>.

    ◆ Rewind()

    void OSD_File::Rewind ( )

    Set file pointer position to the beginning of the file.

    ◆ Seek()

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

    Sets the seek pointer associated with the open file.

    ◆ SetLock()

    void OSD_File::SetLock ( const OSD_LockType Lock)

    Locks current file.

    ◆ Size()

    size_t OSD_File::Size ( )

    Returns actual number of bytes of <me>.

    ◆ UnLock()

    void OSD_File::UnLock ( )

    Unlocks current file.

    ◆ Write() [1/2]

    void OSD_File::Write ( const TCollection_AsciiString & theBuffer,
    const int theNbBytes )
    inline

    Attempts to write theNbBytes bytes from the AsciiString to the file.

    ◆ Write() [2/2]

    void OSD_File::Write ( void *const theBuffer,
    const int theNbBytes )

    Attempts to write theNbBytes bytes from the buffer pointed to by theBuffer to the file associated to the object File.

    Field Documentation

    ◆ myFILE

    void* OSD_File::myFILE
    protected

    ◆ myFileChannel

    int OSD_File::myFileChannel
    protected

    ◆ myIO

    int OSD_File::myIO
    protected

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