zz::fs::FileEditor Class Reference

The FileEditor class to modify file This class is derived from UnCopyable, so no copy operation. Move operation is allowed by std::move();. More...

#include <zupply.hpp>

Inheritance diagram for zz::fs::FileEditor:
zz::UnCopyable

Public Member Functions

 FileEditor (std::string filename, bool truncateOrNot=false, int retryTimes=consts::kDefaultFileOpenRetryTimes, int retryInterval=consts::kDefaultFileOpenRetryInterval)
 FileEditor constructor. More...
 
FileEditoroperator= (FileEditor &&)=delete
 
template<typename T >
FileEditoroperator<< (T what)
 Overload << operator just like a stream.
 
std::string filename () const
 Return filename. More...
 
bool open (std::string filename, bool truncateOrNot=false, int retryTimes=consts::kDefaultFileOpenRetryTimes, int retryInterval=consts::kDefaultFileOpenRetryInterval)
 Open file. More...
 
bool open (const char *filename, bool truncateOrNot=false, int retryTimes=consts::kDefaultFileOpenRetryTimes, int retryInterval=consts::kDefaultFileOpenRetryInterval)
 Open file. More...
 
bool open (bool truncateOrNot=false)
 Open file. More...
 
bool reopen (bool truncateOrNot=true)
 Reopen current file. More...
 
void close ()
 Close current file.
 
bool is_valid () const
 Check whether current file handler is set. More...
 
bool is_open () const
 Check if file is opened. More...
 
void flush ()
 Flush file stream.
 

Detailed Description

The FileEditor class to modify file This class is derived from UnCopyable, so no copy operation. Move operation is allowed by std::move();.

Constructor & Destructor Documentation

zz::fs::FileEditor::FileEditor ( std::string  filename,
bool  truncateOrNot = false,
int  retryTimes = consts::kDefaultFileOpenRetryTimes,
int  retryInterval = consts::kDefaultFileOpenRetryInterval 
)

FileEditor constructor.

Parameters
filename
truncateOrNotWhether open in truncate mode or not
retryTimesRetry open file if not success
retryIntervalRetry interval in ms

Member Function Documentation

std::string zz::fs::FileEditor::filename ( ) const
inline

Return filename.

Returns
Filename of this object
bool zz::fs::FileEditor::is_open ( ) const
inline

Check if file is opened.

Returns
True if opened
bool zz::fs::FileEditor::is_valid ( ) const
inline

Check whether current file handler is set.

Returns
True if valid file
bool zz::fs::FileEditor::open ( std::string  filename,
bool  truncateOrNot = false,
int  retryTimes = consts::kDefaultFileOpenRetryTimes,
int  retryInterval = consts::kDefaultFileOpenRetryInterval 
)

Open file.

Parameters
filename
truncateOrNotWhether open in truncate mode or not
retryTimesRetry open file if not success
retryIntervalRetry interval in ms
Returns
True if success
bool zz::fs::FileEditor::open ( const char *  filename,
bool  truncateOrNot = false,
int  retryTimes = consts::kDefaultFileOpenRetryTimes,
int  retryInterval = consts::kDefaultFileOpenRetryInterval 
)

Open file.

Parameters
filename
truncateOrNotWhether open in truncate mode or not
retryTimesRetry open file if not success
retryIntervalRetry interval in ms
Returns
True if success
bool zz::fs::FileEditor::open ( bool  truncateOrNot = false)

Open file.

Parameters
truncateOrNotWhether open in truncate mode or not
Returns
True if success
bool zz::fs::FileEditor::reopen ( bool  truncateOrNot = true)

Reopen current file.

Parameters
truncateOrNot
Returns
True if success

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