Seamly2D
Code documentation
vabstractconverter.h
Go to the documentation of this file.
1 /***************************************************************************
2  ** @file vabstractconverter.h
3  ** @author Douglas S Caskey
4  ** @date Dec 27, 2022
5  **
6  ** @copyright
7  ** Copyright (C) 2017 - 2022 Seamly, LLC
8  ** https://github.com/fashionfreedom/seamly2d
9  **
10  ** @brief
11  ** Seamly2D is free software: you can redistribute it and/or modify
12  ** it under the terms of the GNU General Public License as published by
13  ** the Free Software Foundation, either version 3 of the License, or
14  ** (at your option) any later version.
15  **
16  ** Seamly2D is distributed in the hope that it will be useful,
17  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  ** GNU General Public License for more details.
20  **
21  ** You should have received a copy of the GNU General Public License
22  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
23  **************************************************************************/
24 
25 /************************************************************************
26  **
27  ** @file vabstractconverter.h
28  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
29  ** @date 10 12, 2014
30  **
31  ** @brief
32  ** @copyright
33  ** This source code is part of the Valentina project, a pattern making
34  ** program, whose allow create and modeling patterns of clothing.
35  ** Copyright (C) 2014 Valentina project
36  ** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
37  **
38  ** Valentina is free software: you can redistribute it and/or modify
39  ** it under the terms of the GNU General Public License as published by
40  ** the Free Software Foundation, either version 3 of the License, or
41  ** (at your option) any later version.
42  **
43  ** Valentina is distributed in the hope that it will be useful,
44  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
45  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46  ** GNU General Public License for more details.
47  **
48  ** You should have received a copy of the GNU General Public License
49  ** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
50  **
51  *************************************************************************/
52 
53 #ifndef VABSTRACTCONVERTER_H
54 #define VABSTRACTCONVERTER_H
55 
56 #include <qcompilerdetection.h>
57 
58 #if !defined(Q_OS_OSX) && !defined(Q_OS_WIN) && defined(Q_CC_GNU)
59 #include <sys/sysmacros.h>
60 #endif
61 
62 #include <QCoreApplication>
63 #include <QString>
64 #include <QTemporaryFile>
65 #include <QtGlobal>
66 
67 #include "vdomdocument.h"
68 
69 template <class Key, class T> class QMap;
70 
71 #define CONVERTER_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch))
72 
74 {
75  Q_DECLARE_TR_FUNCTIONS(VAbstractConverter)
76 public:
77  explicit VAbstractConverter(const QString &fileName);
78  virtual ~VAbstractConverter() Q_DECL_EQ_DEFAULT;
79 
80  QString Convert();
81 
82  int GetCurrentFormatVarsion() const;
83  QString GetVersionStr() const;
84 
85  static int GetVersion(const QString &version);
86 
87 protected:
88  int m_ver;
90 
91  void ValidateInputFile(const QString &currentSchema) const;
92  Q_NORETURN void InvalidVersion(int ver) const;
93  void Save();
94  void SetVersion(const QString &version);
95 
96  virtual int MinVer() const =0;
97  virtual int MaxVer() const =0;
98 
99  virtual QString MinVerStr() const =0;
100  virtual QString MaxVerStr() const =0;
101 
102  virtual QString XSDSchema(int ver) const =0;
103  virtual void ApplyPatches() =0;
104  virtual void DowngradeToCurrentMaxVersion() =0;
105 
106  virtual bool IsReadOnly() const =0;
107 
108  void Replace(QString &formula, const QString &newName, int position,
109  const QString &token, int &bias) const;
110  void CorrectionsPositions(int position, int bias, QMap<int, QString> &tokens) const;
111  static void BiasTokens(int position, int bias, QMap<int, QString> &tokens);
112 
113 private:
114  Q_DISABLE_COPY(VAbstractConverter)
115 
116  QTemporaryFile m_tmpFile;
117 
118  static void ValidateVersion(const QString &version);
119 
120  void ReserveFile() const;
121 
122  /**
123  * \brief Removes version number from \arg fileName
124  *
125  * It removes both, "old style" ie. "(v0.6.0)" and new style "v060" patterns.
126  */
127  static QString removeVersionNumber(const QString& fileName);
128 
129  /** \brief Removes single or repeated '.bak' extension (as long as it is at the end of \arg fileName) */
130  static QString removeBakExtension(const QString& fileName);
131 };
132 
133 #endif // VABSTRACTCONVERTER_H
virtual ~VAbstractConverter() Q_DECL_EQ_DEFAULT
static int GetVersion(const QString &version)
static QString removeVersionNumber(const QString &fileName)
Removes version number from.
virtual void DowngradeToCurrentMaxVersion()=0
virtual bool IsReadOnly() const =0
void SetVersion(const QString &version)
void Replace(QString &formula, const QString &newName, int position, const QString &token, int &bias) const
virtual QString MaxVerStr() const =0
int GetCurrentFormatVarsion() const
static void BiasTokens(int position, int bias, QMap< int, QString > &tokens)
static void ValidateVersion(const QString &version)
Q_NORETURN void InvalidVersion(int ver) const
virtual QString XSDSchema(int ver) const =0
virtual int MaxVer() const =0
static QString removeBakExtension(const QString &fileName)
Removes single or repeated '.bak' extension (as long as it is at the end of.
void CorrectionsPositions(int position, int bias, QMap< int, QString > &tokens) const
virtual int MinVer() const =0
void ValidateInputFile(const QString &currentSchema) const
QString GetVersionStr() const
VAbstractConverter(const QString &fileName)
virtual QString MinVerStr() const =0
virtual void ApplyPatches()=0
QTemporaryFile m_tmpFile
The VDomDocument class represents a Seamly2D document (.val file).
Definition: vdomdocument.h:105