LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
smarttextfile.h
Go to the documentation of this file.
1 /*
2  * LibrePCB - Professional EDA for everyone!
3  * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4  * https://librepcb.org/
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef LIBREPCB_SMARTTEXTFILE_H
21 #define LIBREPCB_SMARTTEXTFILE_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "smartfile.h"
27 
28 #include <QtCore>
29 
30 /*******************************************************************************
31  * Namespace / Forward Declarations
32  ******************************************************************************/
33 namespace librepcb {
34 
35 /*******************************************************************************
36  * Class SmartTextFile
37  ******************************************************************************/
38 
48 class SmartTextFile final : public SmartFile {
49  Q_DECLARE_TR_FUNCTIONS(SmartTextFile)
50 
51 public:
52  // Constructors / Destructor
53  SmartTextFile() = delete;
54  SmartTextFile(const SmartTextFile& other) = delete;
55 
68  SmartTextFile(const FilePath& filepath, bool restore, bool readOnly)
69  : SmartTextFile(filepath, restore, readOnly, false) {}
70 
74  ~SmartTextFile() noexcept;
75 
76  // Getters
77 
83  const QByteArray& getContent() const noexcept { return mContent; }
84 
85  // Setters
86 
94  void setContent(const QByteArray& content) noexcept { mContent = content; }
95 
96  // General Methods
97 
106  void save(bool toOriginal);
107 
108  // Operator Overloadings
109  SmartTextFile& operator=(const SmartTextFile& rhs) = delete;
110 
111  // Static Methods
112 
126  static SmartTextFile* create(const FilePath& filepath);
127 
128 protected:
129  // Protected Methods
130 
141  SmartTextFile(const FilePath& filepath, bool restore, bool readOnly,
142  bool create);
143 
144  // General Attributes
145 
149  QByteArray mContent;
150 };
151 
152 /*******************************************************************************
153  * End of File
154  ******************************************************************************/
155 
156 } // namespace librepcb
157 
158 #endif // LIBREPCB_SMARTTEXTFILE_H
SmartTextFile(const FilePath &filepath, bool restore, bool readOnly)
The constructor to open an existing text file.
Definition: smarttextfile.h:68
static SmartTextFile * create(const FilePath &filepath)
Create a new text file.
Definition: smarttextfile.cpp:66
void save(bool toOriginal)
Write all changes to the file system.
Definition: smarttextfile.cpp:56
The abstract SmartFile class represents a file and provides some useful methods to work with that fil...
Definition: smartfile.h:59
QByteArray mContent
The content of the text file.
Definition: smarttextfile.h:149
void setContent(const QByteArray &content) noexcept
Set the content of the file.
Definition: smarttextfile.h:94
~SmartTextFile() noexcept
The destructor.
Definition: smarttextfile.cpp:49
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:130
The SmartTextFile class represents a text file and provides access to its content.
Definition: smarttextfile.h:48
SmartTextFile & operator=(const SmartTextFile &rhs)=delete
const QByteArray & getContent() const noexcept
Get the content of the file.
Definition: smarttextfile.h:83