tempoch-cpp 0.5.3
Header-only C++ wrapper for tempoch
Loading...
Searching...
No Matches
ffi_core.hpp
Go to the documentation of this file.
1#pragma once
2
11#include <stdexcept>
12#include <string>
13
14extern "C" {
15#include "tempoch_ffi.h"
16}
17
18namespace tempoch {
19
20// ============================================================================
21// Exception Hierarchy
22// ============================================================================
23
27class TempochException : public std::runtime_error {
28public:
29 explicit TempochException(const std::string &msg) : std::runtime_error(msg) {}
30};
31
36public:
37 explicit NullPointerError(const std::string &msg) : TempochException(msg) {}
38};
39
44public:
45 explicit UtcConversionError(const std::string &msg) : TempochException(msg) {}
46};
47
52public:
53 explicit InvalidPeriodError(const std::string &msg) : TempochException(msg) {}
54};
55
60public:
61 explicit NoIntersectionError(const std::string &msg) : TempochException(msg) {}
62};
63
68public:
69 explicit InvalidScaleIdError(const std::string &msg) : TempochException(msg) {}
70};
71
76public:
77 explicit InvalidDurationUnitError(const std::string &msg) : TempochException(msg) {}
78};
79
84public:
85 explicit ConversionFailedError(const std::string &msg) : TempochException(msg) {}
86};
87
92public:
93 explicit InvalidFormatIdError(const std::string &msg) : TempochException(msg) {}
94};
95
100public:
101 explicit InternalPanicError(const std::string &msg) : TempochException(msg) {}
102};
103
108public:
109 explicit Ut1HorizonExceededError(const std::string &msg) : TempochException(msg) {}
110};
111
118public:
119 explicit PeriodListUnsortedError(const std::string &msg) : TempochException(msg) {}
120};
121
128public:
129 explicit PeriodListOverlappingError(const std::string &msg) : TempochException(msg) {}
130};
131
132// ============================================================================
133// Error Translation
134// ============================================================================
135
139inline void check_status(tempoch_status_t status, const char *operation) {
140 if (status == TEMPOCH_STATUS_T_OK)
141 return;
142
143 std::string msg = std::string(operation) + " failed: ";
144 switch (status) {
145 case TEMPOCH_STATUS_T_NULL_POINTER:
146 throw NullPointerError(msg + "null output pointer");
147 case TEMPOCH_STATUS_T_UTC_CONVERSION_FAILED:
148 throw UtcConversionError(msg + "UTC conversion failed");
149 case TEMPOCH_STATUS_T_INVALID_PERIOD:
150 throw InvalidPeriodError(msg + "invalid period (start > end)");
151 case TEMPOCH_STATUS_T_NO_INTERSECTION:
152 throw NoIntersectionError(msg + "periods do not intersect");
153 case TEMPOCH_STATUS_T_INVALID_SCALE_ID:
154 throw InvalidScaleIdError(msg + "invalid scale id");
155 case TEMPOCH_STATUS_T_INVALID_DURATION_UNIT:
156 throw InvalidDurationUnitError(msg + "invalid duration unit");
157 case TEMPOCH_STATUS_T_CONVERSION_FAILED:
158 throw ConversionFailedError(msg + "conversion failed");
159 case TEMPOCH_STATUS_T_INVALID_FORMAT_ID:
160 throw InvalidFormatIdError(msg + "invalid format id");
161 case TEMPOCH_STATUS_T_INTERNAL_PANIC:
162 throw InternalPanicError(msg + "internal panic");
163 case TEMPOCH_STATUS_T_UT1_HORIZON_EXCEEDED:
164 throw Ut1HorizonExceededError(msg + "UT1 horizon exceeded");
165 case TEMPOCH_STATUS_T_PERIOD_LIST_UNSORTED:
166 throw PeriodListUnsortedError(msg + "period list is not sorted");
167 case TEMPOCH_STATUS_T_PERIOD_LIST_OVERLAPPING:
168 throw PeriodListOverlappingError(msg + "period list has overlapping intervals");
169 default:
170 throw TempochException(msg + "unknown error (" + std::to_string(status) + ")");
171 }
172}
173
174} // namespace tempoch
A generic scale/format conversion failed.
Definition ffi_core.hpp:83
ConversionFailedError(const std::string &msg)
Definition ffi_core.hpp:85
Rust caught a panic before unwinding across the FFI boundary.
Definition ffi_core.hpp:99
InternalPanicError(const std::string &msg)
Definition ffi_core.hpp:101
The supplied quantity does not represent a time duration.
Definition ffi_core.hpp:75
InvalidDurationUnitError(const std::string &msg)
Definition ffi_core.hpp:77
The supplied raw format identifier is invalid.
Definition ffi_core.hpp:91
InvalidFormatIdError(const std::string &msg)
Definition ffi_core.hpp:93
The period is invalid (start > end).
Definition ffi_core.hpp:51
InvalidPeriodError(const std::string &msg)
Definition ffi_core.hpp:53
The supplied raw scale identifier is invalid.
Definition ffi_core.hpp:67
InvalidScaleIdError(const std::string &msg)
Definition ffi_core.hpp:69
The two periods do not intersect.
Definition ffi_core.hpp:59
NoIntersectionError(const std::string &msg)
Definition ffi_core.hpp:61
A required output pointer was null.
Definition ffi_core.hpp:35
NullPointerError(const std::string &msg)
Definition ffi_core.hpp:37
The period list contains overlapping intervals.
Definition ffi_core.hpp:127
PeriodListOverlappingError(const std::string &msg)
Definition ffi_core.hpp:129
The period list is not sorted by start time.
Definition ffi_core.hpp:117
PeriodListUnsortedError(const std::string &msg)
Definition ffi_core.hpp:119
Base exception for all tempoch errors.
Definition ffi_core.hpp:27
TempochException(const std::string &msg)
Definition ffi_core.hpp:29
A UT1 conversion requested data beyond the compiled ΔT/EOP horizon.
Definition ffi_core.hpp:107
Ut1HorizonExceededError(const std::string &msg)
Definition ffi_core.hpp:109
UTC conversion failed (date out of range or invalid).
Definition ffi_core.hpp:43
UtcConversionError(const std::string &msg)
Definition ffi_core.hpp:45
void check_status(tempoch_status_t status, const char *operation)
Check a tempoch_status_t and throw the appropriate exception on error.
Definition ffi_core.hpp:139