siderust-cpp 0.8.0
Header-only C++ wrapper for siderust
Loading...
Searching...
No Matches
ffi_core.hpp
Go to the documentation of this file.
1#pragma once
2
11#include <cstddef>
12#include <ostream>
13#include <stdexcept>
14#include <string>
15
16#include <tempoch/ffi_core.hpp>
17
18#ifdef __cplusplus
19using QttyQuantity = qtty_quantity_t;
20#endif
21
22extern "C" {
23#include "siderust_ffi.h"
24}
25
26namespace siderust {
27
28// ============================================================================
29// Exception Hierarchy
30// ============================================================================
31
32class SiderustException : public std::runtime_error {
33public:
34 explicit SiderustException(const std::string &msg) : std::runtime_error(msg) {}
35};
36
38public:
39 explicit NullPointerError(const std::string &msg) : SiderustException(msg) {}
40};
41
43public:
44 explicit InvalidFrameError(const std::string &msg) : SiderustException(msg) {}
45};
46
48public:
49 explicit InvalidCenterError(const std::string &msg) : SiderustException(msg) {}
50};
51
53public:
54 explicit TransformFailedError(const std::string &msg) : SiderustException(msg) {}
55};
56
58public:
59 explicit InvalidBodyError(const std::string &msg) : SiderustException(msg) {}
60};
61
63public:
64 explicit UnknownStarError(const std::string &msg) : SiderustException(msg) {}
65};
66
68public:
69 explicit InvalidPeriodError(const std::string &msg) : SiderustException(msg) {}
70};
71
73public:
74 explicit AllocationFailedError(const std::string &msg) : SiderustException(msg) {}
75};
76
78public:
79 explicit InvalidArgumentError(const std::string &msg) : SiderustException(msg) {}
80};
81
83public:
84 explicit InternalPanicError(const std::string &msg) : SiderustException(msg) {}
85};
86
88public:
89 explicit DataLoadError(const std::string &msg) : SiderustException(msg) {}
90};
91
93public:
94 explicit OutOfRangeError(const std::string &msg) : SiderustException(msg) {}
95};
96
98public:
99 explicit NoEopDataError(const std::string &msg) : SiderustException(msg) {}
100};
101
103public:
104 explicit InvalidDimensionError(const std::string &msg) : SiderustException(msg) {}
105};
106
107// ============================================================================
108// Error Translation
109// ============================================================================
110
111inline void check_status(siderust_status_t status, const char *operation) {
112 if (status == SIDERUST_STATUS_T_OK)
113 return;
114
115 std::string msg = std::string(operation) + " failed: ";
116 switch (status) {
117 case SIDERUST_STATUS_T_NULL_POINTER:
118 throw NullPointerError(msg + "null output pointer");
119 case SIDERUST_STATUS_T_INVALID_FRAME:
120 throw InvalidFrameError(msg + "invalid or unsupported frame");
121 case SIDERUST_STATUS_T_INVALID_CENTER:
122 throw InvalidCenterError(msg + "invalid or unsupported center");
123 case SIDERUST_STATUS_T_TRANSFORM_FAILED:
124 throw TransformFailedError(msg + "coordinate transform failed");
125 case SIDERUST_STATUS_T_INVALID_BODY:
126 throw InvalidBodyError(msg + "invalid body");
127 case SIDERUST_STATUS_T_UNKNOWN_STAR:
128 throw UnknownStarError(msg + "unknown star name");
129 case SIDERUST_STATUS_T_INVALID_PERIOD:
130 throw InvalidPeriodError(msg + "invalid period (start > end)");
131 case SIDERUST_STATUS_T_ALLOCATION_FAILED:
132 throw AllocationFailedError(msg + "memory allocation failed");
133 case SIDERUST_STATUS_T_INVALID_ARGUMENT:
134 throw InvalidArgumentError(msg + "invalid argument");
135 case SIDERUST_STATUS_T_INTERNAL_PANIC:
136 throw InternalPanicError(msg + "internal panic in Rust FFI");
137 case SIDERUST_STATUS_T_DATA_ERROR:
138 throw DataLoadError(msg + "data loading error (I/O, download, or parse)");
139 case SIDERUST_STATUS_T_OUT_OF_RANGE:
140 throw OutOfRangeError(msg + "epoch outside covered data range");
141 case SIDERUST_STATUS_T_NO_EOP_DATA:
142 throw NoEopDataError(msg + "Earth Orientation Parameters unavailable for epoch");
143 case SIDERUST_STATUS_T_INVALID_DIMENSION:
144 throw InvalidDimensionError(msg + "invalid array dimension");
145 default:
146 throw SiderustException(msg + "unknown error (" + std::to_string(status) + ")");
147 }
148}
149
151inline void check_tempoch_status(tempoch_status_t status, const char *operation) {
152 tempoch::check_status(status, operation);
153}
154
155// ============================================================================
156// FFI version
157// ============================================================================
158
163inline uint32_t ffi_version() { return siderust_ffi_version(); }
164
165// ============================================================================
166// Frame and Center Enums (C++ typed)
167// ============================================================================
168
169enum class Frame : int32_t {
170 ICRS = SIDERUST_FRAME_T_ICRS,
171 EclipticMeanJ2000 = SIDERUST_FRAME_T_ECLIPTIC_MEAN_J2000,
172 EquatorialMeanJ2000 = SIDERUST_FRAME_T_EQUATORIAL_MEAN_J2000,
173 EquatorialMeanOfDate = SIDERUST_FRAME_T_EQUATORIAL_MEAN_OF_DATE,
174 EquatorialTrueOfDate = SIDERUST_FRAME_T_EQUATORIAL_TRUE_OF_DATE,
175 Horizontal = SIDERUST_FRAME_T_HORIZONTAL,
176 ECEF = SIDERUST_FRAME_T_ECEF,
177 Galactic = SIDERUST_FRAME_T_GALACTIC,
178 GCRS = SIDERUST_FRAME_T_GCRS,
179 EclipticOfDate = SIDERUST_FRAME_T_ECLIPTIC_OF_DATE,
180 EclipticTrueOfDate = SIDERUST_FRAME_T_ECLIPTIC_TRUE_OF_DATE,
181 CIRS = SIDERUST_FRAME_T_CIRS,
182 TIRS = SIDERUST_FRAME_T_TIRS,
183 ITRF = SIDERUST_FRAME_T_ITRF,
184 ICRF = SIDERUST_FRAME_T_ICRF,
185};
186
187enum class Center : int32_t {
188 Barycentric = SIDERUST_CENTER_T_BARYCENTRIC,
189 Heliocentric = SIDERUST_CENTER_T_HELIOCENTRIC,
190 Geocentric = SIDERUST_CENTER_T_GEOCENTRIC,
191 Topocentric = SIDERUST_CENTER_T_TOPOCENTRIC,
192 Bodycentric = SIDERUST_CENTER_T_BODYCENTRIC,
193};
194
195enum class EarthOrientationModel : int32_t {
196 Iau2000A = SIDERUST_EARTH_ORIENTATION_MODEL_T_IAU2000_A,
197 Iau2000B = SIDERUST_EARTH_ORIENTATION_MODEL_T_IAU2000_B,
198 Iau2006 = SIDERUST_EARTH_ORIENTATION_MODEL_T_IAU2006,
199 Iau2006A = SIDERUST_EARTH_ORIENTATION_MODEL_T_IAU2006_A,
200};
201
202enum class CrossingDirection : int32_t {
203 Rising = SIDERUST_CROSSING_DIRECTION_T_RISING,
204 Setting = SIDERUST_CROSSING_DIRECTION_T_SETTING,
205};
206
207enum class CulminationKind : int32_t {
208 Max = SIDERUST_CULMINATION_KIND_T_MAX,
209 Min = SIDERUST_CULMINATION_KIND_T_MIN,
210};
211
212// ============================================================================
213// Stream operators for enums
214// ============================================================================
215
216inline std::ostream &operator<<(std::ostream &os, CrossingDirection dir) {
217 switch (dir) {
219 return os << "rising";
221 return os << "setting";
222 }
223 return os << "unknown";
224}
225
226inline std::ostream &operator<<(std::ostream &os, CulminationKind kind) {
227 switch (kind) {
229 return os << "max";
231 return os << "min";
232 }
233 return os << "unknown";
234}
235
236inline std::ostream &operator<<(std::ostream &os, EarthOrientationModel model) {
237 switch (model) {
239 return os << "Iau2000A";
241 return os << "Iau2000B";
243 return os << "Iau2006";
245 return os << "Iau2006A";
246 }
247 return os << "Unknown";
248}
249
250enum class RaConvention : int32_t {
251 MuAlpha = SIDERUST_RA_CONVENTION_T_MU_ALPHA,
252 MuAlphaStar = SIDERUST_RA_CONVENTION_T_MU_ALPHA_STAR,
253};
254
255namespace detail {
256
258inline siderust_subject_t make_body_subject(SiderustBody b) {
259 siderust_subject_t s{};
260 s.kind = SIDERUST_SUBJECT_KIND_T_BODY;
261 s.body = b;
262 return s;
263}
264
266inline siderust_subject_t make_star_subject(const SiderustStar *h) {
267 siderust_subject_t s{};
268 s.kind = SIDERUST_SUBJECT_KIND_T_STAR;
269 s.star_handle = h;
270 return s;
271}
272
274inline siderust_subject_t make_icrs_subject(const siderust_spherical_dir_t &dir) {
275 siderust_subject_t s{};
276 s.kind = SIDERUST_SUBJECT_KIND_T_ICRS;
277 s.icrs_dir = dir;
278 return s;
279}
280
282inline siderust_subject_t make_generic_target_subject(const SiderustGenericTarget *h) {
283 siderust_subject_t s{};
284 s.kind = SIDERUST_SUBJECT_KIND_T_GENERIC_TARGET;
285 s.generic_target_handle = h;
286 return s;
287}
288
289} // namespace detail
290
291} // namespace siderust
AllocationFailedError(const std::string &msg)
Definition ffi_core.hpp:74
DataLoadError(const std::string &msg)
Definition ffi_core.hpp:89
InternalPanicError(const std::string &msg)
Definition ffi_core.hpp:84
InvalidArgumentError(const std::string &msg)
Definition ffi_core.hpp:79
InvalidBodyError(const std::string &msg)
Definition ffi_core.hpp:59
InvalidCenterError(const std::string &msg)
Definition ffi_core.hpp:49
InvalidDimensionError(const std::string &msg)
Definition ffi_core.hpp:104
InvalidFrameError(const std::string &msg)
Definition ffi_core.hpp:44
InvalidPeriodError(const std::string &msg)
Definition ffi_core.hpp:69
NoEopDataError(const std::string &msg)
Definition ffi_core.hpp:99
NullPointerError(const std::string &msg)
Definition ffi_core.hpp:39
OutOfRangeError(const std::string &msg)
Definition ffi_core.hpp:94
SiderustException(const std::string &msg)
Definition ffi_core.hpp:34
TransformFailedError(const std::string &msg)
Definition ffi_core.hpp:54
UnknownStarError(const std::string &msg)
Definition ffi_core.hpp:64
siderust_subject_t make_generic_target_subject(const SiderustGenericTarget *h)
Build a siderust_subject_t for a generic target opaque handle.
Definition ffi_core.hpp:282
siderust_subject_t make_star_subject(const SiderustStar *h)
Build a siderust_subject_t for a star, borrowing the handle.
Definition ffi_core.hpp:266
siderust_subject_t make_body_subject(SiderustBody b)
Build a siderust_subject_t for a solar-system body.
Definition ffi_core.hpp:258
siderust_subject_t make_icrs_subject(const siderust_spherical_dir_t &dir)
Build a siderust_subject_t for a fixed ICRS direction.
Definition ffi_core.hpp:274
void check_status(siderust_status_t status, const char *operation)
Definition ffi_core.hpp:111
std::ostream & operator<<(std::ostream &os, AzimuthExtremumKind kind)
Stream operator for AzimuthExtremumKind.
Definition azimuth.hpp:395
void check_tempoch_status(tempoch_status_t status, const char *operation)
Backward-compatible wrapper — delegates to tempoch::check_status.
Definition ffi_core.hpp:151
uint32_t ffi_version()
Returns the siderust-ffi ABI version (major*10000 + minor*100 + patch).
Definition ffi_core.hpp:163
EarthOrientationModel
Definition ffi_core.hpp:195
@ Max
Northernmost (or easternmost) direction reached by the body.
@ Min
Southernmost (or westernmost) direction reached by the body.