Turn Converter::Direction into a QFlags enum
This lets us testFlag() instead of using raw bit-field operations. Task-number: QTBUG-111228 Change-Id: I2c26e9a24728e81baa42cf14c75271a015460913 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> (cherry picked from commit ad63118071e3068ef3f45e75fad82a04952ba0fb)
This commit is contained in:
parent
50b51d2b50
commit
9fcee2287a
@ -125,7 +125,7 @@ QString CborDiagnosticDumper::name() const
|
||||
return "cbor-dump"_L1;
|
||||
}
|
||||
|
||||
Converter::Direction CborDiagnosticDumper::directions() const
|
||||
Converter::Directions CborDiagnosticDumper::directions() const
|
||||
{
|
||||
return Out;
|
||||
}
|
||||
@ -197,7 +197,7 @@ QString CborConverter::name() const
|
||||
return "cbor";
|
||||
}
|
||||
|
||||
Converter::Direction CborConverter::directions() const
|
||||
Converter::Directions CborConverter::directions() const
|
||||
{
|
||||
return InOut;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ class CborDiagnosticDumper : public Converter
|
||||
// Converter interface
|
||||
public:
|
||||
QString name() const override;
|
||||
Direction directions() const override;
|
||||
Directions directions() const override;
|
||||
Options outputOptions() const override;
|
||||
const char *optionsHelp() const override;
|
||||
bool probeFile(QIODevice *f) const override;
|
||||
@ -28,7 +28,7 @@ public:
|
||||
// Converter interface
|
||||
public:
|
||||
QString name() const override;
|
||||
Direction directions() const override;
|
||||
Directions directions() const override;
|
||||
Options outputOptions() const override;
|
||||
const char *optionsHelp() const override;
|
||||
bool probeFile(QIODevice *f) const override;
|
||||
|
@ -32,7 +32,8 @@ protected:
|
||||
public:
|
||||
static Converter *null;
|
||||
|
||||
enum Direction { In = 1, Out = 2, InOut = 3 };
|
||||
enum Direction { In = 1, Out = 2, InOut = In | Out };
|
||||
Q_DECLARE_FLAGS(Directions, Direction)
|
||||
|
||||
enum Option { SupportsArbitraryMapKeys = 0x01 };
|
||||
Q_DECLARE_FLAGS(Options, Option)
|
||||
@ -40,7 +41,7 @@ public:
|
||||
virtual ~Converter() = 0;
|
||||
|
||||
virtual QString name() const = 0;
|
||||
virtual Direction directions() const = 0;
|
||||
virtual Directions directions() const = 0;
|
||||
virtual Options outputOptions() const = 0;
|
||||
virtual const char *optionsHelp() const = 0;
|
||||
virtual bool probeFile(QIODevice *f) const = 0;
|
||||
@ -49,6 +50,7 @@ public:
|
||||
const QStringList &options) const = 0;
|
||||
};
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(Converter::Directions)
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(Converter::Options)
|
||||
|
||||
#endif // CONVERTER_H
|
||||
|
@ -53,7 +53,7 @@ QString DataStreamConverter::name() const
|
||||
return "datastream"_L1;
|
||||
}
|
||||
|
||||
Converter::Direction DataStreamConverter::directions() const
|
||||
Converter::Directions DataStreamConverter::directions() const
|
||||
{
|
||||
return InOut;
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ public:
|
||||
// Converter interface
|
||||
public:
|
||||
QString name() const override;
|
||||
Direction directions() const override;
|
||||
Directions directions() const override;
|
||||
Options outputOptions() const override;
|
||||
const char *optionsHelp() const override;
|
||||
bool probeFile(QIODevice *f) const override;
|
||||
|
@ -48,7 +48,7 @@ QString DebugTextDumper::name() const
|
||||
return "debugtext-dump"_L1;
|
||||
}
|
||||
|
||||
Converter::Direction DebugTextDumper::directions() const
|
||||
Converter::Directions DebugTextDumper::directions() const
|
||||
{
|
||||
return Out;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ class DebugTextDumper : public Converter
|
||||
// Converter interface
|
||||
public:
|
||||
QString name() const override;
|
||||
Direction directions() const override;
|
||||
Directions directions() const override;
|
||||
Options outputOptions() const override;
|
||||
const char *optionsHelp() const override;
|
||||
bool probeFile(QIODevice *f) const override;
|
||||
|
@ -30,7 +30,7 @@ QString JsonConverter::name() const
|
||||
return "json"_L1;
|
||||
}
|
||||
|
||||
Converter::Direction JsonConverter::directions() const
|
||||
Converter::Directions JsonConverter::directions() const
|
||||
{
|
||||
return InOut;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ class JsonConverter : public Converter
|
||||
// Converter interface
|
||||
public:
|
||||
QString name() const override;
|
||||
Direction directions() const override;
|
||||
Directions directions() const override;
|
||||
Options outputOptions() const override;
|
||||
const char *optionsHelp() const override;
|
||||
bool probeFile(QIODevice *f) const override;
|
||||
|
@ -36,9 +36,9 @@ int main(int argc, char *argv[])
|
||||
for (const Converter *conv : std::as_const(*availableConverters)) {
|
||||
auto direction = conv->directions();
|
||||
QString name = conv->name();
|
||||
if (direction & Converter::In)
|
||||
if (direction.testFlag(Converter::In))
|
||||
inputFormats << name;
|
||||
if (direction & Converter::Out)
|
||||
if (direction.testFlag(Converter::Out))
|
||||
outputFormats << name;
|
||||
}
|
||||
inputFormats.sort();
|
||||
@ -162,7 +162,7 @@ int main(int argc, char *argv[])
|
||||
if (!inconv) {
|
||||
// probe the input to find a file format
|
||||
for (const Converter *conv : std::as_const(*availableConverters)) {
|
||||
if (conv->directions() & Converter::In && conv->probeFile(&input)) {
|
||||
if (conv->directions().testFlag(Converter::In) && conv->probeFile(&input)) {
|
||||
inconv = conv;
|
||||
break;
|
||||
}
|
||||
@ -177,7 +177,7 @@ int main(int argc, char *argv[])
|
||||
if (!outconv) {
|
||||
// probe the output to find a file format
|
||||
for (const Converter *conv : std::as_const(*availableConverters)) {
|
||||
if (conv->directions() & Converter::Out && conv->probeFile(&output)) {
|
||||
if (conv->directions().testFlag(Converter::Out) && conv->probeFile(&output)) {
|
||||
outconv = conv;
|
||||
break;
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ QString NullConverter::name() const
|
||||
return "null"_L1;
|
||||
}
|
||||
|
||||
Converter::Direction NullConverter::directions() const
|
||||
Converter::Directions NullConverter::directions() const
|
||||
{
|
||||
return Out;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ class NullConverter : public Converter
|
||||
// Converter interface
|
||||
public:
|
||||
QString name() const override;
|
||||
Direction directions() const override;
|
||||
Directions directions() const override;
|
||||
Options outputOptions() const override;
|
||||
const char *optionsHelp() const override;
|
||||
bool probeFile(QIODevice *f) const override;
|
||||
|
@ -49,7 +49,7 @@ QString TextConverter::name() const
|
||||
return "text"_L1;
|
||||
}
|
||||
|
||||
Converter::Direction TextConverter::directions() const
|
||||
Converter::Directions TextConverter::directions() const
|
||||
{
|
||||
return InOut;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ class TextConverter : public Converter
|
||||
// Converter interface
|
||||
public:
|
||||
QString name() const override;
|
||||
Direction directions() const override;
|
||||
Directions directions() const override;
|
||||
Options outputOptions() const override;
|
||||
const char *optionsHelp() const override;
|
||||
bool probeFile(QIODevice *f) const override;
|
||||
|
@ -401,7 +401,7 @@ QString XmlConverter::name() const
|
||||
return "xml"_L1;
|
||||
}
|
||||
|
||||
Converter::Direction XmlConverter::directions() const
|
||||
Converter::Directions XmlConverter::directions() const
|
||||
{
|
||||
return InOut;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ class XmlConverter : public Converter
|
||||
// Converter interface
|
||||
public:
|
||||
QString name() const override;
|
||||
Direction directions() const override;
|
||||
Directions directions() const override;
|
||||
Options outputOptions() const override;
|
||||
const char *optionsHelp() const override;
|
||||
bool probeFile(QIODevice *f) const override;
|
||||
|
Loading…
x
Reference in New Issue
Block a user