NCBI C++ ToolKit
Public Types | Public Member Functions | Private Types | List of all members
CFile Class Reference

Search Toolkit Book for CFile

CFile –. More...

#include <corelib/ncbifile.hpp>

+ Inheritance diagram for CFile:
+ Collaboration diagram for CFile:

Public Types

enum  ECompareText { eIgnoreEol = eCompareText_IgnoreEol , eIgnoreWs = eCompareText_IgnoreWhiteSpace }
 Mode to compare streams in text form. More...
 
- Public Types inherited from CDirEntry
enum  EIfEmptyPath { eIfEmptyPath_Empty , eIfEmptyPath_Current }
 What GetDir() should return if the dir entry does not contain path. More...
 
enum  ERelativeToWhat { eRelativeToCwd , eRelativeToExe }
 How to interpret relative paths. More...
 
enum  ECopyFlags {
  fCF_Overwrite = (1 << 1) , fCF_Update = (1 << 2) | fCF_Overwrite , fCF_Backup = (1 << 3) | fCF_Overwrite , fCF_Safe = (1 << 4) | fCF_Overwrite ,
  fCF_TopDirOnly = (1 << 6) , fCF_EqualTypes = (1 << 7) , fCF_FollowLinks = (1 << 8) , fCF_Verify = (1 << 9) ,
  fCF_PreserveOwner = (1 << 10) , fCF_PreservePerm = (1 << 11) , fCF_PreserveTime = (1 << 12) , fCF_PreserveAll = fCF_PreserveOwner | fCF_PreservePerm | fCF_PreserveTime ,
  fCF_Recursive = (1 << 14) , fCF_SkipUnsupported = (1 << 15) , fCF_Default = fCF_Recursive | fCF_FollowLinks
}
 Copy flags. More...
 
enum  ERenameFlags {
  fRF_Overwrite = (1 << 1) , fRF_Update = (1 << 2) | fCF_Overwrite , fRF_Backup = (1 << 3) | fCF_Overwrite , fRF_EqualTypes = (1 << 4) ,
  fRF_FollowLinks = (1 << 5) , fRF_Default = 0
}
 Rename flags. More...
 
enum  EBackupMode { eBackup_Copy = (1 << 1) , eBackup_Rename = (1 << 2) , eBackup_Default = eBackup_Copy }
 Backup modes. More...
 
enum  EProcessingFlags {
  fEntry = (1 << 0) , fDir_Self = fEntry , fDir_Files = (1 << 1) , fDir_Subdirs = (1 << 2) ,
  fDir_Recursive = (1 << 3) , fDir_All = fDir_Self + fDir_Files + fDir_Subdirs , fIgnoreMissing = (1 << 4) , fProcessAll = (1 << 5) ,
  eOnlyEmpty = fDir_Self , eEntryOnly = fDir_Self , eTopDirOnly = fDir_Self | fDir_Files , eNonRecursive = fDir_All ,
  eRecursive = fDir_All | fDir_Recursive , eRecursiveStopOnErrors = eRecursive , eRecursiveIgnoreMissing = eRecursive | fIgnoreMissing , eRecursiveNotStopOnErrors = eRecursive | fIgnoreMissing | fProcessAll
}
 Entries processing flags. More...
 
enum  EType {
  eFile = 0 , eDir , ePipe , eLink ,
  eSymLink = eLink , eSocket , eDoor , eBlockSpecial ,
  eCharSpecial , eUnknown
}
 Directory entry type. More...
 
enum  EIfAbsent { eIfAbsent_Throw , eIfAbsent_Newer , eIfAbsent_NotNewer }
 What IsNewer() should do if the dir entry does not exist or is not accessible. More...
 
enum  EIfAbsent2 {
  fHasThisNoPath_Newer = (1 << 0) , fHasThisNoPath_NotNewer = (1 << 1) , fNoThisHasPath_Newer = (1 << 2) , fNoThisHasPath_NotNewer = (1 << 3) ,
  fNoThisNoPath_Newer = (1 << 4) , fNoThisNoPath_NotNewer = (1 << 5)
}
 What path version of IsNewer() should do if the dir entry or specified path does not exist or is not accessible. More...
 
enum  EMode {
  fExecute = 1 , fWrite = 2 , fRead = 4 , fDefault = 8 ,
  fDefaultDirUser = fRead | fExecute | fWrite , fDefaultDirGroup = fRead | fExecute , fDefaultDirOther = fRead | fExecute , fDefaultUser = fRead | fWrite ,
  fDefaultGroup = fRead , fDefaultOther = fRead
}
 Directory entry access permissions. More...
 
