mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-21 10:13:43 +03:00
0026381: OSD_File - close file on destruction
Add destructor for OSD_File, that unlocks and close file. Remove senseless checks from status functions in code for Linux. Destructor of OSD_FileNode is made protected to avoid possibility of deleting descendants by pointer to base class
This commit is contained in:
parent
90c8c7f32b
commit
4485f3d0f0
@ -700,9 +700,6 @@ int status;
|
|||||||
// Return lock of a file
|
// Return lock of a file
|
||||||
|
|
||||||
OSD_LockType OSD_File::GetLock(){
|
OSD_LockType OSD_File::GetLock(){
|
||||||
if (myFileChannel == -1)
|
|
||||||
Standard_ProgramError::Raise("OSD_File::GetLock : file is not open");
|
|
||||||
|
|
||||||
return(myLock);
|
return(myLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -762,19 +759,11 @@ TCollection_AsciiString PrinterName;
|
|||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
Standard_Boolean OSD_File::IsOpen()const{
|
Standard_Boolean OSD_File::IsOpen()const{
|
||||||
|
|
||||||
if (myPath.Name().Length()==0)
|
|
||||||
Standard_ProgramError::Raise("OSD_File::IsOpen : empty file name");
|
|
||||||
|
|
||||||
return (myFileChannel != -1);
|
return (myFileChannel != -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Standard_Boolean OSD_File::IsLocked(){
|
Standard_Boolean OSD_File::IsLocked(){
|
||||||
|
|
||||||
if (myPath.Name().Length()==0)
|
|
||||||
Standard_ProgramError::Raise("OSD_File::IsLocked : empty file name");
|
|
||||||
|
|
||||||
return(myLock != OSD_NoLock);
|
return(myLock != OSD_NoLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2875,6 +2864,19 @@ Standard_Boolean OSD_File::IsExecutable()
|
|||||||
|
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
// Destructs a file object (unlocks and closes file if it is open)
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
OSD_File::~OSD_File()
|
||||||
|
{
|
||||||
|
if (IsOpen())
|
||||||
|
{
|
||||||
|
if (IsLocked())
|
||||||
|
UnLock();
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Read lines in a file while it is increasing.
|
// Read lines in a file while it is increasing.
|
||||||
|
@ -53,6 +53,9 @@ public:
|
|||||||
//! Instantiates the object file, storing its name
|
//! Instantiates the object file, storing its name
|
||||||
Standard_EXPORT OSD_File(const OSD_Path& Name);
|
Standard_EXPORT OSD_File(const OSD_Path& Name);
|
||||||
|
|
||||||
|
//! Unlocks and closes a file, deletes a descriptor and destructs a file object.
|
||||||
|
Standard_EXPORT ~OSD_File();
|
||||||
|
|
||||||
//! CREATES a file if it doesn't already exists or empties
|
//! CREATES a file if it doesn't already exists or empties
|
||||||
//! an existing file.
|
//! an existing file.
|
||||||
//! After 'Build', the file is open.
|
//! After 'Build', the file is open.
|
||||||
|
@ -18,16 +18,12 @@
|
|||||||
#define _OSD_FileNode_HeaderFile
|
#define _OSD_FileNode_HeaderFile
|
||||||
|
|
||||||
#include <Standard.hxx>
|
#include <Standard.hxx>
|
||||||
#include <Standard_DefineAlloc.hxx>
|
|
||||||
#include <Standard_Handle.hxx>
|
|
||||||
|
|
||||||
#include <OSD_Path.hxx>
|
#include <OSD_Path.hxx>
|
||||||
#include <OSD_Error.hxx>
|
#include <OSD_Error.hxx>
|
||||||
#include <Standard_Boolean.hxx>
|
|
||||||
#include <Standard_Integer.hxx>
|
|
||||||
class OSD_OSDError;
|
class OSD_OSDError;
|
||||||
class Standard_ProgramError;
|
class Standard_ProgramError;
|
||||||
class OSD_Path;
|
|
||||||
class OSD_Protection;
|
class OSD_Protection;
|
||||||
class Quantity_Date;
|
class Quantity_Date;
|
||||||
|
|
||||||
@ -96,12 +92,8 @@ public:
|
|||||||
//! Returns error number if 'Failed' is TRUE.
|
//! Returns error number if 'Failed' is TRUE.
|
||||||
Standard_EXPORT Standard_Integer Error() const;
|
Standard_EXPORT Standard_Integer Error() const;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|
||||||
//! Creates FileNode object
|
//! Creates FileNode object
|
||||||
//! This is to be used with SetPath .
|
//! This is to be used with SetPath .
|
||||||
//! Allocate space for the file name and initializes this
|
//! Allocate space for the file name and initializes this
|
||||||
@ -112,23 +104,14 @@ protected:
|
|||||||
//! If a name is not found, it raises a program error.
|
//! If a name is not found, it raises a program error.
|
||||||
Standard_EXPORT OSD_FileNode(const OSD_Path& Name);
|
Standard_EXPORT OSD_FileNode(const OSD_Path& Name);
|
||||||
|
|
||||||
|
//! Destructor is protected for safer inheritance
|
||||||
|
~OSD_FileNode () {}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
OSD_Path myPath;
|
OSD_Path myPath;
|
||||||
OSD_Error myError;
|
OSD_Error myError;
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // _OSD_FileNode_HeaderFile
|
#endif // _OSD_FileNode_HeaderFile
|
||||||
|
Loading…
x
Reference in New Issue
Block a user