diff --git a/src/OSD/OSD_File.cxx b/src/OSD/OSD_File.cxx index e293c79944..c26b39edb9 100644 --- a/src/OSD/OSD_File.cxx +++ b/src/OSD/OSD_File.cxx @@ -700,9 +700,6 @@ int status; // Return lock of a file OSD_LockType OSD_File::GetLock(){ - if (myFileChannel == -1) - Standard_ProgramError::Raise("OSD_File::GetLock : file is not open"); - return(myLock); } @@ -762,19 +759,11 @@ TCollection_AsciiString PrinterName; // -------------------------------------------------------------------------- Standard_Boolean OSD_File::IsOpen()const{ - - if (myPath.Name().Length()==0) - Standard_ProgramError::Raise("OSD_File::IsOpen : empty file name"); - return (myFileChannel != -1); } Standard_Boolean OSD_File::IsLocked(){ - - if (myPath.Name().Length()==0) - Standard_ProgramError::Raise("OSD_File::IsLocked : empty file name"); - return(myLock != OSD_NoLock); } @@ -2875,6 +2864,19 @@ Standard_Boolean OSD_File::IsExecutable() #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. diff --git a/src/OSD/OSD_File.hxx b/src/OSD/OSD_File.hxx index 528f232b1b..2cc055f91a 100644 --- a/src/OSD/OSD_File.hxx +++ b/src/OSD/OSD_File.hxx @@ -52,6 +52,9 @@ public: //! Instantiates the object file, storing its 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 //! an existing file. diff --git a/src/OSD/OSD_FileNode.hxx b/src/OSD/OSD_FileNode.hxx index 51941d5176..067e8ccda8 100644 --- a/src/OSD/OSD_FileNode.hxx +++ b/src/OSD/OSD_FileNode.hxx @@ -18,16 +18,12 @@ #define _OSD_FileNode_HeaderFile #include -#include -#include #include #include -#include -#include + class OSD_OSDError; class Standard_ProgramError; -class OSD_Path; class OSD_Protection; class Quantity_Date; @@ -96,11 +92,7 @@ public: //! Returns error number if 'Failed' is TRUE. Standard_EXPORT Standard_Integer Error() const; - - - protected: - //! Creates FileNode object //! This is to be used with SetPath . @@ -112,23 +104,14 @@ protected: //! If a name is not found, it raises a program error. Standard_EXPORT OSD_FileNode(const OSD_Path& Name); + //! Destructor is protected for safer inheritance + ~OSD_FileNode () {} + +protected: OSD_Path myPath; OSD_Error myError; - - -private: - - - - - }; - - - - - #endif // _OSD_FileNode_HeaderFile