LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SmartTextFile Class Referencefinal

The SmartTextFile class represents a text file and provides access to its content. More...

#include <smarttextfile.h>

+ Inheritance diagram for SmartTextFile:
+ Collaboration diagram for SmartTextFile:

Public Member Functions

 SmartTextFile ()=delete
 
 SmartTextFile (const SmartTextFile &other)=delete
 
 SmartTextFile (const FilePath &filepath, bool restore, bool readOnly)
 The constructor to open an existing text file. More...
 
 ~SmartTextFile () noexcept
 The destructor. More...
 
const QByteArray & getContent () const noexcept
 Get the content of the file. More...
 
void setContent (const QByteArray &content) noexcept
 Set the content of the file. More...
 
void save (bool toOriginal)
 Write all changes to the file system. More...
 
SmartTextFileoperator= (const SmartTextFile &rhs)=delete
 
- Public Member Functions inherited from SmartFile
 SmartFile ()=delete
 
 SmartFile (const SmartFile &other)=delete
 
 SmartFile (const FilePath &filepath, bool restore, bool readOnly, bool create)
 The constructor. More...
 
virtual ~SmartFile () noexcept
 The destructor. More...
 
const FilePathgetFilepath () const noexcept
 Get the filepath to the file which was passed to the constructor. More...
 
bool isRestored () const noexcept
 Check if this file was restored from a backup. More...
 
bool isReadOnly () const noexcept
 Check if this file was opened in read-only mode. More...
 
bool isCreated () const noexcept
 Check if this file is created and not yet saved to the harddisc. More...
 
void removeFile (bool original)
 Remove the file from the file system. More...
 
SmartFileoperator= (const SmartFile &rhs)=delete
 

Static Public Member Functions

static SmartTextFilecreate (const FilePath &filepath)
 Create a new text file. More...
 

Protected Member Functions

 SmartTextFile (const FilePath &filepath, bool restore, bool readOnly, bool create)
 Constructor to create or open a text file. More...
 
- Protected Member Functions inherited from SmartFile
const FilePathprepareSaveAndReturnFilePath (bool toOriginal)
 Prepare to save the file and return the filepath to the file. More...
 
void updateMembersAfterSaving (bool toOriginal) noexcept
 Update the member variables mIsRestored and mIsCreated after saving. More...
 

Protected Attributes

QByteArray mContent
 The content of the text file. More...
 
- Protected Attributes inherited from SmartFile
FilePath mFilePath
 The filepath which was passed to the constructor. More...
 
FilePath mTmpFilePath
 The filepath to the temporary file (mFilePath + '~') More...
 
FilePath mOpenedFilePath
 The filepath from where the content was loaded. More...
 
bool mIsRestored
 This variable determines whether the file was restored or not. More...
 
bool mIsReadOnly
 If true, the file is opened as read-only. More...
 
bool mIsCreated
 If true, the file was created and not yet written to the filesystem (so the file mFilePath does not yet exist!) More...
 

Detailed Description

The SmartTextFile class represents a text file and provides access to its content.

Note
See class SmartFile for more information.
Author
ubruhin
Date
2015-01-19

Constructor & Destructor Documentation

SmartTextFile ( )
delete

+ Here is the caller graph for this function:

SmartTextFile ( const SmartTextFile other)
delete
SmartTextFile ( const FilePath filepath,
bool  restore,
bool  readOnly 
)
inline

The constructor to open an existing text file.

This constructor tries to open an existing file and throws an exception if an error occurs.

Parameters
filepathSee SmartFile::SmartFile()
restoreSee SmartFile::SmartFile()
readOnlySee SmartFile::SmartFile()
Exceptions
ExceptionSee SmartFile::SmartFile()
~SmartTextFile ( )
noexcept

The destructor.

Removes the temporary file (if existing)

SmartTextFile ( const FilePath filepath,
bool  restore,
bool  readOnly,
bool  create 
)
protected

Constructor to create or open a text file.

Parameters
filepathSee SmartFile::SmartFile()
restoreSee SmartFile::SmartFile()
readOnlySee SmartFile::SmartFile()
createSee SmartFile::SmartFile()
Exceptions
ExceptionSee SmartFile::SmartFile()

+ Here is the call graph for this function:

Member Function Documentation

const QByteArray& getContent ( ) const
inlinenoexcept

Get the content of the file.

Returns
The content of the file
void setContent ( const QByteArray &  content)
inlinenoexcept

Set the content of the file.

Note
The content won't be written to the file until save() is called.
Parameters
contentThe new content of the file
void save ( bool  toOriginal)

Write all changes to the file system.

Parameters
toOriginalSpecifies whether the original or the backup file should be overwritten/created.
Exceptions
ExceptionIf an error occurs

+ Here is the call graph for this function:

SmartTextFile& operator= ( const SmartTextFile rhs)
delete
SmartTextFile * create ( const FilePath filepath)
static

Create a new text file.

Note
This method will NOT immediately create the file! The file will be created after calling save().
Parameters
filepathThe filepath to the file to create (always to the original file, not to the backup file with "~" at the end of the filename!)
Returns
The SmartTextFile object of the created file
Exceptions
ExceptionIf an error occurs

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

QByteArray mContent
protected

The content of the text file.


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