enum  ESpecialModeBits { fSticky = 1 , fSetGID = 2 , fSetUID = 4 }
 
enum  EModeRelative { fModeAdd = 16 , fModeRemove = 32 , fModeNoChange = 64 }
 Relative permissions change modes. More...
 
enum  EModeStringFormat { eModeFormat_Octal , eModeFormat_Symbolic , eModeFormat_List , eModeFormat_Default = eModeFormat_Octal }
 Permission mode string format. More...
 
enum  ETmpFileCreationMode { eTmpFileCreate , eTmpFileGetName }
 Temporary file creation mode. More...
 
enum  ETextBinary { eText , eBinary }
 What type of temporary file to create. More...
 
enum  EAllowRead { eAllowRead , eWriteOnly }
 Which operations to allow on temporary file. More...
 
typedef unsigned int TCopyFlags
 Binary OR of "ECopyFlags". More...
 
typedef unsigned int TRenameFlags
 Binary OR of "ERenameFlags". More...
 
typedef unsigned int TProcessingFlags
 Binary OR of "EProcessingFlags". More...
 
typedef TProcessingFlags TRemoveFlags
 Flags based on TProcessingFlags. More...
 
typedef TProcessingFlags TSetModeFlags
 
typedef TRemoveFlags EDirRemoveMode
 Directory remove mode. More...
 
typedef int TIfAbsent2
 Binary OR of "EIfAbsent2". More...
 
typedef unsigned int TMode
 Bitwise OR of "EMode". More...
 
typedef unsigned int TSpecialModeBits
 Bitwise OR of ESpecialModeBits. More...
 

Public Member Functions

 CFile (void)
 Default constructor. More...
 
 CFile (const string &file)
 Constructor using specified path string. More...
 
 CFile (const CDirEntry &file)
 Copy constructor. More...
 
virtual ~CFile (void)
 Destructor. More...
 
virtual EType GetObjectType (void) const
 Get a type of constructed object. More...
 
virtual bool Exists (void) const
 Check existence of file. More...
 
Int8 GetLength (void) const
 Get size of file. More...
 
virtual bool Copy (const string &new_path, TCopyFlags flags=fCF_Default, size_t buf_size=0) const
 Copy a file. More...
 
bool Compare (const string &file, size_t buf_size=0) const
 Compare files contents in binary form. More...
 
bool CompareTextContents (const string &file, ECompareText mode, size_t buf_size=0) const
 Compare files contents in text form. More...
 
- Public Member Functions inherited from CDirEntry
 CDirEntry (void)
 Default constructor. More...
 
 CDirEntry (const string &path)
 Constructor using specified path string. More...
 
 CDirEntry (const CDirEntry &other)
 Copy constructor. More...
 
virtual ~CDirEntry (void)
 Destructor. More...
 
const stringGetPath (void) const
 Get entry path. More...
 
void Reset (const string &path)
 Reset path string. More...
 
CDirEntryoperator= (const CDirEntry &other)
 Assignment operator. More...
 
string GetDir (EIfEmptyPath mode=eIfEmptyPath_Current) const
 Get the directory component for this directory entry. More...
 
string GetName (void) const
 Get the base entry name with extension (if any). More...
 
string GetBase (void) const
 Get the base entry name without extension. More...
 
string GetExt (void) const
 Get extension name. More...
 
bool CopyToDir (const string &dir, TCopyFlags flags=fCF_Default, size_t buf_size=0) const
 Copy the entry to a specified directory. More...
 
bool Rename (const string &new_path, TRenameFlags flags=fRF_Default)
 Rename entry. More...
 
bool MoveToDir (const string &dir, TCopyFlags flags=fRF_Default)
 Move the entry to a specified directory. More...
 
bool Backup (const string &suffix=kEmptyStr, EBackupMode mode=eBackup_Default, TCopyFlags copyflags=fCF_Default, size_t copybufsize=0)
 Backup an entry. More...
 
virtual bool Remove (TRemoveFlags flags=eRecursive) const
 Remove a directory entry. More...
 
virtual bool RemoveEntry (TRemoveFlags flags=eEntryOnly) const
 Remove a directory entry. More...
 
bool Stat (struct SStat *buffer, EFollowLinks follow_links=eIgnoreLinks) const
 Get status information on a dir entry. More...
 
EType GetType (EFollowLinks follow=eIgnoreLinks) const
 Get a type of a directory entry. More...
 
bool IsFile (EFollowLinks follow=eFollowLinks) const
 Check whether a directory entry is a file. More...
 
bool IsDir (EFollowLinks follow=eFollowLinks) const
 Check whether a directory entry is a directory. More...
 
