|
||||
File indexing completed on 2025-01-18 10:04:36
0001 // Created on: 1992-02-17 0002 // Created by: Stephan GARNAUD 0003 // Copyright (c) 1992-1999 Matra Datavision 0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS 0005 // 0006 // This file is part of Open CASCADE Technology software library. 0007 // 0008 // This library is free software; you can redistribute it and/or modify it under 0009 // the terms of the GNU Lesser General Public License version 2.1 as published 0010 // by the Free Software Foundation, with special exception defined in the file 0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 0012 // distribution for complete text of the license and disclaimer of any warranty. 0013 // 0014 // Alternatively, this file may be used under the terms of Open CASCADE 0015 // commercial license or contractual agreement. 0016 0017 #ifndef _OSD_File_HeaderFile 0018 #define _OSD_File_HeaderFile 0019 0020 #include <OSD_FileNode.hxx> 0021 #include <OSD_FromWhere.hxx> 0022 #include <OSD_KindFile.hxx> 0023 #include <OSD_LockType.hxx> 0024 #include <OSD_OpenMode.hxx> 0025 0026 class OSD_Path; 0027 class OSD_Protection; 0028 0029 //! Basic tools to manage files 0030 //! Warning: 'ProgramError' is raised when somebody wants to use the methods 0031 //! Read, Write, Seek, Close when File is not open. 0032 class OSD_File : public OSD_FileNode 0033 { 0034 public: 0035 0036 //! Creates File object. 0037 Standard_EXPORT OSD_File(); 0038 0039 //! Instantiates the object file, storing its name 0040 Standard_EXPORT OSD_File(const OSD_Path& Name); 0041 0042 //! Unlocks and closes a file, deletes a descriptor and destructs a file object. 0043 Standard_EXPORT ~OSD_File(); 0044 0045 //! CREATES a file if it doesn't already exists or empties 0046 //! an existing file. 0047 //! After 'Build', the file is open. 0048 //! If no name was given, ProgramError is raised. 0049 Standard_EXPORT void Build (const OSD_OpenMode Mode, const OSD_Protection& Protect); 0050 0051 //! Opens a File with specific attributes 0052 //! This works only on already existing file. 0053 //! If no name was given, ProgramError is raised. 0054 Standard_EXPORT void Open (const OSD_OpenMode Mode, const OSD_Protection& Protect); 0055 0056 //! Appends data to an existing file. 0057 //! If file doesn't exist, creates it first. 0058 //! After 'Append', the file is open. 0059 //! If no name was given, ProgramError is raised. 0060 Standard_EXPORT void Append (const OSD_OpenMode Mode, const OSD_Protection& Protect); 0061 0062 //! Attempts to read Nbyte bytes from the file associated with 0063 //! the object file. 0064 //! Upon successful completion, Read returns the number of 0065 //! bytes actually read and placed in the Buffer. This number 0066 //! may be less than Nbyte if the number of bytes left in the file 0067 //! is less than Nbyte bytes. In this case only number of read 0068 //! bytes will be placed in the buffer. 0069 Standard_EXPORT void Read (TCollection_AsciiString& Buffer, const Standard_Integer Nbyte); 0070 0071 //! Reads bytes from the data pointed to by the object file 0072 //! into the buffer <Buffer>. 0073 //! Data is read until <NByte-1> bytes have been read, 0074 //! until a newline character is read and transferred into 0075 //! <Buffer>, or until an EOF (End-of-File) condition is 0076 //! encountered. 0077 //! Upon successful completion, Read returns the number of 0078 //! bytes actually read into <NByteRead> and placed into the 0079 //! Buffer <Buffer>. 0080 Standard_EXPORT void ReadLine (TCollection_AsciiString& Buffer, const Standard_Integer NByte, Standard_Integer& NbyteRead); 0081 0082 //! Reads bytes from the data pointed to by the object file 0083 //! into the buffer <Buffer>. 0084 //! Data is read until <NByte-1> bytes have been read, 0085 //! until a newline character is read and transferred into 0086 //! <Buffer>, or until an EOF (End-of-File) condition is 0087 //! encountered. 0088 //! Upon successful completion, Read returns the number of 0089 //! bytes actually read and placed into the Buffer <Buffer>. 0090 inline Standard_Integer ReadLine ( 0091 TCollection_AsciiString& Buffer, const Standard_Integer NByte) 0092 { 0093 Standard_Integer NbyteRead; 0094 ReadLine(Buffer, NByte, NbyteRead); 0095 return NbyteRead; 0096 } 0097 0098 0099 //! Attempts to read Nbyte bytes from the files associated with 0100 //! the object File. 0101 //! Upon successful completion, Read returns the number of 0102 //! bytes actually read and placed in the Buffer. This number 0103 //! may be less than Nbyte if the number of bytes left in the file 0104 //! is less than Nbyte bytes. For this reason the output 0105 //! parameter Readbyte will contain the number of read bytes. 0106 Standard_EXPORT void Read (const Standard_Address Buffer, const Standard_Integer Nbyte, Standard_Integer& Readbyte); 0107 0108 //! Attempts to write theNbBytes bytes from the AsciiString to the file. 0109 void Write (const TCollection_AsciiString& theBuffer, const Standard_Integer theNbBytes) 0110 { 0111 Write ((Standard_Address )theBuffer.ToCString(), theNbBytes); 0112 } 0113 0114 //! Attempts to write theNbBytes bytes from the buffer pointed 0115 //! to by theBuffer to the file associated to the object File. 0116 Standard_EXPORT void Write (const Standard_Address theBuffer, const Standard_Integer theNbBytes); 0117 0118 //! Sets the seek pointer associated with the open file 0119 Standard_EXPORT void Seek (const Standard_Integer Offset, const OSD_FromWhere Whence); 0120 0121 //! Closes the file (and deletes a descriptor) 0122 Standard_EXPORT void Close(); 0123 0124 //! Returns TRUE if the seek pointer is at end of file. 0125 Standard_EXPORT Standard_Boolean IsAtEnd(); 0126 0127 //! Returns the kind of file. A file can be a 0128 //! file, a directory or a link. 0129 Standard_EXPORT OSD_KindFile KindOfFile() const; 0130 0131 //! Makes a temporary File 0132 //! This temporary file is already open ! 0133 Standard_EXPORT void BuildTemporary(); 0134 0135 //! Locks current file 0136 Standard_EXPORT void SetLock (const OSD_LockType Lock); 0137 0138 //! Unlocks current file 0139 Standard_EXPORT void UnLock(); 0140 0141 //! Returns the current lock state 0142 OSD_LockType GetLock() const { return myLock; } 0143 0144 //! Returns TRUE if this file is locked. 0145 Standard_Boolean IsLocked() const 0146 { 0147 #ifdef _WIN32 0148 return ImperativeFlag; 0149 #else 0150 return myLock != OSD_NoLock; 0151 #endif 0152 } 0153 0154 //! Returns actual number of bytes of <me>. 0155 Standard_EXPORT Standard_Size Size(); 0156 0157 //! Returns TRUE if <me> is open. 0158 Standard_EXPORT Standard_Boolean IsOpen() const; 0159 0160 //! returns TRUE if the file exists and if the user 0161 //! has the authorization to read it. 0162 Standard_EXPORT Standard_Boolean IsReadable(); 0163 0164 //! returns TRUE if the file can be read and overwritten. 0165 Standard_EXPORT Standard_Boolean IsWriteable(); 0166 0167 //! returns TRUE if the file can be executed. 0168 Standard_EXPORT Standard_Boolean IsExecutable(); 0169 0170 //! Enables to emulate unix "tail -f" command. 0171 //! If a line is available in the file <me> returns it. 0172 //! Otherwise attempts to read again aNbTries times in the file 0173 //! waiting aDelay seconds between each read. 0174 //! If meanwhile the file increases returns the next line, otherwise 0175 //! returns FALSE. 0176 Standard_EXPORT Standard_Boolean ReadLastLine (TCollection_AsciiString& aLine, const Standard_Integer aDelay, const Standard_Integer aNbTries); 0177 0178 //! find an editor on the system and edit the given file 0179 Standard_EXPORT Standard_Boolean Edit(); 0180 0181 //! Set file pointer position to the beginning of the file 0182 Standard_EXPORT void Rewind(); 0183 0184 protected: 0185 0186 #ifdef _WIN32 0187 Standard_Address myFileHandle; 0188 #else 0189 Standard_Integer myFileChannel; 0190 Standard_Address myFILE; 0191 #endif 0192 Standard_Integer myIO; 0193 0194 private: 0195 0196 OSD_LockType myLock; 0197 OSD_OpenMode myMode; 0198 Standard_Boolean ImperativeFlag; 0199 0200 }; 0201 0202 #endif // _OSD_File_HeaderFile
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |