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

The SmartSExprFile class represents an S-Expressions file and provides methods to load/save DOM trees (#DomDocument) More...

#include <smartsexprfile.h>

+ Inheritance diagram for SmartSExprFile:
+ Collaboration diagram for SmartSExprFile:

Public Member Functions

 SmartSExprFile ()=delete
 
 SmartSExprFile (const SmartSExprFile &other)=delete
 
 SmartSExprFile (const FilePath &filepath, bool restore, bool readOnly)
 The constructor to open an existing S-Expressions file. More...
 
 ~SmartSExprFile () noexcept
 The destructor. More...
 
SExpression parseFileAndBuildDomTree () const
 Open and parse the S-Expressions file and build the whole DOM tree. More...
 
void save (const SExpression &domDocument, bool toOriginal)
 Write the S-Expressions DOM tree to the file system. More...
 
SmartSExprFileoperator= (const SmartSExprFile &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 SmartSExprFilecreate (const FilePath &filepath)
 Create a new S-Expressions file. More...
 

Private Member Functions

 SmartSExprFile (const FilePath &filepath, bool restore, bool readOnly, bool create)
 Constructor to create or open a S-Expressions file. More...
 

Additional Inherited Members

- 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 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 SmartSExprFile class represents an S-Expressions file and provides methods to load/save DOM trees (#DomDocument)

With parseFileAndBuildDomTree() the file can be parsed and a DOM tree is created. With save() the DOM tree can be saved back to the S-Expressions file.

Note
See class SmartFile for more information.
Author
ubruhin
Date
2014-08-13

Constructor & Destructor Documentation

SmartSExprFile ( )
delete

+ Here is the caller graph for this function:

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

The constructor to open an existing S-Expressions 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
ExceptionIf the specified text file could not be opened successful, an exception will be thrown.
~SmartSExprFile ( )
noexcept

The destructor.

Removes the temporary file (if existing)

SmartSExprFile ( const FilePath filepath,
bool  restore,
bool  readOnly,
bool  create 
)
private

Constructor to create or open a S-Expressions file.

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

Member Function Documentation

SExpression parseFileAndBuildDomTree ( ) const

Open and parse the S-Expressions file and build the whole DOM tree.

Returns
A pointer to the created DOM tree. The caller takes the ownership of the DOM document.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void save ( const SExpression domDocument,
bool  toOriginal 
)

Write the S-Expressions DOM tree to the file system.

Parameters
domDocumentThe DOM document to save
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:

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

Create a new S-Expressions 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 SmartSExprFile 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:


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