📄 classpfile.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>PFile class Reference</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.2.18 --><center><a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> </center><hr><h1>PFile Class Reference</h1><code>#include <<a class="el" href="file_8h-source.html">file.h</a>></code><p><p>Inheritance diagram for PFile:<p><center><img src="classPFile.png" usemap="#PFile_map" border="0" alt=""></center><map name="PFile_map"><area href="classPChannel.html" alt="PChannel" shape="rect" coords="165,56,265,80"><area href="classPObject.html" alt="PObject" shape="rect" coords="165,0,265,24"><area href="classPMemoryFile.html" alt="PMemoryFile" shape="rect" coords="0,168,100,192"><area href="classPStructuredFile.html" alt="PStructuredFile" shape="rect" coords="110,168,210,192"><area href="classPTextFile.html" alt="PTextFile" shape="rect" coords="220,168,320,192"><area href="classPWAVFile.html" alt="PWAVFile" shape="rect" coords="330,168,430,192"></map><a href="classPFile-members.html">List of all members.</a><table border=0 cellpadding=0 cellspacing=0><tr><td></td></tr><tr><td colspan=2><br><h2>Construction</h2></td></tr><tr><td nowrap align=right valign=top>enum </td><td valign=bottom><a class="el" href="classPFile.html#z125_0">OpenMode</a> { <a class="el" href="classPFile.html#z125_0s0">ReadOnly</a>, <a class="el" href="classPFile.html#z125_0s1">WriteOnly</a>, <a class="el" href="classPFile.html#z125_0s2">ReadWrite</a> }</td></tr><tr><td nowrap align=right valign=top>enum </td><td valign=bottom><a class="el" href="classPFile.html#z125_1">OpenOptions</a> { <br> <a class="el" href="classPFile.html#z125_1s3">ModeDefault</a> = -1, <a class="el" href="classPFile.html#z125_1s4">MustExist</a> = 0, <a class="el" href="classPFile.html#z125_1s5">Create</a> = 1, <a class="el" href="classPFile.html#z125_1s6">Truncate</a> = 2, <br> <a class="el" href="classPFile.html#z125_1s7">Exclusive</a> = 4, <a class="el" href="classPFile.html#z125_1s8">Temporary</a> = 8, <a class="el" href="classPFile.html#z125_1s9">DenySharedRead</a> = 16, <a class="el" href="classPFile.html#z125_1s10">DenySharedWrite</a> = 32<br> }</td></tr><tr><td nowrap align=right valign=top> </td><td valign=bottom><a class="el" href="classPFile.html#z125_2">PFile</a> ()</td></tr><tr><td nowrap align=right valign=top> </td><td valign=bottom><a class="el" href="classPFile.html#z125_3">PFile</a> (<a class="el" href="classPFile.html#z125_0">OpenMode</a> mode, int opts=ModeDefault)</td></tr><tr><td nowrap align=right valign=top> </td><td valign=bottom><a class="el" href="classPFile.html#z125_4">PFile</a> (const <a class="el" href="classPFilePath.html">PFilePath</a> &name, <a class="el" href="classPFile.html#z125_0">OpenMode</a> mode=ReadWrite, int opts=ModeDefault)</td></tr><tr><td nowrap align=right valign=top> </td><td valign=bottom><a class="el" href="classPFile.html#z125_5">~PFile</a> ()</td></tr><tr><td> </td><td><font size=-1><em>Close the file on destruction.</em> <a href="#z125_5"></a><em></em></font><br><br></td></tr><tr><td colspan=2><br><h2>File channel functions</h2></td></tr><tr><td nowrap align=right valign=top>enum </td><td valign=bottom><a class="el" href="classPFile.html#z133_0">FilePositionOrigin</a> { <a class="el" href="classPFile.html#z133_0s11">Start</a> = SEEK_SET, <a class="el" href="classPFile.html#z133_0s12">Current</a> = SEEK_CUR, <a class="el" href="classPFile.html#z133_0s13">End</a> = SEEK_END }</td></tr><tr><td> </td><td><font size=-1><em>Options for the origin in setting the file position.</em> <a href="#z133_0">More...</a><em></em></font><br><br></td></tr><tr><td nowrap align=right valign=top>const <a class="el" href="classPFilePath.html">PFilePath</a> & </td><td valign=bottom><a class="el" href="classPFile.html#z133_1">GetFilePath</a> () const</td></tr><tr><td nowrap align=right valign=top>void </td><td valign=bottom><a class="el" href="classPFile.html#z133_2">SetFilePath</a> (const <a class="el" href="classPString.html">PString</a> &<a class="el" href="classPFile.html#n0">path</a>)</td></tr><tr><td nowrap align=right valign=top>virtual BOOL </td><td valign=bottom><a class="el" href="classPFile.html#z133_3">Open</a> (<a class="el" href="classPFile.html#z125_0">OpenMode</a> mode=ReadWrite, int opts=ModeDefault)</td></tr><tr><td nowrap align=right valign=top>virtual BOOL </td><td valign=bottom><a class="el" href="classPFile.html#z133_4">Open</a> (const <a class="el" href="classPFilePath.html">PFilePath</a> &name, <a class="el" href="classPFile.html#z125_0">OpenMode</a> mode=ReadWrite, int opts=ModeDefault)</td></tr><tr><td nowrap align=right valign=top>virtual off_t </td><td valign=bottom><a class="el" href="classPFile.html#z133_5">GetLength</a> () const</td></tr><tr><td nowrap align=right valign=top>virtual BOOL </td><td valign=bottom><a class="el" href="classPFile.html#z133_6">SetLength</a> (off_t len)</td></tr><tr><td nowrap align=right valign=top>virtual BOOL </td><td valign=bottom><a class="el" href="classPFile.html#z133_7">SetPosition</a> (off_t pos, <a class="el" href="classPFile.html#z133_0">FilePositionOrigin</a> origin=Start)</td></tr><tr><td nowrap align=right valign=top>virtual off_t </td><td valign=bottom><a class="el" href="classPFile.html#z133_8">GetPosition</a> () const</td></tr><tr><td nowrap align=right valign=top>BOOL </td><td valign=bottom><a class="el" href="classPFile.html#z133_9">IsEndOfFile</a> () const</td></tr><tr><td nowrap align=right valign=top>BOOL </td><td valign=bottom><a class="el" href="classPFile.html#z133_10">GetInfo</a> (<a class="el" href="classPFileInfo.html">PFileInfo</a> &info)</td></tr><tr><td nowrap align=right valign=top>BOOL </td><td valign=bottom><a class="el" href="classPFile.html#z133_11">SetPermissions</a> (int permissions)</td></tr><tr><td nowrap align=right valign=top>BOOL </td><td valign=bottom><a class="el" href="classPFile.html#z133_12">GetInfo</a> (const <a class="el" href="classPFilePath.html">PFilePath</a> &name, <a class="el" href="classPFileInfo.html">PFileInfo</a> &info)</td></tr><tr><td nowrap align=right valign=top>BOOL </td><td valign=bottom><a class="el" href="classPFile.html#z133_13">SetPermissions</a> (const <a class="el" href="classPFilePath.html">PFilePath</a> &name, int permissions)</td></tr><tr><td colspan=2><br><h2>File manipulation functions</h2></td></tr><tr><td nowrap align=right valign=top>BOOL </td><td valign=bottom><a class="el" href="classPFile.html#z131_0">Exists</a> () const</td></tr><tr><td nowrap align=right valign=top>BOOL </td><td valign=bottom><a class="el" href="classPFile.html#z131_1">Access</a> (<a class="el" href="classPFile.html#z125_0">OpenMode</a> mode)</td></tr><tr><td nowrap align=right valign=top>BOOL </td><td valign=bottom><a class="el" href="classPFile.html#z131_2">Remove</a> (BOOL force=FALSE)</td></tr><tr><td nowrap align=right valign=top>BOOL </td><td valign=bottom><a class="el" href="classPFile.html#z131_3">Rename</a> (const <a class="el" href="classPString.html">PString</a> &newname, BOOL force=FALSE)</td></tr><tr><td nowrap align=right valign=top>BOOL </td><td valign=bottom><a class="el" href="classPFile.html#z131_4">Copy</a> (const <a class="el" href="classPFilePath.html">PFilePath</a> &newname, BOOL force=FALSE)</td></tr><tr><td nowrap align=right valign=top>BOOL </td><td valign=bottom><a class="el" href="classPFile.html#z131_5">Move</a> (const <a class="el" href="classPFilePath.html">PFilePath</a> &newname, BOOL force=FALSE)</td></tr><tr><td nowrap align=right valign=top>BOOL </td><td valign=bottom><a class="el" href="classPFile.html#z131_6">Exists</a> (const <a class="el" href="classPFilePath.html">PFilePath</a> &name)</td></tr><tr><td nowrap align=right valign=top>BOOL </td><td valign=bottom><a class="el" href="classPFile.html#z131_7">Access</a> (const <a class="el" href="classPFilePath.html">PFilePath</a> &name, <a class="el" href="classPFile.html#z125_0">OpenMode</a> mode)</td></tr><tr><td nowrap align=right valign=top>BOOL </td><td valign=bottom><a class="el" href="classPFile.html#z131_8">Remove</a> (const <a class="el" href="classPFilePath.html">PFilePath</a> &name, BOOL force=FALSE)</td></tr><tr><td nowrap align=right valign=top>BOOL </td><td valign=bottom><a class="el" href="classPFile.html#z131_9">Rename</a> (const <a class="el" href="classPFilePath.html">PFilePath</a> &oldname, const <a class="el" href="classPString.html">PString</a> &newname, BOOL force=FALSE)</td></tr><tr><td nowrap align=right valign=top>BOOL </td><td valign=bottom><a class="el" href="classPFile.html#z131_10">Copy</a> (const <a class="el" href="classPFilePath.html">PFilePath</a> &oldname, const <a class="el" href="classPFilePath.html">PFilePath</a> &newname, BOOL force=FALSE)</td></tr><tr><td nowrap align=right valign=top>BOOL </td><td valign=bottom><a class="el" href="classPFile.html#z131_11">Move</a> (const <a class="el" href="classPFilePath.html">PFilePath</a> &oldname, const <a class="el" href="classPFilePath.html">PFilePath</a> &newname, BOOL force=FALSE)</td></tr><tr><td colspan=2><br><h2>Public Types</h2></td></tr><tr><td colspan=2><br><h2>Public Methods</h2></td></tr><tr><td colspan="2"><div class="groupHeader">Overrides from class PObject</div></td></tr><tr><td nowrap align=right valign=top><a class="el" href="classPObject.html#z199_0">Comparison</a> </td><td valign=bottom><a class="el" href="classPFile.html#z127_0">Compare</a> (const <a class="el" href="classPObject.html">PObject</a> &obj) const</td></tr><tr><td colspan="2"><div class="groupHeader">Overrides from class PChannel</div></td></tr><tr><td nowrap align=right valign=top>virtual <a class="el" href="classPString.html">PString</a> </td><td valign=bottom><a class="el" href="classPFile.html#z129_0">GetName</a> () const</td></tr><tr><td nowrap align=right valign=top>virtual BOOL </td><td valign=bottom><a class="el" href="classPFile.html#z129_1">Read</a> (void *buf, PINDEX len)</td></tr><tr><td nowrap align=right valign=top>virtual BOOL </td><td valign=bottom><a class="el" href="classPFile.html#z129_2">Write</a> (const void *buf, PINDEX len)</td></tr><tr><td nowrap align=right valign=top>virtual BOOL </td><td valign=bottom><a class="el" href="classPFile.html#z129_3">Close</a> ()</td></tr><tr><td colspan=2><br><h2>Protected Attributes</h2></td></tr><tr><td nowrap align=right valign=top><a class="el" href="classPFilePath.html">PFilePath</a> </td><td valign=bottom><a class="el" href="classPFile.html#n0">path</a></td></tr><tr><td> </td><td><font size=-1><em>The fully qualified path name for the file.</em> <a href="#n0"></a><em></em></font><br><br></td></tr><tr><td nowrap align=right valign=top>BOOL </td><td valign=bottom><a class="el" href="classPFile.html#n1">removeOnClose</a></td></tr><tr><td> </td><td><font size=-1><em>File is to be removed when closed.</em> <a href="#n1"></a><em></em></font><br><br></td></tr></table><hr><a name="_details"></a><h2>Detailed Description</h2>This class represents a disk file. This is a particular type of I/O channel that has certain attributes. All platforms have a disk file, though exact details of naming convertions etc may be different.<p>The basic model for files is that they are a named sequence of bytes that persists within a directory structure. The transfer of data to and from the file is made at a current position in the file. This may be set to random locations within the file. <p><hr><h2>Member Enumeration Documentation</h2><a name="z133_0" doxytag="PFile::FilePositionOrigin"></a><p><table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> enum PFile::FilePositionOrigin </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p>Options for the origin in setting the file position.<p><dl compact><dt><b>Enumeration values: </b></dt><dd><table border=0 cellspacing=2 cellpadding=0><tr><td valign=top><em><a name="z133_0s11" doxytag="Start"></a><em>Start</em></em> </td><td>Set position relative to start of file.</td></tr><tr><td valign=top><em><a name="z133_0s12" doxytag="Current"></a><em>Current</em></em> </td><td>Set position relative to current file position.</td></tr><tr><td valign=top><em><a name="z133_0s13" doxytag="End"></a><em>End</em></em> </td><td>Set position relative to end of file.</td></tr></table></dl> </td> </tr></table><a name="z125_0" doxytag="PFile::OpenMode"></a><p><table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> enum PFile::OpenMode </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p>When a file is opened, it may restrict the access available to operations on the object instance. A value from this enum is passed to the <a class="el" href="classPFile.html#z133_3">Open()</a># function to set the mode. <dl compact><dt><b>Enumeration values: </b></dt><dd><table border=0 cellspacing=2 cellpadding=0><tr><td valign=top><em><a name="z125_0s0" doxytag="ReadOnly"></a><em>ReadOnly</em></em> </td><td>File can be read but not written.</td></tr><tr><td valign=top><em><a name="z125_0s1" doxytag="WriteOnly"></a><em>WriteOnly</em></em> </td><td>File can be written but not read.</td></tr><tr><td valign=top><em><a name="z125_0s2" doxytag="ReadWrite"></a><em>ReadWrite</em></em> </td><td>File can be both read and written.</td></tr></table></dl> </td> </tr></table><a name="z125_1" doxytag="PFile::OpenOptions"></a><p><table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> enum PFile::OpenOptions </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p>When a file is opened, a number of options may be associated with the open file. These describe what action to take on opening the file and what to do on closure. A value from this enum is passed to the <a class="el" href="classPFile.html#z133_3">Open()</a># function to set the options.<p>The <a class="el" href="classPFile.html#z125_1s3">ModeDefault</a># option will use the following values: \begin{tabular}{rr} Mode & Options \ \hline <a class="el" href="classPFile.html#z125_0s0">ReadOnly</a># & <a class="el" href="classPFile.html#z125_1s4">MustExist</a># \ <a class="el" href="classPFile.html#z125_0s1">WriteOnly</a># & <a class="el" href="classPFile.html#z125_1s5">Create</a> | Truncate# \ <a class="el" href="classPFile.html#z125_0s2">ReadWrite</a># & <a class="el" href="classPFile.html#z125_1s5">Create</a># \ \hline \end{tabular} <dl compact><dt><b>Enumeration values: </b></dt><dd><table border=0 cellspacing=2 cellpadding=0><tr><td valign=top><em><a name="z125_1s3" doxytag="ModeDefault"></a><em>ModeDefault</em></em> </td><td>File options depend on the OpenMode parameter.</td></tr><tr><td valign=top><em><a name="z125_1s4" doxytag="MustExist"></a><em>MustExist</em></em> </td><td>File open fails if file does not exist.</td></tr><tr><td valign=top><em><a name="z125_1s5" doxytag="Create"></a><em>Create</em></em> </td><td>File is created if it does not exist.</td></tr><tr><td valign=top><em><a name="z125_1s6" doxytag="Truncate"></a><em>Truncate</em></em> </td><td>File is set to zero length if it already exists.</td></tr><tr><td valign=top><em><a name="z125_1s7" doxytag="Exclusive"></a><em>Exclusive</em></em> </td><td>File open fails if file already exists.</td></tr><tr><td valign=top><em><a name="z125_1s8" doxytag="Temporary"></a><em>Temporary</em></em> </td><td>File is temporary and is to be deleted when closed.</td></tr><tr><td valign=top><em><a name="z125_1s9" doxytag="DenySharedRead"></a><em>DenySharedRead</em></em> </td><td>File may not be read by another process.</td></tr><tr><td valign=top><em><a name="z125_1s10" doxytag="DenySharedWrite"></a><em>DenySharedWrite</em></em> </td><td>File may not be written by another process.</td></tr></table></dl> </td> </tr></table><hr><h2>Constructor & Destructor Documentation</h2><a name="z125_2" doxytag="PFile::PFile"></a><p><table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> PINLINE PFile::PFile </td> <td class="md" valign="top">( </td> <td class="mdname1" valign="top" nowrap> </td> <td class="md" valign="top">) </td> <td class="md" nowrap></td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p>Create a file object but do not open it. It does not initially have a valid file name. However, an attempt to open the file using the <a class="el" href="classPFile.html#z133_3">Open()</a># function will generate a unique temporary file. </td> </tr></table><a name="z125_3" doxytag="PFile::PFile"></a><p><table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> PINLINE PFile::PFile </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top"><a class="el" href="classPFile.html#z125_0">OpenMode</a> </td> <td class="mdname" nowrap> <em>mode</em>, </td> </tr> <tr> <td></td> <td></td> <td class="md" nowrap>int </td> <td class="mdname" nowrap> <em>opts</em> = ModeDefault</td> </tr> <tr> <td></td> <td class="md">) </td> <td class="md" colspan="2"></td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p>Create a unique temporary file name, and open the file in the specified mode and using the specified options. Note that opening a new, unique, temporary file name in ReadOnly mode will always fail. This would only be usefull in a mode and options that will create the file.<p>The PChannel::IsOpen()# function may be used after object construction to determine if the file was successfully opened. <dl compact><dt><b>Parameters: </b></dt><dd><table border=0 cellspacing=2 cellpadding=0><tr><td valign=top><em>opts</em> </td><td>Mode in which to open the file. <a class="el" href="classPFile.html#z125_1">OpenOptions</a> enum# for open operation. </td></tr></table></dl> </td> </tr></table><a name="z125_4" doxytag="PFile::PFile"></a><p><table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> PINLINE PFile::PFile </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">const <a class="el" href="classPFilePath.html">PFilePath</a> & </td> <td class="mdname" nowrap> <em>name</em>, </td> </tr> <tr> <td></td> <td></td> <td class="md" nowrap><a class="el" href="classPFile.html#z125_0">OpenMode</a> </td> <td class="mdname" nowrap> <em>mode</em> = ReadWrite, </td> </tr> <tr> <td></td> <td></td> <td class="md" nowrap>int </td> <td class="mdname" nowrap> <em>opts</em> = ModeDefault</td> </tr> <tr> <td></td> <td class="md">) </td> <td class="md" colspan="2"></td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p>Create a file object with the specified name and open it in the specified mode and with the specified options.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -