task.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef __TASK_HPP__
  2. #define __TASK_HPP__
  3. #include <QQueue>
  4. #include <QString>
  5. #include <memory>
  6. #include <variant>
  7. #include <vector>
  8. enum FileType { VIDEO = 1, IMAGE = 2 };
  9. struct KFileData {
  10. QString name;
  11. FileType type;
  12. QString path;
  13. QByteArray bytes;
  14. };
  15. namespace Scheduler {
  16. namespace Type {
  17. static constexpr const char* TEXT = "Text";
  18. static constexpr const char* FILE = "File";
  19. static constexpr const char* STRINGVECTOR = "StringVector";
  20. static constexpr const char* FILEVECTOR = "FileVector";
  21. static constexpr const char* DATETIME = "DateTime";
  22. static constexpr const char* BOOLEAN = "Boolean";
  23. } // namespace Type
  24. using ArgumentType = const char*;
  25. using TypeVariant = std::variant<QString, bool, std::vector<std::string>, std::vector<KFileData>>;
  26. class TaskArgumentBase {
  27. public:
  28. virtual QString text() const = 0;
  29. virtual void setValue(TypeVariant v) = 0;
  30. };
  31. template <typename T>
  32. class TaskArgument : TaskArgumentBase {
  33. public:
  34. TaskArgument(QString n, ArgumentType t, T _value) {
  35. name = n;
  36. type = t;
  37. value = _value;
  38. }
  39. TaskArgument(TaskArgument&& a) : name(std::move(a.name)), type(std::move(a.type)), value(std::move(a.value)) {}
  40. virtual QString text() const { return name; }
  41. virtual void setValue(TypeVariant new_value) override { value = new_value; }
  42. QString name;
  43. ArgumentType type;
  44. T value;
  45. };
  46. using TaskIterator = std::vector<std::unique_ptr<TaskArgumentBase>>::iterator;
  47. using TaskArguments = std::vector<std::unique_ptr<TaskArgumentBase>>;
  48. class Task {
  49. public:
  50. virtual void defineTaskArguments() = 0;
  51. virtual bool isReady() = 0;
  52. virtual const TaskArguments getTaskArguments() = 0;
  53. virtual void clear() = 0;
  54. virtual ~Task(){};
  55. };
  56. } // namespace Scheduler
  57. typedef QQueue<Task> TaskQueue;
  58. #endif // __TASK_HPP__