bool IsLink (void) const
 Check whether a directory entry is a symbolic link (alias). More...
 
string LookupLink (void) const
 Get an entry name that a link points to. More...
 
void DereferenceLink (ENormalizePath normalize=eNormalizePath)
 Dereference a link. More...
 
void DereferencePath (void)
 Dereference a path. More...
 
bool GetTime (CTime *modification, CTime *last_access=0, CTime *creation=0) const
 Get time stamp(s) of a directory entry. More...
 
bool GetTimeT (time_t *modification, time_t *last_access=0, time_t *creation=0) const
 Get time stamp(s) of a directory entry (time_t version). More...
 
bool SetTime (const CTime *modification=0, const CTime *last_access=0, const CTime *creation=0) const
 Set time stamp(s) of a directory entry. More...
 
bool SetTimeT (const time_t *modification=0, const time_t *last_access=0, const time_t *creation=0) const
 Set time stamp(s) of a directory entry (time_t version). More...
 
bool IsNewer (time_t tm, EIfAbsent if_absent) const
 Check if the current entry is newer than a specified date/time. More...
 
bool IsNewer (const CTime &tm, EIfAbsent if_absent) const
 Check if the current entry is newer than a specified date/time. More...
 
bool IsNewer (const string &path, TIfAbsent2 if_absent) const
 Check if the current entry is newer than some other. More...
 
bool IsIdentical (const string &entry_name, EFollowLinks follow_links=eIgnoreLinks) const
 Check if the current entry and the given entry_name are identical. More...
 
bool GetOwner (string *owner, string *group=0, EFollowLinks follow=eFollowLinks, unsigned int *uid=0, unsigned int *gid=0) const
 Get an entry owner. More...
 
bool SetOwner (const string &owner, const string &group=kEmptyStr, EFollowLinks follow=eFollowLinks, unsigned int *uid=0, unsigned int *gid=0) const
 Set an entry owner and/or group. More...
 
bool GetMode (TMode *user_mode, TMode *group_mode=0, TMode *other_mode=0, TSpecialModeBits *special=0) const
 Get permission mode(s) of a directory entry. More...
 
virtual bool SetMode (TMode user_mode, TMode group_mode=fDefault, TMode other_mode=fDefault, TSpecialModeBits special=0, TSetModeFlags flags=eEntryOnly) const
 Set permission mode(s) of a directory entry. More...
 
virtual bool SetModeEntry (TMode user_mode, TMode group_mode=fDefault, TMode other_mode=fDefault, TSpecialModeBits special=0, TSetModeFlags flags=eEntryOnly) const
 Set permission mode(s) of a directory entry. More...
 
virtual void SetDefaultMode (EType entry_type, TMode user_mode, TMode group_mode=fDefault, TMode other_mode=fDefault, TSpecialModeBits special=0)
 Set default mode(s) for this entry only. More...
 
bool CheckAccess (TMode access_mode) const
 Check access rights. More...
 

Private Types

typedef CDirEntry CParent
 CDirEntry is the parent class. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from CDirEntry
static void SplitPath (const string &path, string *dir=0, string *base=0, string *ext=0)
 Split a path string into its basic components. More...
 
static void SplitPathEx (const string &path, string *disk=0, string *dir=0, string *base=0, string *ext=0)
 Split a path string into its basic components. More...
 
static string MakePath (const string &dir=kEmptyStr, const string &base=kEmptyStr, const string &ext=kEmptyStr)
 Assemble a path from basic components. More...
 
static char GetPathSeparator (void)
 Get path separator symbol specific for the current platform. More...
 
static bool IsPathSeparator (const char c)
 Check whether a character "c" is a path separator symbol specific for the current platform. More...
 
static string AddTrailingPathSeparator (const string &path)
 Add trailing path separator, if needed. More...
 
static string DeleteTrailingPathSeparator (const string &path)
 Delete trailing path separator, if any. More...
 
static string ConvertToOSPath (const string &path)
 Convert "path" on any OS to the current OS-dependent path. More...
 
static bool IsAbsolutePath (const string &path)
 Check if a "path" is absolute for the current OS. More...
 
static bool IsAbsolutePathEx (const string &path)
 Check if the "path" is absolute for any OS. More...
 
static string GetNearestExistingParentDir (const string &path)
 Given a path, gets the closest parent directory which actually exists. More...
 
static string CreateRelativePath (const string &path_from, const string &path_to)
 Create a relative path between two points in the file system specified by their absolute paths. More...
 
static string CreateAbsolutePath (const string &path, ERelativeToWhat rtw=eRelativeToCwd)
 Get an absolute path from some, possibly relative, path. More...
 
