LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
smartversionfile.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_SMARTVERSIONFILE_H
21 #define LIBREPCB_SMARTVERSIONFILE_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "smartfile.h"
27 #include "versionfile.h"
28 
29 #include <QtCore>
30 
31 /*******************************************************************************
32  * Namespace / Forward Declarations
33  ******************************************************************************/
34 namespace librepcb {
35 
36 /*******************************************************************************
37  * Class SmartVersionFile
38  ******************************************************************************/
39 
48 class SmartVersionFile final : public SmartFile {
49  Q_DECLARE_TR_FUNCTIONS(SmartVersionFile)
50 
51 public:
52  // Constructors / Destructor
53  SmartVersionFile() = delete;
54  SmartVersionFile(const SmartVersionFile& other) = delete;
55 
68  SmartVersionFile(const FilePath& filepath, bool restore, bool readOnly);
69 
73  ~SmartVersionFile() noexcept;
74 
75  // Getters
76 
82  const Version& getVersion() const noexcept {
83  return mVersionFile.getVersion();
84  }
85 
86  // Setters
87 
95  void setVersion(const Version& version) noexcept {
96  mVersionFile.setVersion(version);
97  }
98 
99  // General Methods
100 
109  void save(bool toOriginal);
110 
111  // Operator Overloadings
112  SmartVersionFile& operator=(const SmartVersionFile& rhs) = delete;
113 
114  // Static Methods
115 
129  static SmartVersionFile* create(const FilePath& filepath,
130  const Version& version);
131 
132 protected:
141  SmartVersionFile(const FilePath& filepath, const Version& newVersion);
142 
143  static VersionFile readVersionFromFile(const FilePath& filepath);
144 
145 private: // Data
147 };
148 
149 /*******************************************************************************
150  * End of File
151  ******************************************************************************/
152 
153 } // namespace librepcb
154 
155 #endif // LIBREPCB_SMARTVERSIONFILE_H
The Version class represents a version number in the format "1.42.7".
Definition: version.h:60
void setVersion(const Version &version) noexcept
Set the version of the file.
Definition: smartversionfile.h:95
const Version & getVersion() const noexcept
Get the content of the file.
Definition: smartversionfile.h:82
void save(bool toOriginal)
Write all changes to the file system.
Definition: smartversionfile.cpp:57
Class for reading and writing version files from/to QByteArray.
Definition: versionfile.h:47
The SmartVersionFile class.
Definition: smartversionfile.h:48
~SmartVersionFile() noexcept
The destructor.
Definition: smartversionfile.cpp:50
VersionFile mVersionFile
Definition: smartversionfile.h:146
static VersionFile readVersionFromFile(const FilePath &filepath)
Definition: smartversionfile.cpp:72
The abstract SmartFile class represents a file and provides some useful methods to work with that fil...
Definition: smartfile.h:59
const Version & getVersion() const noexcept
Get the content of the file.
Definition: versionfile.h:74
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:130
static SmartVersionFile * create(const FilePath &filepath, const Version &version)
Create a new version file.
Definition: smartversionfile.cpp:67
SmartVersionFile & operator=(const SmartVersionFile &rhs)=delete
void setVersion(const Version &version) noexcept
Set the version of the file.
Definition: versionfile.h:83