task.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #ifndef TASK_HPP
  2. #define TASK_HPP
  3. #include <cassert>
  4. #include <cstring>
  5. class Task{
  6. public:
  7. struct Data;
  8. enum Statut{Undefined,Unaffected,Affected,Done};
  9. protected:
  10. char *input,*output;
  11. size_t input_size,output_size;
  12. Statut statut;
  13. public:
  14. Task();
  15. Task(const Task& task);
  16. Task(Task&& task);
  17. ~Task();
  18. Task& operator=(const Task& task);
  19. Task& operator=(Task&& task);
  20. Statut get_statut() const;
  21. void set_statut(Statut s);
  22. const char* get_input() const;
  23. const char* get_output() const;
  24. size_t get_input_size() const;
  25. size_t get_output_size() const;
  26. void set_input(char* buffer,size_t s);
  27. void set_output(char* buffer,size_t s);
  28. };
  29. struct Task::Data{
  30. char* buffer;
  31. size_t size;
  32. };
  33. inline
  34. Task::Task(){
  35. input=nullptr;
  36. output=nullptr;
  37. statut=Undefined;
  38. }
  39. inline
  40. Task::Task(const Task& task){
  41. input_size=task.input_size;
  42. output_size=task.output_size;
  43. if(task.input!=nullptr){
  44. memcpy(input,task.input,input_size);
  45. }
  46. if(task.output!=nullptr){
  47. memcpy(output,task.output,output_size);
  48. }
  49. statut=task.statut;
  50. }
  51. inline
  52. Task::Task(Task&& task){
  53. input_size=task.input_size;
  54. output_size=task.output_size;
  55. input=task.input;
  56. output=task.output;
  57. task.input=nullptr;
  58. task.output=nullptr;
  59. statut=task.statut;
  60. }
  61. inline
  62. Task::~Task(){
  63. if(input!=nullptr) delete[] input;
  64. if(output!=nullptr) delete[] output;
  65. }
  66. inline Task&
  67. Task::operator=(const Task& task){
  68. input_size=task.input_size;
  69. output_size=task.output_size;
  70. if(input==nullptr) delete[] input;
  71. if(output==nullptr) delete[] output;
  72. if(task.input!=nullptr){
  73. memcpy(input,task.input,input_size);
  74. }
  75. if(task.output!=nullptr){
  76. memcpy(output,task.output,output_size);
  77. }
  78. statut=task.statut;
  79. return *this;
  80. }
  81. inline
  82. Task& Task::operator=(Task&& task){
  83. input_size=task.input_size;
  84. output_size=task.output_size;
  85. input=task.input;
  86. output=task.output;
  87. task.input=nullptr;
  88. task.output=nullptr;
  89. statut=task.statut;
  90. return *this;
  91. }
  92. inline
  93. Task::Statut
  94. Task::get_statut() const{
  95. return statut;
  96. }
  97. inline
  98. void
  99. Task::set_statut(Statut s){
  100. statut=s;
  101. }
  102. inline
  103. const char*
  104. Task::get_input() const{
  105. return input;
  106. }
  107. inline
  108. const char*
  109. Task::get_output() const{
  110. return output;
  111. }
  112. inline
  113. size_t
  114. Task::get_input_size() const{
  115. return input_size;
  116. }
  117. inline
  118. size_t
  119. Task::get_output_size() const{
  120. return output_size;
  121. }
  122. inline
  123. void
  124. Task::set_input(char* buffer,size_t s){
  125. assert(input==nullptr);
  126. input_size=s;
  127. input=new char[s];
  128. memcpy(input,buffer,s);
  129. }
  130. inline
  131. void
  132. Task::set_output(char* buffer,size_t s){
  133. assert(output==nullptr);
  134. output_size=s;
  135. output=new char[s];
  136. memcpy(output,buffer,s);
  137. }
  138. #endif