STAR++ v0.2.2
C++ implementation of STAR voting
Loading...
Searching...
No Matches
calculatoroptions_p.h
1#ifndef CALCULATOROPTIONS_P_H
2#define CALCULATOROPTIONS_P_H
3
4// Qt Includes
5#include <QString>
6#include <QList>
7
8// Qx Includes
9#include <qx/io/qx-textstreamreader.h>
10
11// Project Includes
12#include "star/calculator.h"
13
14namespace Star
15{
18class QX_ERROR_TYPE(CalcOptionsError, "Star::CalcOptionsError", 1151)
19{
20 friend class CalcOptionsReader;
21//-Class Enums-------------------------------------------------------------
22public:
23 enum Type
24 {
25 NoError,
26 DoesNotExist,
27 IoError,
28 InvalidOption
29 };
30
31//-Class Variables-------------------------------------------------------------
32private:
33 static inline const QString MAIN_ERR_MSG = u"Error reading the options list."_s;
34 static inline const QHash<Type, QString> ERR_STRINGS{
35 {NoError, u""_s},
36 {NoError, u"IO Error: %1"_s},
37 {DoesNotExist, u"The specified file does not exist."_s},
38 {InvalidOption, u"The file contains an invalid option (Line: %1)."_s}
39 };
40
41//-Instance Variables-------------------------------------------------------------
42private:
43 Type mType;
44 QString mString;
45
46//-Constructor-------------------------------------------------------------
47private:
48 CalcOptionsError(Type t = NoError);
49
50 template<typename... Strings>
51 requires (std::same_as<Strings, QString> && ...)
52 CalcOptionsError(Type t, Strings... args) :
53 CalcOptionsError(t)
54 {
55 mString = mString.arg(args...);
56 }
57
58 template<typename... Ints>
59 requires (std::integral<Ints> && ...)
60 CalcOptionsError(Type t, Ints... args) :
61 CalcOptionsError(t)
62 {
63 auto sub = [this](auto integer) { mString = mString.arg(integer); };
64 (sub(args), ...);
65 }
66
67//-Instance Functions-------------------------------------------------------------
68public:
69 bool isValid() const;
70 Type type() const;
71 QString string() const;
72
73private:
74 Qx::Severity deriveSeverity() const override;
75 quint32 deriveValue() const override;
76 QString derivePrimary() const override;
77 QString deriveSecondary() const override;
78};
79
80class CalcOptionsReader
81{
82//-Instance Variables--------------------------------------------------------------------------------------------------
83private:
84 Star::Calculator::Options* mTargetOptions;
85 Qx::TextStreamReader mOptionsReader;
86
87//-Constructor--------------------------------------------------------------------------------------------------------
88public:
89 CalcOptionsReader(Star::Calculator::Options* targetOptions, const QString& filePath);
90
91//-Instance Functions-------------------------------------------------------------------------------------------------
92public:
93 CalcOptionsError readInto();
94};
96}
97#endif // CALCULATOROPTIONS_P_H
QFlags< Option > Options
Definition calculator.h:34
The Star namespace is the main namespace through which all functionality of the STAR++ library is acc...
Definition calculator.cpp:21