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
// 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);
}
// --------------------------------------------------------------------------
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);
}
#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.
//! 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.
#define _OSD_FileNode_HeaderFile
#include <Standard.hxx>
-#include <Standard_DefineAlloc.hxx>
-#include <Standard_Handle.hxx>
#include <OSD_Path.hxx>
#include <OSD_Error.hxx>
-#include <Standard_Boolean.hxx>
-#include <Standard_Integer.hxx>
+
class OSD_OSDError;
class Standard_ProgramError;
-class OSD_Path;
class OSD_Protection;
class Quantity_Date;
//! Returns error number if 'Failed' is TRUE.
Standard_EXPORT Standard_Integer Error() const;
-
-
-
protected:
-
//! Creates FileNode object
//! This is to be used with SetPath .
//! 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