DatOperationResult.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #include <EasyLogging++/easylogging++.h>
  11. extern "C++"
  12. {
  13. namespace LOTRO_DAT {
  14. enum DAT_OPERATION_RESULT {
  15. SUCCESS = 1,
  16. ERROR = 0
  17. };
  18. template<typename... OutputData>
  19. class DatOperationResult {
  20. typedef DAT_OPERATION_RESULT RESULT;
  21. };
  22. class __DatOperationResult_base {
  23. public:
  24. typedef DAT_OPERATION_RESULT RESULT;
  25. __DatOperationResult_base() : result(SUCCESS), msg("No message") {}
  26. __DatOperationResult_base(const __DatOperationResult_base &other) = default;
  27. __DatOperationResult_base(__DatOperationResult_base &&other) noexcept = default;
  28. __DatOperationResult_base(RESULT result_, std::string msg_) : result(result_), msg(std::move(msg_)) {
  29. if (result_ == ERROR)
  30. LOG(ERROR) << msg;
  31. }
  32. __DatOperationResult_base &operator=(const __DatOperationResult_base &other) = default;
  33. __DatOperationResult_base &operator=(__DatOperationResult_base &&other) = default;
  34. RESULT result;
  35. std::string msg;
  36. };
  37. template<>
  38. class DatOperationResult<> : public __DatOperationResult_base {
  39. public:
  40. DatOperationResult() : __DatOperationResult_base() {}
  41. explicit DatOperationResult(RESULT result_) : __DatOperationResult_base(result_, "No message") {}
  42. DatOperationResult(RESULT result_, std::string msg_) : __DatOperationResult_base(result_, std::move(msg_)) {}
  43. };
  44. template<typename Output>
  45. class DatOperationResult<Output> : public __DatOperationResult_base {
  46. public:
  47. typedef DAT_OPERATION_RESULT RESULT;
  48. DatOperationResult() = delete;
  49. DatOperationResult(const DatOperationResult<Output> &other) : __DatOperationResult_base(), value(other.value) {}
  50. DatOperationResult(DatOperationResult<Output> &&other) noexcept
  51. : __DatOperationResult_base(), value(std::move(other.value)) {}
  52. DatOperationResult(Output &&output_, RESULT result_, const std::string &msg_ = std::string("No message provided")) : __DatOperationResult_base(
  53. result_, msg_), value(output_) {}
  54. DatOperationResult(const Output &output_, RESULT result_, const std::string &msg_ = std::string("No message provided")) : __DatOperationResult_base(
  55. result_, msg_), value(output_) {}
  56. Output value;
  57. };
  58. }
  59. }
  60. #endif //LOTRO_DAT_LIBRARY_DATOPERATIONRESULT_H