123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- #ifndef __TASK_HPP__
- #define __TASK_HPP__
- #include <QQueue>
- #include <QString>
- #include <QVector>
- #include <memory>
- #include <variant>
- #include <vector>
- namespace Scheduler {
- enum TaskType { INSTAGRAM = 1, OTHER = 2 };
- enum FileType { VIDEO = 1, IMAGE = 2 };
- struct KFileData {
- QString name;
- FileType type;
- QString path;
- QByteArray bytes;
- };
- namespace Type {
- static constexpr const char* TEXT = "Text";
- static constexpr const char* FILE = "File";
- static constexpr const char* STRINGVECTOR = "StringVector";
- static constexpr const char* FILEVECTOR = "FileVector";
- static constexpr const char* DATETIME = "DateTime";
- static constexpr const char* BOOLEAN = "Boolean";
- }
- namespace VariantIndex {
- static const uint8_t BOOLEAN = 0;
- static const uint8_t INTEGER = 1;
- static const uint8_t QSTRING = 2;
- static const uint8_t STRVEC = 3;
- static const uint8_t FILEVEC = 4;
- }
- inline bool isIndex(uint8_t v, uint8_t i) { return v == i; }
- class TaskArgumentBase;
- class Task;
- using TaskQueue = QQueue<Task*>;
- using ArgumentType = const char*;
- using ArgumentValues = QVector<const QString>;
- using TypeVariant = std::variant<bool, int, QString, QVector<QString>, std::vector<KFileData>>;
- using TaskIterator = std::vector<std::unique_ptr<TaskArgumentBase>>::iterator;
- using TaskArguments = std::vector<std::unique_ptr<TaskArgumentBase>>;
- class TaskArgumentBase {
- public:
- virtual const QString text() = 0;
- virtual const QString getStringValue() = 0;
- virtual TypeVariant getValue() = 0;
- virtual void setValue(TypeVariant v) = 0;
- virtual bool isContainer() = 0;
- virtual void clear() = 0;
- };
- template <typename T = TypeVariant>
- class TaskArgument : TaskArgumentBase {
- public:
- TaskArgument(QString n, ArgumentType t, T _value) {
- name = n;
- type = t;
- value = _value;
- }
-
- TaskArgument(TaskArgument&& a) :
- name(std::move(a.name)), type(std::move(a.type)), value(std::move(a.value)) {}
-
- virtual const QString text() { return name; }
-
- virtual void setValue(TypeVariant new_value) override { value = new_value; }
-
- virtual const QString getStringValue() override {
- if (isIndex(value.index(), VariantIndex::QSTRING)) {
- return std::get<VariantIndex::QSTRING>(value);
- } else if (isIndex(value.index(), VariantIndex::BOOLEAN)) {
- return QString::number(std::get<VariantIndex::BOOLEAN>(value));
- } else if (isIndex(value.index(), VariantIndex::INTEGER)) {
- return QString::number(std::get<VariantIndex::INTEGER>(value));
- }
- }
-
- virtual TypeVariant getValue() override {
- if (isIndex(value.index(), VariantIndex::QSTRING)) {
- return std::get<VariantIndex::QSTRING>(value);
- } else if (isIndex(value.index(), VariantIndex::BOOLEAN)) {
- return std::get<VariantIndex::BOOLEAN>(value);
- } else if (isIndex(value.index(), VariantIndex::INTEGER)) {
- return std::get<VariantIndex::INTEGER>(value);
- }
- }
-
- virtual void clear() override {
- if (isIndex(value.index(), VariantIndex::STRVEC)) {
- std::get<VariantIndex::STRVEC>(value).clear();
- } else if (isIndex(value.index(), VariantIndex::FILEVEC)) {
- std::get<VariantIndex::FILEVEC>(value).clear();
- } else if (isIndex(value.index(), VariantIndex::QSTRING)) {
- std::get<VariantIndex::QSTRING>(value).clear();
- } else if (isIndex(value.index(), VariantIndex::INTEGER)) {
- std::get<VariantIndex::INTEGER>(value) = 0;
- } else if (isIndex(value.index(), VariantIndex::BOOLEAN)) {
- std::get<VariantIndex::BOOLEAN>(value) = false;
- }
- }
-
- virtual bool isContainer() override {
- return (isIndex(value.index(), VariantIndex::STRVEC) || isIndex(value.index(), VariantIndex::FILEVEC));
- }
- private:
- QString name;
- ArgumentType type;
- TypeVariant value;
- };
- class Task {
- public:
- Task(){};
- Task(KFileData);
- Task(QVector<KFileData>);
- virtual void setArgument(QString name, TypeVariant arg) = 0;
- virtual const TaskArguments getTaskArguments() = 0;
- virtual TypeVariant getTaskArgument(QString name) = 0;
- virtual ArgumentValues getArgumentValues() = 0;
- virtual TaskType getType() = 0;
- virtual void defineTaskArguments() = 0;
- virtual void setDefaultValues() = 0;
- virtual const QVector<KFileData> getFiles() = 0;
- virtual bool isReady() = 0;
- virtual void clear() = 0;
- virtual ~Task(){};
- };
- }
- #endif
|