?? file.h
字號(hào):
//
// File.h
//
// $Id: //poco/Main/Foundation/include/Foundation/File.h#5 $
//
// Definition of the File class.
//
// Copyright (c) 2004, Guenter Obiltschnig/Applied Informatics.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Redistributions in any form must be accompanied by information on
// how to obtain complete source code for this software and any
// accompanying software that uses this software. The source code
// must either be included in the distribution or be available for no
// more than the cost of distribution plus a nominal fee, and must be
// freely redistributable under reasonable conditions. For an
// executable file, complete source code means the source code for all
// modules it contains. It does not include source code for modules or
// files that typically accompany the major components of the operating
// system on which the executable file runs.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef Foundation_File_INCLUDED
#define Foundation_File_INCLUDED
#ifndef Foundation_Foundation_INCLUDED
#include "Foundation/Foundation.h"
#endif
#ifndef Foundation_Timestamp_INCLUDED
#include "Foundation/Timestamp.h"
#endif
#ifndef STD_VECTOR_INCLUDED
#include <vector>
#define STD_VECTOR_INCLUDED
#endif
#if defined(POCO_OS_FAMILY_WINDOWS)
#include "Foundation/File_WIN32.h"
#elif defined(POCO_OS_FAMILY_UNIX)
#include "Foundation/File_UNIX.h"
#else
#include "Foundation/File_VMS.h"
#endif
Foundation_BEGIN
class Path;
class Foundation_API File: private FileImp
/// The File class provides methods for working with a file.
{
public:
typedef FileSizeImp FileSize;
File();
/// Creates the file.
File(const std::string& path);
/// Creates the file.
File(const char* path);
/// Creates the file.
File(const Path& path);
/// Creates the file.
File(const File& file);
/// Copy constructor.
virtual ~File();
/// Destroys the file.
File& operator = (const File& file);
/// Assignment operator.
File& operator = (const std::string& path);
/// Assignment operator.
File& operator = (const char* path);
/// Assignment operator.
File& operator = (const Path& path);
/// Assignment operator.
const std::string& path() const;
/// Returns the path.
bool exists() const;
/// Returns true iff the file exists.
bool canRead() const;
/// Returns true iff the file is readable.
bool canWrite() const;
/// Returns true iff the file is writeable.
bool isFile() const;
/// Returns true iff the file is a regular file.
bool isDirectory() const;
/// Returns true iff the file is a directory.
Timestamp created() const;
/// Returns the creation date of the file.
Timestamp getLastModified() const;
/// Returns the modification date of the file.
void setLastModified(const Timestamp& ts);
/// Sets the modification date of the file.
FileSize getSize() const;
/// Returns the size of the file in bytes.
void setSize(FileSize size);
/// Sets the size of the file in bytes. Can be used
/// to truncate a file.
void setWriteable(bool flag = true);
/// Makes the file writeable (if flag is true), or
/// non-writeable (if flag is false) by setting the
/// file's flags in the filesystem accordingly.
void setReadOnly(bool flag = true);
/// Makes the file non-writeable (if flag is true), or
/// writeable (if flag is false) by setting the
/// file's flags in the filesystem accordingly.
void copyTo(const std::string& path) const;
/// Copies the file to the given path. The target path
/// can be a directory.
void moveTo(const std::string& path);
/// Copies the file to the given path and removes the
/// original file. The target path can be a directory.
void renameTo(const std::string& path);
/// Renames the file to the new name.
void remove(bool recursive = false);
/// Deletes the file. If recursive is true and the
/// file is a directory, recursively deletes all
/// files in the directory.
bool createFile();
/// Creates a new, empty file in an atomic operation.
/// Returns true if the file has been created and false
/// if the file already exists. Throws an exception if
/// an error occurs.
bool createDirectory();
/// Creates a directory. Returns true if the directory
/// has been created and false if it already exists.
/// Throws an exception if an error occurs.
void createDirectories();
/// Creates a directory (and all parent directories
/// if necessary).
void list(std::vector<std::string>& files) const;
/// Fills the vector with the names of all
/// files in the directory.
void list(std::vector<File>& files) const;
/// Fills the vector with the names of all
/// files in the directory.
bool operator == (const File& file) const;
bool operator != (const File& file) const;
bool operator < (const File& file) const;
bool operator <= (const File& file) const;
bool operator > (const File& file) const;
bool operator >= (const File& file) const;
};
//
// inlines
//
inline const std::string& File::path() const
{
return getPathImp();
}
inline bool File::operator == (const File& file) const
{
return getPathImp() == file.getPathImp();
}
inline bool File::operator != (const File& file) const
{
return getPathImp() != file.getPathImp();
}
inline bool File::operator < (const File& file) const
{
return getPathImp() < file.getPathImp();
}
inline bool File::operator <= (const File& file) const
{
return getPathImp() <= file.getPathImp();
}
inline bool File::operator > (const File& file) const
{
return getPathImp() > file.getPathImp();
}
inline bool File::operator >= (const File& file) const
{
return getPathImp() >= file.getPathImp();
}
Foundation_END
#endif // Foundation_File_INCLUDED
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -