task.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef __TASK_HPP__
  2. #define __TASK_HPP__
  3. #include <QQueue>
  4. #include <QString>
  5. #include <memory>
  6. #include <variant>
  7. #include <vector>
  8. namespace Scheduler {
  9. enum FileType { VIDEO = 1, IMAGE = 2 };
  10. struct KFileData {
  11. QString name;
  12. FileType type;
  13. QString path;
  14. QByteArray bytes;
  15. };
  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. class TaskArgumentBase;
  25. class Task;
  26. using ArgumentType = const char*;
  27. using TypeVariant = std::variant<QString, bool, std::vector<std::string>, std::vector<KFileData>>;
  28. using TaskIterator = std::vector<std::unique_ptr<TaskArgumentBase>>::iterator;
  29. using TaskArguments = std::vector<std::unique_ptr<TaskArgumentBase>>;
  30. using TaskQueue = QQueue<Task>;
  31. class TaskArgumentBase {
  32. public:
  33. virtual QString text() const = 0;
  34. virtual void setValue(TypeVariant v) = 0;
  35. };
  36. template <typename T>
  37. class TaskArgument : TaskArgumentBase {
  38. public:
  39. TaskArgument(QString n, ArgumentType t, T _value) {
  40. name = n;
  41. type = t;
  42. value = _value;
  43. }
  44. TaskArgument(TaskArgument&& a) : name(std::move(a.name)), type(std::move(a.type)), value(std::move(a.value)) {}
  45. virtual QString text() const { return name; }
  46. virtual void setValue(TypeVariant new_value) override { value = new_value; }
  47. QString name;
  48. ArgumentType type;
  49. T value;
  50. };
  51. class Task {
  52. public:
  53. virtual void defineTaskArguments() = 0;
  54. virtual bool isReady() = 0;
  55. virtual const TaskArguments getTaskArguments() = 0;
  56. virtual void clear() = 0;
  57. virtual ~Task(){};
  58. };
  59. } // namespace Scheduler
  60. #endif // __TASK_HPP__