libnmbs 1.0.0
Loading...
Searching...
No Matches
expected.h
Go to the documentation of this file.
1
26
27#pragma once
28
29#include <expected>
30#include <string>
31#include <utility>
32
33#include "exit_code.h"
34
35namespace nmbs
36{
37
49 class Error
50 {
51 ExitCode code_;
52 std::string message_;
53
54 private:
55 Error(const ExitCode code, std::string message) : code_(code), message_(std::move(message))
56 {
57 }
58
59 public:
60 Error() = delete;
61 Error(Error&&) noexcept = default;
62 Error& operator=(Error&&) noexcept = default;
63 Error(const Error&) = default;
64 Error& operator=(const Error&) = default;
65
66 [[nodiscard]] ExitCode code() const { return code_; }
67 [[nodiscard]] const std::string& message() const { return message_; }
68
69 static Error unexpected(
70 std::string message = "An unexpected error occurred")
71 {
72 return {ExitCode::unknown_error, std::move(message)};
73 }
74
75 static Error file_not_found(
76 std::string message = "Requested resource could not be found")
77 {
78 return {ExitCode::file_not_found, std::move(message)};
79 }
80
81 static Error xmp_not_found(
82 std::string message = "Requested resource did not contain any XMP data (at all)")
83 {
84 return {ExitCode::xmp_not_found, std::move(message)};
85 }
86
87 static Error xmp_key_not_found(
88 std::string message = "Requested resource did not contain the desired XMP key")
89 {
90 return {ExitCode::xmp_key_not_found, std::move(message)};
91 }
92
93 static Error xml_could_not_parse(
94 std::string message = "Requested XML could not be read")
95 {
96 return {ExitCode::xml_could_not_parse, std::move(message)};
97 }
98
100 std::string message = "Requested XML could not be read")
101 {
103 }
104
105 static Error no_binding_support(
106 std::string message = "Requested file does not support any supported binding mechanism")
107 {
108 return {ExitCode::no_binding_support, std::move(message)};
109 }
110
111 };
112
115 template <typename T>
116 using Expected = std::expected<T, Error>;
117}
static Error xmp_key_not_found(std::string message="Requested resource did not contain the desired XMP key")
Definition expected.h:87
Error(Error &&) noexcept=default
ExitCode code() const
Definition expected.h:66
Error()=delete
static Error xml_could_not_create_xpath_context(std::string message="Requested XML could not be read")
Definition expected.h:99
static Error xmp_not_found(std::string message="Requested resource did not contain any XMP data (at all)")
Definition expected.h:81
static Error unexpected(std::string message="An unexpected error occurred")
Definition expected.h:69
const std::string & message() const
Definition expected.h:67
static Error file_not_found(std::string message="Requested resource could not be found")
Definition expected.h:75
static Error xml_could_not_parse(std::string message="Requested XML could not be read")
Definition expected.h:93
static Error no_binding_support(std::string message="Requested file does not support any supported binding mechanism")
Definition expected.h:105
Basic enum containing a list of integer exit codes which the application may use.
Lightweight helpers for generating NATO confidentiality metadata.
Definition binding.h:32
std::expected< T, Error > Expected
Convenience typedef to standardise usage of nmbs::error in all std::expected usages.
Definition expected.h:116
ExitCode
Definition exit_code.h:33
@ xml_could_not_parse
The XML parser was unable to read the provided XML.
Definition exit_code.h:57
@ file_not_found
The specified file could not be found.
Definition exit_code.h:45
@ unknown_error
An unspecified error occurred.
Definition exit_code.h:73
@ xml_could_not_create_xpath_context
The XML parser was unable to read create an XPath context.
Definition exit_code.h:61
@ xmp_not_found
There was no XMP packet attached to a file.
Definition exit_code.h:49
@ no_binding_support
There was no binding profile available for the selected file.
Definition exit_code.h:69
@ xmp_key_not_found
Although the file contained XMP, the desired key was not found.
Definition exit_code.h:53