more revisions of f*h headers

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55861 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Francesco Montorsi
2008-09-25 14:03:38 +00:00
parent bd84061db3
commit 23b7f0cbd0
3 changed files with 153 additions and 88 deletions

View File

@@ -6,6 +6,29 @@
// Licence: wxWindows license // Licence: wxWindows license
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
//@{
/**
These constants define the file access rights and are used with wxFile::Create and wxFile::Open.
*/
#define wxS_IRUSR 00400
#define wxS_IWUSR 00200
#define wxS_IXUSR 00100
#define wxS_IRGRP 00040
#define wxS_IWGRP 00020
#define wxS_IXGRP 00010
#define wxS_IROTH 00004
#define wxS_IWOTH 00002
#define wxS_IXOTH 00001
/** Default mode for the new files: corresponds to umask 022 */
#define wxS_DEFAULT (wxS_IRUSR | wxS_IWUSR | wxS_IRGRP | wxS_IWGRP | wxS_IROTH | wxS_IWOTH)
//@}
/** /**
@class wxTempFile @class wxTempFile
@@ -14,10 +37,10 @@
just a temporary file if you don't replace the old file contents. just a temporary file if you don't replace the old file contents.
Usually, when a program replaces the contents of some file it first opens it for Usually, when a program replaces the contents of some file it first opens it for
writing, thus losing all of the old data and then starts recreating it. This writing, thus losing all of the old data and then starts recreating it.
approach is not very safe because during the regeneration of the file bad things This approach is not very safe because during the regeneration of the file bad
may happen: the program may find that there is an internal error preventing it things may happen: the program may find that there is an internal error preventing
from completing file generation, the user may interrupt it (especially if file it from completing file generation, the user may interrupt it (especially if file
generation takes long time) and, finally, any other external interrupts (power generation takes long time) and, finally, any other external interrupts (power
supply failure or a disk error) will leave you without either the original file supply failure or a disk error) will leave you without either the original file
or the new one. or the new one.
@@ -27,20 +50,18 @@
interrupts the program during the file generation, the old file won't be lost. interrupts the program during the file generation, the old file won't be lost.
Also, if the program discovers itself that it doesn't want to replace the old Also, if the program discovers itself that it doesn't want to replace the old
file there is no problem - in fact, wxTempFile will @b not replace the old file there is no problem - in fact, wxTempFile will @b not replace the old
file by default, you should explicitly call wxTempFile::Commit file by default, you should explicitly call wxTempFile::Commit() to do it.
to do it. Calling wxTempFile::Discard explicitly discards any Calling wxTempFile::Discard() explicitly discards any modifications: it
modifications: it closes and deletes the temporary file and leaves the original closes and deletes the temporary file and leaves the original file unchanged.
file unchanged. If you don't call neither of Commit() and Discard(), the If you don't call neither of Commit() and Discard(), the destructor will
destructor will call Discard() automatically. call Discard() automatically.
To summarize: if you want to replace another file, create an instance of To summarize: if you want to replace another file, create an instance of
wxTempFile passing the name of the file to be replaced to the constructor (you wxTempFile passing the name of the file to be replaced to the constructor
may also use default constructor and pass the file name to (you may also use default constructor and pass the file name to wxTempFile::Open).
wxTempFile::Open). Then you can wxTempFile::write Then you can write to wxTempFile using wxFile-like functions and later call
to wxTempFile using wxFile-like functions and later call wxTempFile::Commit() to replace the old file (and close this one) or call
Commit() to replace the old file (and close this one) or call Discard() to wxTempFile::Discard() to cancel the modifications.
cancel
the modifications.
@library{wxbase} @library{wxbase}
@category{file} @category{file}
@@ -49,23 +70,23 @@ class wxTempFile
{ {
public: public:
/** /**
Associates wxTempFile with the file to be replaced and opens it. You should use Associates wxTempFile with the file to be replaced and opens it.
IsOpened() to verify if the constructor succeeded. You should use IsOpened() to verify if the constructor succeeded.
*/ */
wxTempFile(const wxString& strName); wxTempFile(const wxString& strName);
/** /**
Destructor calls Discard() if temporary file Destructor calls Discard() if temporary file is still opened.
is still opened.
*/ */
~wxTempFile(); ~wxTempFile();
/** /**
Validate changes: deletes the old file of name m_strName and renames the new Validate changes: deletes the old file of name m_strName and renames the new
file to the old name. Returns @true if both actions succeeded. If @false is file to the old name. Returns @true if both actions succeeded.
returned it may unfortunately mean two quite different things: either that
either the old file couldn't be deleted or that the new file couldn't be renamed If @false is returned it may unfortunately mean two quite different things:
to the old name. either that either the old file couldn't be deleted or that the new file
couldn't be renamed to the old name.
*/ */
bool Commit(); bool Commit();
@@ -85,9 +106,10 @@ public:
This method may return wxInvalidOffset if the length couldn't be This method may return wxInvalidOffset if the length couldn't be
determined or also 0 even for non-empty files if the file is not determined or also 0 even for non-empty files if the file is not
seekable. In general, the only way to determine if the file for which seekable.
this function returns 0 is really empty or not is to try reading from
it. In general, the only way to determine if the file for which this function
returns 0 is really empty or not is to try reading from it.
*/ */
wxFileOffset Length() const; wxFileOffset Length() const;
@@ -95,9 +117,9 @@ public:
Open the temporary file, returns @true on success, @false if an error Open the temporary file, returns @true on success, @false if an error
occurred. occurred.
@a strName is the name of file to be replaced. The temporary file is always @a strName is the name of file to be replaced. The temporary file is always
created in the directory where @a strName is. In particular, if created in the directory where @a strName is. In particular, if @a strName
@a strName doesn't include the path, it is created in the current directory doesn't include the path, it is created in the current directory and the
and the program should have write access to it for the function to succeed. program should have write access to it for the function to succeed.
*/ */
bool Open(const wxString& strName); bool Open(const wxString& strName);
@@ -108,9 +130,8 @@ public:
wxSeekMode mode = wxFromStart); wxSeekMode mode = wxFromStart);
/** /**
Returns the current position or wxInvalidOffset if file is not opened or if Returns the current position or wxInvalidOffset if file is not opened or
another if another error occurred.
error occurred.
*/ */
wxFileOffset Tell() const; wxFileOffset Tell() const;
@@ -128,18 +149,27 @@ public:
/** /**
@class wxFile @class wxFile
A wxFile performs raw file I/O.
This is a very small class designed to minimize the overhead of using it - in fact,
there is hardly any overhead at all, but using it brings you automatic error
checking and hides differences between platforms and compilers.
wxFile also automatically closes the file in its destructor making it unnecessary
to worry about forgetting to do it.
A wxFile performs raw file I/O. This is a very small class designed to A wxFile performs raw file I/O. This is a very small class designed to
minimize the overhead of using it - in fact, there is hardly any overhead at minimize the overhead of using it - in fact, there is hardly any overhead at
all, but using it brings you automatic error checking and hides differences all, but using it brings you automatic error checking and hides differences
between platforms and compilers. wxFile also automatically closes the file in between platforms and compilers. wxFile also automatically closes the file in
its destructor making it unnecessary to worry about forgetting to do it. its destructor making it unnecessary to worry about forgetting to do it.
wxFile is a wrapper around @c file descriptor. - see also wxFile is a wrapper around @c file descriptor. - see also wxFFile for a
wxFFile for a wrapper around @c FILE structure. wrapper around @c FILE structure.
@c wxFileOffset is used by the wxFile functions which require offsets as ::wxFileOffset is used by the wxFile functions which require offsets as
parameter or return them. If the platform supports it, wxFileOffset is a typedef parameter or return them. If the platform supports it, wxFileOffset is a
for a native 64 bit integer, otherwise a 32 bit integer is used for typedef for a native 64 bit integer, otherwise a 32 bit integer is used for
wxFileOffset. ::wxFileOffset.
@library{wxbase} @library{wxbase}
@category{file} @category{file}
@@ -147,38 +177,66 @@ public:
class wxFile class wxFile
{ {
public: public:
/** /**
Opening mode The OpenMode enumeration defines the different modes for opening a file with wxFile.
It is also used with wxFile::Access function.
*/ */
enum OpenMode { read, write, read_write, write_append, write_excl }; enum OpenMode {
/** /** Open file for reading or test if it can be opened for reading with Access() */
read,
/** Open file for writing deleting the contents of the file if it already exists
or test if it can be opened for writing with Access(). */
write,
/** Open file for reading and writing; can not be used with Access() */
read_write,
/** Open file for appending: the file is opened for writing, but the old contents
of the file is not erased and the file pointer is initially placed at the end
of the file; can not be used with Access().
This is the same as OpenMode::write if the file doesn't exist.
*/
write_append,
/**
Open the file securely for writing (Uses O_EXCL | O_CREAT).
Will fail if the file already exists, else create and open it atomically.
Useful for opening temporary files without being vulnerable to race exploits.
*/
write_excl
};
/**
Standard file descriptors Standard file descriptors
*/ */
enum { fd_invalid = -1, fd_stdin, fd_stdout, fd_stderr }; enum { fd_invalid = -1, fd_stdin, fd_stdout, fd_stderr };
/** /**
Default constructor. Default constructor.
*/ */
wxFile(); wxFile();
/** /**
Opens a file with a filename. Opens a file with a filename.
@param filename @param filename
The filename. The filename.
@param mode @param mode
The mode in which to open the file. May be one of @c wxFile::read, The mode in which to open the file.
@c wxFile::write and @c wxFile::read_write.
*/ */
wxFile(const wxString& filename, wxFile(const wxString& filename,
wxFile::OpenMode mode = wxFile::read); wxFile::OpenMode mode = wxFile::read);
/** /**
Associates the file with the given file descriptor, which has already been Associates the file with the given file descriptor, which has already been
opened. See Attach() for the list of predefined descriptors. opened. See Attach() for the list of predefined descriptors.
@param fd @param fd
An existing file descriptor. An existing file descriptor.
*/ */
wxFile(int fd); wxFile(int fd);
@@ -192,14 +250,14 @@ public:
This function verifies if we may access the given file in specified mode. This function verifies if we may access the given file in specified mode.
Only values of @c wxFile::read or @c wxFile::write really make sense here. Only values of @c wxFile::read or @c wxFile::write really make sense here.
*/ */
static bool Access(const wxString& name, OpenMode mode); static bool Access(const wxString& name, wxFile::OpenMode mode);
/** /**
Attaches an existing file descriptor to the wxFile object. Example of Attaches an existing file descriptor to the wxFile object.
predefined file descriptors are 0, 1 and 2 which correspond to stdin, Example of predefined file descriptors are 0, 1 and 2 which correspond to
stdout and stderr (and have symbolic names of @c wxFile::fd_stdin, stdin, stdout and stderr (and have symbolic names of @c wxFile::fd_stdin,
@c wxFile::fd_stdout and @c wxFile::fd_stderr). @c wxFile::fd_stdout and @c wxFile::fd_stderr).
The descriptor should be already opened and it will be closed by wxFile The descriptor should be already opened and it will be closed by wxFile
object. object.
*/ */
@@ -211,53 +269,60 @@ public:
void Close(); void Close();
/** /**
Creates a file for writing. If the file already exists, setting @b overwrite to Creates a file for writing.
@true
will ensure it is overwritten. If the file already exists, setting @b overwrite to @true will ensure
it is overwritten.
@a access may be an OR combination of the file access values
like ::wxS_IRUSR, ::wxS_IWUSR, etc, etc.
*/ */
bool Create(const wxString& filename, bool overwrite = false, bool Create(const wxString& filename,
bool overwrite = false,
int access = wxS_DEFAULT); int access = wxS_DEFAULT);
/** /**
Get back a file descriptor from wxFile object - the caller is responsible for Get back a file descriptor from wxFile object - the caller is responsible for
closing the file if this closing the file if this descriptor is opened.
descriptor is opened. IsOpened() will return @false after call to Detach(). IsOpened() will return @false after call to Detach().
*/ */
void Detach(); void Detach();
/** /**
Returns @true if the end of the file has been reached. Returns @true if the end of the file has been reached.
Note that the behaviour of the file pointer based class Note that the behaviour of the file pointer based class wxFFile is
wxFFile is different as wxFFile::Eof will return @true here only if an different as wxFFile::Eof() will return @true here only if an
attempt has been made to read @b past the last byte of the file, while attempt has been made to read @b past the last byte of the file, while
wxFile::Eof() will return @true even before such attempt is made if the wxFile::Eof() will return @true even before such attempt is made if the
file pointer is at the last position in the file. file pointer is at the last position in the file.
Note also that this function doesn't work on unseekable file descriptors Note also that this function doesn't work on unseekable file descriptors
(examples include pipes, terminals and sockets under Unix) and an attempt to (examples include pipes, terminals and sockets under Unix) and an attempt to
use it will result in an error message in such case. So, to read the entire use it will result in an error message in such case.
file into memory, you should write a loop which uses
Read() repeatedly and tests its return condition instead So, to read the entire file into memory, you should write a loop which uses
of using Eof() as this will not work for special files under Unix. Read() repeatedly and tests its return condition instead of using Eof()
as this will not work for special files under Unix.
*/ */
bool Eof() const; bool Eof() const;
/** /**
Returns @true if the given name specifies an existing regular file (not a Returns @true if the given name specifies an existing regular file
directory or a link) (not a directory or a link)
*/ */
static bool Exists(const wxString& filename); static bool Exists(const wxString& filename);
/** /**
Flushes the file descriptor. Flushes the file descriptor.
Note that Flush() is not implemented on some Windows compilers
due to a missing fsync function, which reduces the usefulness of this function Note that Flush() is not implemented on some Windows compilers due to a
missing fsync function, which reduces the usefulness of this function
(it can still be called but it will do nothing on unsupported compilers). (it can still be called but it will do nothing on unsupported compilers).
*/ */
bool Flush(); bool Flush();
/** /**
Returns the type of the file. Possible return values are: Returns the type of the file.
*/ */
wxFileKind GetKind() const; wxFileKind GetKind() const;
@@ -277,21 +342,20 @@ public:
@param filename @param filename
The filename. The filename.
@param mode @param mode
The mode in which to open the file. May be one of read(), write() and The mode in which to open the file.
wxFile::read_write.
*/ */
bool Open(const wxString& filename, bool Open(const wxString& filename,
wxFile::OpenMode mode = wxFile::read); wxFile::OpenMode mode = wxFile::read);
/** /**
Reads from the file into a memory buffer. Reads from the file into a memory buffer.
@param buffer @param buffer
Buffer to write in Buffer to write in
@param count @param count
Bytes to read Bytes to read
@return The number of bytes read, or the symbol wxInvalidOffset @return The number of bytes read, or the symbol wxInvalidOffset.
*/ */
size_t Read(void* buffer, size_t count); size_t Read(void* buffer, size_t count);
@@ -304,38 +368,38 @@ public:
One of wxFromStart, wxFromEnd, wxFromCurrent. One of wxFromStart, wxFromEnd, wxFromCurrent.
@return The actual offset position achieved, or wxInvalidOffset on @return The actual offset position achieved, or wxInvalidOffset on
failure. failure.
*/ */
wxFileOffset Seek(wxFileOffset ofs, wxFileOffset Seek(wxFileOffset ofs,
wxSeekMode mode = wxFromStart); wxSeekMode mode = wxFromStart);
/** /**
Moves the file pointer to the specified number of bytes relative to the end of Moves the file pointer to the specified number of bytes relative to the
the file. For example, @c SeekEnd(-5) would position the pointer 5 end of the file. For example, @c SeekEnd(-5) would position the pointer 5
bytes before the end. bytes before the end.
@param ofs @param ofs
Number of bytes before the end of the file. Number of bytes before the end of the file.
@return The actual offset position achieved, or wxInvalidOffset on @return The actual offset position achieved, or wxInvalidOffset on
failure. failure.
*/ */
wxFileOffset SeekEnd(wxFileOffset ofs = 0); wxFileOffset SeekEnd(wxFileOffset ofs = 0);
/** /**
Returns the current position or wxInvalidOffset if file is not opened or Returns the current position or wxInvalidOffset if file is not opened or
if another error occurred. if another error occurred.
*/ */
wxFileOffset Tell() const; wxFileOffset Tell() const;
/** /**
Write data to the file (descriptor). Write data to the file (descriptor).
@param buffer @param buffer
Buffer from which to read data Buffer from which to read data
@param count @param count
Number of bytes to write Number of bytes to write
@return The number of bytes written. @return The number of bytes written.
*/ */
size_t Write(const void *buffer, size_t count); size_t Write(const void *buffer, size_t count);
@@ -344,6 +408,7 @@ public:
Writes the contents of the string to the file, returns @true on success. Writes the contents of the string to the file, returns @true on success.
The second argument is only meaningful in Unicode build of wxWidgets when The second argument is only meaningful in Unicode build of wxWidgets when
@a conv is used to convert @a s to a multibyte representation. @a conv is used to convert @a s to a multibyte representation.
Note that this method only works with @c NUL-terminated strings, if you want Note that this method only works with @c NUL-terminated strings, if you want
to write data with embedded @c NULs to the file you should use the other to write data with embedded @c NULs to the file you should use the other
Write() overload. Write() overload.

View File

@@ -40,7 +40,7 @@
The current folder of the file control has been changed The current folder of the file control has been changed
@endEventTable @endEventTable
@nativeimpl{gtk} @nativeimpl{wxgtk}
@library{wxbase} @library{wxbase}
@category{miscwnd} @category{miscwnd}

View File

@@ -58,7 +58,7 @@
@library{wxcore} @library{wxcore}
@category{cmndlg} @category{cmndlg}
@see @ref overview_wxfiledialog, ::wxFileSelector() @see @ref overview_cmndlg_file, ::wxFileSelector()
*/ */
class wxFileDialog : public wxDialog class wxFileDialog : public wxDialog
{ {