DatOperationResult.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // Created by kikab on 04.06.2018.
  3. //
  4. #ifndef LOTRO_DAT_LIBRARY_DATOPERATIONRESULT_H
  5. #define LOTRO_DAT_LIBRARY_DATOPERATIONRESULT_H
  6. #include <string>
  7. #include <memory>
  8. #include <utility>
  9. #include <BinaryData.h>
  10. extern "C++"
  11. {
  12. namespace LOTRO_DAT {
  13. enum DAT_OPERATION_RESULT {
  14. SUCCESS = 1,
  15. ERROR = 0
  16. };
  17. template<typename... OutputData> class DatOperationResult {
  18. typedef DAT_OPERATION_RESULT RESULT;
  19. };
  20. class __DatOperationResult_base {
  21. public:
  22. typedef DAT_OPERATION_RESULT RESULT;
  23. __DatOperationResult_base() : result(SUCCESS), msg("No message") {}
  24. __DatOperationResult_base(const __DatOperationResult_base &other) = default;
  25. __DatOperationResult_base(__DatOperationResult_base &&other) noexcept = default;
  26. __DatOperationResult_base(RESULT result_, std::string msg_) : result(result_), msg(std::move(msg_)) {}
  27. __DatOperationResult_base &operator=(const __DatOperationResult_base& other) = default;
  28. __DatOperationResult_base &operator=(__DatOperationResult_base&& other) = default;
  29. RESULT result;
  30. std::string msg;
  31. };
  32. template <>
  33. class DatOperationResult<> : public __DatOperationResult_base {
  34. public:
  35. DatOperationResult() : __DatOperationResult_base() {}
  36. explicit DatOperationResult(RESULT result_) : __DatOperationResult_base(result_, "No message") {}
  37. DatOperationResult(RESULT result_, std::string msg_) : __DatOperationResult_base(result_, std::move(msg_)) {}
  38. };
  39. template<typename Output>
  40. class DatOperationResult<Output> : public __DatOperationResult_base {
  41. public:
  42. typedef DAT_OPERATION_RESULT RESULT;
  43. DatOperationResult() = delete;
  44. DatOperationResult(const DatOperationResult<Output>& other) : __DatOperationResult_base(), value(other.value) {}
  45. DatOperationResult(DatOperationResult<Output> &&other) noexcept : __DatOperationResult_base(), value(std::move(other.value)) {}
  46. template <typename OutputRef>
  47. DatOperationResult(OutputRef&& output_, RESULT result_, const std::string& msg_ = std::string("No message provided")) : __DatOperationResult_base(result_, msg_), value(std::forward<Output>(output_)) {}
  48. operator Output() const {return value;}
  49. Output value;
  50. };
  51. }
  52. }
  53. #endif //LOTRO_DAT_LIBRARY_DATOPERATIONRESULT_H