PixelLightAPI  .
Public Member Functions | Protected Member Functions | Protected Attributes
PLCore::FileObject Class Reference

Base class for files and directories. More...

#include <FileObject.h>

Inheritance diagram for PLCore::FileObject:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 FileObject ()
 Constructor.
 FileObject (const String &sUrl, const FileAccess *pAccess=nullptr)
 Constructor.
 FileObject (const Url &cUrl, const FileAccess *pAccess=nullptr)
 Constructor.
virtual ~FileObject ()
 Destructor.
void Assign (const String &sUrl, const FileAccess *pAccess=nullptr)
 Assign a new URL.
PLCORE_API void Assign (const Url &cUrl, const FileAccess *pAccess=nullptr)
 Assign a new URL.
PLCORE_API void Assign (FILE *pFile, uint32 nAccess)
 Assign a new file.
PLCORE_API void Assign (handle hFile)
 Assign a new file.
const UrlGetUrl () const
 Get URL.
bool Exists () const
 Check if the file or directory exists.
bool IsFile () const
 Returns if the object is a regular file.
bool IsDirectory () const
 Returns if the object is a directory.
bool Copy (const String &sDestination, bool bOverwrite=false) const
 Copy the file or directory to a new location.
bool Move (const String &sDestination)
 Move the file or directory to a new location.
bool Rename (const String &sName)
 Rename the file or directory.
void Close ()
 Close the file or directory.

Protected Member Functions

PLCORE_API FileObject (FILE *pFile, uint32 nAccess)
 Constructor for a standard OS stream.
PLCORE_API FileObject (handle hFile)
 Constructor for a OS file handle.
PLCORE_API bool GenericCopy (const String &sDestination, bool bOverwrite=false) const
 Generic implementation of 'Copy()' (if system-implementation does not work)
PLCORE_API bool GenericMove (const String &sDestination)
 Generic implementation of 'Move()' (if system-implementation does not work)

Protected Attributes

FileImplm_pFileImpl
Url m_cNullUrl

Detailed Description

Base class for files and directories.

Remarks:
When working with archive file objects, you have to differ whether you want to use the archive files as 'file' or whether you want do use it as 'directory'. Here some examples: FileObject("test.zip") .IsFile() -> true FileObject("test.zip") .IsDirectory() -> false FileObject("test.zip/").IsFile() -> false FileObject("test.zip/").IsDirectory() -> true
Note:
  • Implementation of the state design pattern, this class is the context

Constructor & Destructor Documentation

PLCore::FileObject::FileObject ( const String sUrl,
const FileAccess pAccess = nullptr 
) [inline]

Constructor.

Parameters:
[in]sUrlURL of the file or directory
[in]pAccessAdditional file access information (can be a null pointer)
PLCore::FileObject::FileObject ( const Url cUrl,
const FileAccess pAccess = nullptr 
) [inline]

Constructor.

Parameters:
[in]cUrlURL of the file or directory
[in]pAccessAdditional file access information (can be a null pointer)
PLCore::FileObject::~FileObject ( ) [inline, virtual]

Destructor.

Note:
  • The file object is closed automatically
PLCore::FileObject::FileObject ( FILE *  pFile,
uint32  nAccess 
) [inline, protected]

Constructor for a standard OS stream.

Parameters:
[in]pFileStandard stream pointer
[in]nAccessAccess flags that were used to open the stream
PLCore::FileObject::FileObject ( handle  hFile) [inline, protected]

Constructor for a OS file handle.

Parameters:
[in]hFileOS file handle

Member Function Documentation

void PLCore::FileObject::Assign ( const String sUrl,
const FileAccess pAccess = nullptr 
) [inline]

Assign a new URL.

Parameters:
[in]sUrlURL of the file or directory
[in]pAccessAdditional file access information (can be a null pointer)
PLCORE_API void PLCore::FileObject::Assign ( const Url cUrl,
const FileAccess pAccess = nullptr 
)

Assign a new URL.

Parameters:
[in]cUrlURL of the file or directory
[in]pAccessAdditional file access information (can be a null pointer)
PLCORE_API void PLCore::FileObject::Assign ( FILE *  pFile,
uint32  nAccess 
)

Assign a new file.

Parameters:
[in]pFileStandard stream pointer
[in]nAccessAccess flags that were used to open the stream
PLCORE_API void PLCore::FileObject::Assign ( handle  hFile)

Assign a new file.

Parameters:
[in]hFileOS file handle
Note:
  • On Linux, the handle is a file handle of type int.
  • On Windows, the handle is a file handle of type HANDLE. Do not expect an int (fileno) here! If you need it to work with low level io functions, you need to convert the HANDLE to a file handle by yourself (see _open_osfhandle).
const Url & PLCore::FileObject::GetUrl ( ) const [inline]

Get URL.

Returns:
URL of the file
Note:
  • The URL of a 'FileObject' always contains a filename that never ends with "/"! (so, you can safely use 'Url::GetFilename()' to get the name of any file or directory)
  • e.g.: 'Directory("C:\\test")' and 'Directory("C:\\test\\")' are equal, but 'GetUrl()' will always return "C:/test".
bool PLCore::FileObject::Exists ( ) const [inline]

Check if the file or directory exists.

Returns:
'true', if the object is existing, else 'false'
bool PLCore::FileObject::IsFile ( ) const [inline]

Returns if the object is a regular file.

Returns if the object is a file.

Returns:
'true', if the object is a file, else 'false'
bool PLCore::FileObject::IsDirectory ( ) const [inline]

Returns if the object is a directory.

Returns:
'true', if the object is a directory, else 'false'
bool PLCore::FileObject::Copy ( const String sDestination,
bool  bOverwrite = false 
) const [inline]

Copy the file or directory to a new location.

Parameters:
[in]sDestinationURL of the destination
[in]bOverwriteShall the file be overwritten if it already exists?
Returns:
'true', if all went fine, else 'false'
bool PLCore::FileObject::Move ( const String sDestination) [inline]

Move the file or directory to a new location.

Parameters:
[in]sDestinationURL of the destination
Returns:
'true', if all went fine, else 'false'
bool PLCore::FileObject::Rename ( const String sName) [inline]

Rename the file or directory.

Parameters:
[in]sNameNew filename (filename only, no path)
Returns:
'true', if all went fine, else 'false'
void PLCore::FileObject::Close ( ) [inline]

Close the file or directory.

Reimplemented in PLCore::File.

PLCORE_API bool PLCore::FileObject::GenericCopy ( const String sDestination,
bool  bOverwrite = false 
) const [protected]

Generic implementation of 'Copy()' (if system-implementation does not work)

Parameters:
[in]sDestinationURL of the destination
[in]bOverwriteShall the file be overwritten if it already exists?
Returns:
'true', if all went fine, else 'false'
PLCORE_API bool PLCore::FileObject::GenericMove ( const String sDestination) [protected]

Generic implementation of 'Move()' (if system-implementation does not work)

Parameters:
[in]sDestinationURL of the destination
Returns:
'true', if all went fine, else 'false'

Member Data Documentation

Platform implementation for file object (can be a null pointer)

Empty URL


The documentation for this class was generated from the following files:


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:09:25
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported