|
|
|||
File indexing completed on 2026-07-07 08:36:29
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 //! Creates File object. 0036 Standard_EXPORT OSD_File(); 0037 0038 //! Instantiates the object file, storing its name 0039 Standard_EXPORT OSD_File(const OSD_Path& Name); 0040 0041 //! Unlocks and closes a file, deletes a descriptor and destructs a file object. 0042 Standard_EXPORT ~OSD_File(); 0043 0044 //! CREATES a file if it doesn't already exists or empties 0045 //! an existing file. 0046 //! After 'Build', the file is open. 0047 //! If no name was given, ProgramError is raised. 0048 Standard_EXPORT void Build(const OSD_OpenMode Mode, const OSD_Protection& Protect); 0049 0050 //! Opens a File with specific attributes 0051 //! This works only on already existing file. 0052 //! If no name was given, ProgramError is raised. 0053 Standard_EXPORT void Open(const OSD_OpenMode Mode, const OSD_Protection& Protect); 0054 0055 //! Appends data to an existing file. 0056 //! If file doesn't exist, creates it first. 0057 //! After 'Append', the file is open. 0058 //! If no name was given, ProgramError is raised. 0059 Standard_EXPORT void Append(const OSD_OpenMode Mode, const OSD_Protection& Protect); 0060 0061 //! Attempts to read Nbyte bytes from the file associated with 0062 //! the object file. 0063 //! Upon successful completion, Read returns the number of 0064 //! bytes actually read and placed in the Buffer. This number 0065 //! may be less than Nbyte if the number of bytes left in the file 0066 //! is less than Nbyte bytes. In this case only number of read 0067 //! bytes will be placed in the buffer. 0068 Standard_EXPORT void Read(TCollection_AsciiString& Buffer, const Standard_Integer Nbyte); 0069 0070 //! Reads bytes from the data pointed to by the object file 0071 //! into the buffer <Buffer>. 0072 //! Data is read until <NByte-1> bytes have been read, 0073 //! until a newline character is read and transferred into 0074 //! <Buffer>, or until an EOF (End-of-File) condition is 0075 //! encountered. 0076 //! Upon successful completion, Read returns the number of 0077 //! bytes actually read into <NByteRead> and placed into the 0078 //! Buffer <Buffer>. 0079 Standard_EXPORT void ReadLine(TCollection_AsciiString& Buffer, 0080 const Standard_Integer NByte, 0081 Standard_Integer& NbyteRead); 0082 0083 //! Reads bytes from the data pointed to by the object file 0084 //! into the buffer <Buffer>. 0085 //! Data is read until <NByte-1> bytes have been read, 0086 //! until a newline character is read and transferred into 0087 //! <Buffer>, or until an EOF (End-of-File) condition is 0088 //! encountered. 0089 //! Upon successful completion, Read returns the number of 0090 //! bytes actually read and placed into the Buffer <Buffer>. 0091 inline Standard_Integer ReadLine(TCollection_AsciiString& Buffer, const Standard_Integer NByte) 0092 { 0093 Standard_Integer NbyteRead; 0094 ReadLine(Buffer, NByte, NbyteRead); 0095 return NbyteRead; 0096 } 0097 0098 //! Attempts to read Nbyte bytes from the files associated with 0099 //! the object File. 0100 //! Upon successful completion, Read returns the number of 0101 //! bytes actually read and placed in the Buffer. This number 0102 //! may be less than Nbyte if the number of bytes left in the file 0103 //! is less than Nbyte bytes. For this reason the output 0104 //! parameter Readbyte will contain the number of read bytes. 0105 Standard_EXPORT void Read(const Standard_Address Buffer, 0106 const Standard_Integer Nbyte, 0107 Standard_Integer& Readbyte); 0108 0109 //! Attempts to write theNbBytes bytes from the AsciiString to the file. 0110 void Write(const TCollection_AsciiString& theBuffer, const Standard_Integer theNbBytes) 0111 { 0112 Write((Standard_Address)theBuffer.ToCString(), theNbBytes); 0113 } 0114 0115 //! Attempts to write theNbBytes bytes from the buffer pointed 0116 //! to by theBuffer to the file associated to the object File. 0117 Standard_EXPORT void Write(const Standard_Address theBuffer, const Standard_Integer theNbBytes); 0118 0119 //! Sets the seek pointer associated with the open file 0120 Standard_EXPORT void Seek(const Standard_Integer Offset, const OSD_FromWhere Whence); 0121 0122 //! Closes the file (and deletes a descriptor) 0123 Standard_EXPORT void Close(); 0124 0125 //! Returns TRUE if the seek pointer is at end of file. 0126 Standard_EXPORT Standard_Boolean IsAtEnd(); 0127 0128 //! Returns the kind of file. A file can be a 0129 //! file, a directory or a link. 0130 Standard_EXPORT OSD_KindFile KindOfFile() const; 0131 0132 //! Makes a temporary File 0133 //! This temporary file is already open ! 0134 Standard_EXPORT void BuildTemporary(); 0135 0136 //! Locks current file 0137 Standard_EXPORT void SetLock(const OSD_LockType Lock); 0138 0139 //! Unlocks current file 0140 Standard_EXPORT void UnLock(); 0141 0142 //! Returns the current lock state 0143 OSD_LockType GetLock() const { return myLock; } 0144 0145 //! Returns TRUE if this file is locked. 0146 Standard_Boolean IsLocked() const 0147 { 0148 #ifdef _WIN32 0149 return ImperativeFlag; 0150 #else 0151 return myLock != OSD_NoLock; 0152 #endif 0153 } 0154 0155 //! Returns actual number of bytes of <me>. 0156 Standard_EXPORT Standard_Size Size(); 0157 0158 //! Returns TRUE if <me> is open. 0159 Standard_EXPORT Standard_Boolean IsOpen() const; 0160 0161 //! returns TRUE if the file exists and if the user 0162 //! has the authorization to read it. 0163 Standard_EXPORT Standard_Boolean IsReadable(); 0164 0165 //! returns TRUE if the file can be read and overwritten. 0166 Standard_EXPORT Standard_Boolean IsWriteable(); 0167 0168 //! returns TRUE if the file can be executed. 0169 Standard_EXPORT Standard_Boolean IsExecutable(); 0170 0171 //! Enables to emulate unix "tail -f" command. 0172 //! If a line is available in the file <me> returns it. 0173 //! Otherwise attempts to read again aNbTries times in the file 0174 //! waiting aDelay seconds between each read. 0175 //! If meanwhile the file increases returns the next line, otherwise 0176 //! returns FALSE. 0177 Standard_EXPORT Standard_Boolean ReadLastLine(TCollection_AsciiString& aLine, 0178 const Standard_Integer aDelay, 0179 const Standard_Integer aNbTries); 0180 0181 //! find an editor on the system and edit the given file 0182 Standard_EXPORT Standard_Boolean Edit(); 0183 0184 //! Set file pointer position to the beginning of the file 0185 Standard_EXPORT void Rewind(); 0186 0187 protected: 0188 #ifdef _WIN32 0189 Standard_Address myFileHandle; 0190 #else 0191 Standard_Integer myFileChannel; 0192 Standard_Address myFILE; 0193 #endif 0194 Standard_Integer myIO; 0195 0196 private: 0197 OSD_LockType myLock; 0198 OSD_OpenMode myMode; 0199 Standard_Boolean ImperativeFlag; 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 |
|