libnmbs 1.0.0
Loading...
Searching...
No Matches
expected.h
Go to the documentation of this file.
1
27
28#pragma once
29
30#include <expected>
31#include <string>
32#include <utility>
33
34#include "exit_code.h"
35
36namespace nmbs
37{
47 class Error
48 {
49 ExitCode code_;
50 std::string message_;
51
52 private:
53 Error(const ExitCode code, std::string message) : code_(code), message_(std::move(message))
54 {
55 }
56
57 public:
60 Error() = delete;
61
64 Error(Error&&) noexcept = default;
65
68 Error& operator=(Error&&) noexcept = default;
69
72 Error(const Error&) = default;
73
76 Error& operator=(const Error&) = default;
77
81 [[nodiscard]] ExitCode code() const { return code_; }
82
86 [[nodiscard]] const std::string& message() const { return message_; }
87
91 static Error unexpected(
92 std::string message = "An unexpected error occurred")
93 {
94 return {ExitCode::unknown_error, std::move(message)};
95 }
96
100 static Error file_not_found(
101 std::string message = "Requested resource could not be found")
102 {
103 return {ExitCode::file_not_found, std::move(message)};
104 }
105
109 static Error xmp_not_found(
110 std::string message = "Requested resource did not contain any XMP data (at all)")
111 {
112 return {ExitCode::xmp_not_found, std::move(message)};
113 }
114
118 static Error xmp_key_not_found(
119 std::string message = "Requested resource did not contain the desired XMP key")
120 {
121 return {ExitCode::xmp_key_not_found, std::move(message)};
122 }
123
128 std::string message = "Requested XML could not be read")
129 {
130 return {ExitCode::xml_could_not_parse, std::move(message)};
131 }
132
137 std::string message = "Requested XML could not be read")
138 {
140 }
141
145 static Error no_binding_support(
146 std::string message = "Requested file does not support any supported binding mechanism")
147 {
148 return {ExitCode::no_binding_support, std::move(message)};
149 }
150 };
151
155 template <typename T>
156 using Expected = std::expected<T, Error>;
157}
static Error xmp_key_not_found(std::string message="Requested resource did not contain the desired XMP key")
Creates an XMP key missing error.
Definition expected.h:118
Error(Error &&) noexcept=default
Default move constructor.
ExitCode code() const
Retrieves the underlying error code.
Definition expected.h:81
Error()=delete
Default constructor is explicitly deleted.
static Error xml_could_not_create_xpath_context(std::string message="Requested XML could not be read")
Creates an XML XPath context error.
Definition expected.h:136
static Error xmp_not_found(std::string message="Requested resource did not contain any XMP data (at all)")
Creates an XMP data missing error.
Definition expected.h:109
static Error unexpected(std::string message="An unexpected error occurred")
Creates an unknown error.
Definition expected.h:91
const std::string & message() const
Retrieves the descriptive error message.
Definition expected.h:86
static Error file_not_found(std::string message="Requested resource could not be found")
Creates a file not found error.
Definition expected.h:100
static Error xml_could_not_parse(std::string message="Requested XML could not be read")
Creates an XML parsing error.
Definition expected.h:127
static Error no_binding_support(std::string message="Requested file does not support any supported binding mechanism")
Creates an unsupported binding error.
Definition expected.h:145
Standardized integer exit codes for the nmbs application and library.
Lightweight utilities for NATO confidentiality metadata.
Definition binding.h:38
std::expected< T, Error > Expected
Alias for std::expected standardized with nmbs::Error.
Definition expected.h:156
ExitCode
Standard exit codes produced by nmbs tools.
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 or unknown error occurred.
Definition exit_code.h:73
@ xml_could_not_create_xpath_context
The XML parser was unable to create an XPath context.
Definition exit_code.h:61
@ xmp_not_found
No XMP packet was attached to the file.
Definition exit_code.h:49
@ no_binding_support
No binding profile is available for the selected file type.
Definition exit_code.h:69
@ xmp_key_not_found
The file contained XMP, but the desired key was missing.
Definition exit_code.h:53