siderust-cpp
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 <stdexcept>
13#include <string>
14
15#include <tempoch/ffi_core.hpp>
16
17extern "C" {
18#include "siderust_ffi.h"
19}
20
21namespace siderust {
22
23// ============================================================================
24// Exception Hierarchy
25// ============================================================================
26
27class SiderustException : public std::runtime_error {
28 public:
29 explicit SiderustException(const std::string& msg) : std::runtime_error(msg) {}
30};
31
33 public:
34 explicit NullPointerError(const std::string& msg) : SiderustException(msg) {}
35};
36
38 public:
39 explicit InvalidFrameError(const std::string& msg) : SiderustException(msg) {}
40};
41
43 public:
44 explicit InvalidCenterError(const std::string& msg) : SiderustException(msg) {}
45};
46
48 public:
49 explicit TransformFailedError(const std::string& msg) : SiderustException(msg) {}
50};
51
53 public:
54 explicit InvalidBodyError(const std::string& msg) : SiderustException(msg) {}
55};
56
58 public:
59 explicit UnknownStarError(const std::string& msg) : SiderustException(msg) {}
60};
61
63 public:
64 explicit InvalidPeriodError(const std::string& msg) : SiderustException(msg) {}
65};
66
68 public:
69 explicit AllocationFailedError(const std::string& msg) : SiderustException(msg) {}
70};
71
73 public:
74 explicit InvalidArgumentError(const std::string& msg) : SiderustException(msg) {}
75};
76
77// ============================================================================
78// Error Translation
79// ============================================================================
80
81inline void check_status(siderust_status_t status, const char* operation) {
82 if (status == SIDERUST_STATUS_T_OK)
83 return;
84
85 std::string msg = std::string(operation) + " failed: ";
86 switch (status) {
87 case SIDERUST_STATUS_T_NULL_POINTER:
88 throw NullPointerError(msg + "null output pointer");
89 case SIDERUST_STATUS_T_INVALID_FRAME:
90 throw InvalidFrameError(msg + "invalid or unsupported frame");
91 case SIDERUST_STATUS_T_INVALID_CENTER:
92 throw InvalidCenterError(msg + "invalid or unsupported center");
93 case SIDERUST_STATUS_T_TRANSFORM_FAILED:
94 throw TransformFailedError(msg + "coordinate transform failed");
95 case SIDERUST_STATUS_T_INVALID_BODY:
96 throw InvalidBodyError(msg + "invalid body");
97 case SIDERUST_STATUS_T_UNKNOWN_STAR:
98 throw UnknownStarError(msg + "unknown star name");
99 case SIDERUST_STATUS_T_INVALID_PERIOD:
100 throw InvalidPeriodError(msg + "invalid period (start > end)");
101 case SIDERUST_STATUS_T_ALLOCATION_FAILED:
102 throw AllocationFailedError(msg + "memory allocation failed");
103 case SIDERUST_STATUS_T_INVALID_ARGUMENT:
104 throw InvalidArgumentError(msg + "invalid argument");
105 default:
106 throw SiderustException(msg + "unknown error (" + std::to_string(status) + ")");
107 }
108}
109
111inline void check_tempoch_status(tempoch_status_t status, const char* operation) {
112 tempoch::check_status(status, operation);
113}
114
115// ============================================================================
116// Frame and Center Enums (C++ typed)
117// ============================================================================
118
119enum class Frame : int32_t {
120 ICRS = SIDERUST_FRAME_T_ICRS,
121 EclipticMeanJ2000 = SIDERUST_FRAME_T_ECLIPTIC_MEAN_J2000,
122 EquatorialMeanJ2000 = SIDERUST_FRAME_T_EQUATORIAL_MEAN_J2000,
123 EquatorialMeanOfDate = SIDERUST_FRAME_T_EQUATORIAL_MEAN_OF_DATE,
124 EquatorialTrueOfDate = SIDERUST_FRAME_T_EQUATORIAL_TRUE_OF_DATE,
125 Horizontal = SIDERUST_FRAME_T_HORIZONTAL,
126 ECEF = SIDERUST_FRAME_T_ECEF,
127 Galactic = SIDERUST_FRAME_T_GALACTIC,
128 GCRS = SIDERUST_FRAME_T_GCRS,
129 EclipticOfDate = SIDERUST_FRAME_T_ECLIPTIC_OF_DATE,
130 EclipticTrueOfDate = SIDERUST_FRAME_T_ECLIPTIC_TRUE_OF_DATE,
131 CIRS = SIDERUST_FRAME_T_CIRS,
132 TIRS = SIDERUST_FRAME_T_TIRS,
133 ITRF = SIDERUST_FRAME_T_ITRF,
134 ICRF = SIDERUST_FRAME_T_ICRF,
135};
136
137enum class Center : int32_t {
138 Barycentric = SIDERUST_CENTER_T_BARYCENTRIC,
139 Heliocentric = SIDERUST_CENTER_T_HELIOCENTRIC,
140 Geocentric = SIDERUST_CENTER_T_GEOCENTRIC,
141 Topocentric = SIDERUST_CENTER_T_TOPOCENTRIC,
142 Bodycentric = SIDERUST_CENTER_T_BODYCENTRIC,
143};
144
145enum class CrossingDirection : int32_t {
146 Rising = SIDERUST_CROSSING_DIRECTION_T_RISING,
147 Setting = SIDERUST_CROSSING_DIRECTION_T_SETTING,
148};
149
150enum class CulminationKind : int32_t {
151 Max = SIDERUST_CULMINATION_KIND_T_MAX,
152 Min = SIDERUST_CULMINATION_KIND_T_MIN,
153};
154
155enum class RaConvention : int32_t {
156 MuAlpha = SIDERUST_RA_CONVENTION_T_MU_ALPHA,
157 MuAlphaStar = SIDERUST_RA_CONVENTION_T_MU_ALPHA_STAR,
158};
159
160} // namespace siderust
AllocationFailedError(const std::string &msg)
Definition ffi_core.hpp:69
InvalidArgumentError(const std::string &msg)
Definition ffi_core.hpp:74
InvalidBodyError(const std::string &msg)
Definition ffi_core.hpp:54
InvalidCenterError(const std::string &msg)
Definition ffi_core.hpp:44
InvalidFrameError(const std::string &msg)
Definition ffi_core.hpp:39
InvalidPeriodError(const std::string &msg)
Definition ffi_core.hpp:64
NullPointerError(const std::string &msg)
Definition ffi_core.hpp:34
SiderustException(const std::string &msg)
Definition ffi_core.hpp:29
TransformFailedError(const std::string &msg)
Definition ffi_core.hpp:49
UnknownStarError(const std::string &msg)
Definition ffi_core.hpp:59
void check_status(siderust_status_t status, const char *operation)
Definition ffi_core.hpp:81
void check_tempoch_status(tempoch_status_t status, const char *operation)
Backward-compatible wrapper — delegates to tempoch::check_status.
Definition ffi_core.hpp:111