static string CreateAbsolutePath (const string &path, const string &rtw)
 Get an absolute path from some, possibly relative, path. More...
 
static string ConcatPath (const string &first, const string &second)
 Concatenate two parts of the path for the current OS. More...
 
static string ConcatPathEx (const string &first, const string &second)
 Concatenate two parts of the path for any OS. More...
 
static string NormalizePath (const string &path, EFollowLinks follow_links=eIgnoreLinks)
 Normalize a path. More...
 
static bool MatchesMask (const string &name, const string &mask, NStr::ECase use_case=NStr::eCase)
 Match a "name" against a simple filename "mask". More...
 
static bool MatchesMask (const string &name, const vector< string > &masks, NStr::ECase use_case=NStr::eCase)
 Match a "name" against a set of "masks" Note that any name match to empty vector of masks. More...
 
static bool MatchesMask (const string &name, const CMask &mask, NStr::ECase use_case=NStr::eCase)
 Match a "name" against a set of "masks" Note that any name match to empty set of masks. More...
 
static const char * GetBackupSuffix (void)
 Get backup suffix. More...
 
static void SetBackupSuffix (const char *suffix)
 Set backup suffix. More...
 
static CDirEntryCreateObject (EType type, const string &path=kEmptyStr)
 Construct a directory entry object of a specified type. More...
 
static EType GetType (const TNcbiSys_stat &st)
 Get a type of a directory entry by status information. More...
 
static void SetDefaultModeGlobal (EType entry_type, TMode user_mode, TMode group_mode=fDefault, TMode other_mode=fDefault, TSpecialModeBits special=0)
 Set default permission modes globally for all CDirEntry objects. More...
 
static mode_t MakeModeT (TMode user_mode, TMode group_mode, TMode other_mode, TSpecialModeBits special)
 Construct mode_t value from permission modes. More...
 
static void ModeFromModeT (mode_t mode, TMode *user_mode, TMode *group_mode=0, TMode *other_mode=0, TSpecialModeBits *special=0)
 Convert mode_t to permission mode(s). More...
 
static string ModeToString (TMode user_mode, TMode group_mode, TMode other_mode, TSpecialModeBits special, EModeStringFormat format=eModeFormat_Default)
 Convert permission modes to string representation using one of predefined formats. More...
 
static bool StringToMode (const CTempString &mode, TMode *user_mode, TMode *group_mode=0, TMode *other_mode=0, TSpecialModeBits *special=0)
 Convert string (in one of predefined formats, detects automatically) to permission mode(s). More...
 
static void GetUmask (TMode *user_mode, TMode *group_mode=0, TMode *other_mode=0, TSpecialModeBits *special=0)
 Get file/directory mode creation mask. More...
 
static void SetUmask (TMode user_mode, TMode group_mode=fDefault, TMode other_mode=fDefault, TSpecialModeBits special=0)
 Set file/directory mode creation mask. More...
 
static string GetTmpName (ETmpFileCreationMode mode=eTmpFileGetName)
 Get temporary file name. More...
 
static string GetTmpNameEx (const string &dir=kEmptyStr, const string &prefix=kEmptyStr, ETmpFileCreationMode mode=eTmpFileGetName)
 Get temporary file name. More...
 
static fstream * CreateTmpFile (const string &filename=kEmptyStr, ETextBinary text_binary=eBinary, EAllowRead allow_read=eAllowRead)
 Create temporary file and return pointer to corresponding stream. More...
 
static fstream * CreateTmpFileEx (const string &dir=".", const string &prefix=kEmptyStr, ETextBinary text_binary=eBinary, EAllowRead allow_read=eAllowRead)
 Create temporary file and return pointer to corresponding stream. More...
 
- Protected Member Functions inherited from CDirEntry
void GetDefaultMode (TMode *user_mode, TMode *group_mode, TMode *other_mode, TSpecialModeBits *special) const
 Get the default mode. More...
 
mode_t GetDefaultModeT (void) const
 
- Static Protected Member Functions inherited from CDirEntry
static void GetDefaultModeGlobal (EType entry_type, TMode *user_mode, TMode *group_mode, TMode *other_mode, TSpecialModeBits *special)
 Get the default global mode. More...
 

Detailed Description

CFile –.

Define class to work with regular files. NOTE: it don't work with any special or block devices like /dev/null

Models a file in a file system. Basic functionality is derived from CDirEntry and extended for files.

Definition at line 1604 of file ncbifile.hpp.


The documentation for this class was generated from the following files:
Modified on Fri Sep 20 14:57:44 2024 by modify_doxy.py rev. 669887