aboutsummaryrefslogtreecommitdiff
path: root/src/platform/Exception.cpp
blob: d5ae470258ab6cf31d51c67b2aae86f543cfc9df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "cru/platform/Exception.h"
#include "cru/base/Exception.h"

#include <format>
#include <optional>
#include <string_view>

namespace cru::platform {
PlatformNotMatchException::PlatformNotMatchException(
    std::string resource_platform, std::string target_platform,
    std::optional<std::string> additional_message)
    : PlatformException(std::format(
          "Resource platform '{}' does not match target platform '{}'.",
          resource_platform_, target_platform_)),
      resource_platform_(std::move(resource_platform)),
      target_platform_(std::move(target_platform)) {
  AppendMessage(additional_message);
}

PlatformNotMatchException::PlatformNotMatchException(
    StringView resource_platform, StringView target_platform,
    std::optional<StringView> additional_message)
    : PlatformNotMatchException(
          resource_platform.ToUtf8(), target_platform.ToUtf8(),
          additional_message.has_value()
              ? std::make_optional(additional_message->ToUtf8())
              : std::nullopt) {}

PlatformNotMatchException::~PlatformNotMatchException() {}

PlatformUnsupportedException::PlatformUnsupportedException(
    std::string platform, std::string operation,
    std::optional<std::string_view> additional_message)
    : PlatformException(
          std::format("Operation '{}' is not supported on platform '{}'.",
                      operation, platform)),
      platform_(std::move(platform)),
      operation_(std::move(operation)) {
  AppendMessage(additional_message);
}

PlatformUnsupportedException::PlatformUnsupportedException(
    StringView platform, StringView operation,
    std::optional<StringView> additional_message)
    : PlatformUnsupportedException(
          platform.ToUtf8(), operation.ToUtf8(),
          additional_message.has_value()
              ? std::make_optional(additional_message->ToUtf8())
              : std::nullopt) {}

PlatformUnsupportedException::~PlatformUnsupportedException() {}

String PlatformUnsupportedException::GetPlatform() const {
  return String::FromUtf8(platform_);
}

String PlatformUnsupportedException::GetOperation() const {
  return String::FromUtf8(operation_);
}

}  // namespace cru::platform