siderust-cpp 0.8.0
Header-only C++ wrapper for siderust
Loading...
Searching...
No Matches
astro_context.hpp
Go to the documentation of this file.
1#pragma once
2
8#include "ffi_core.hpp"
9
10namespace siderust {
11
15
19
23
27
30
31public:
32 constexpr AstroContext() = default;
33 constexpr explicit AstroContext(EarthOrientationModel model) : model_(model) {}
34
35 constexpr EarthOrientationModel model() const { return model_; }
36
37 template <typename ModelTag> constexpr AstroContext with_model() const {
38 return AstroContext(ModelTag::model_id);
39 }
40
43 siderust_context_t *h = nullptr;
44 check_status(siderust_context_create_default(&h), "AstroContext::from_default_ffi");
45 siderust_earth_orientation_model_t model_out{};
46 auto st = siderust_context_get_model(h, &model_out);
47 siderust_context_free(h);
48 check_status(st, "AstroContext::from_default_ffi::get_model");
49 return AstroContext(static_cast<EarthOrientationModel>(model_out));
50 }
51};
52
53namespace detail {
54
59public:
62 check_status(siderust_context_create_default(&handle_), "AstroContext::create_default");
63 }
64
66 check_status(siderust_context_create_with_model(
67 static_cast<siderust_earth_orientation_model_t>(model), &handle_),
68 "AstroContext::create");
69 }
70 explicit OwnedFfiContext(const AstroContext &ctx) : OwnedFfiContext(ctx.model()) {}
71
74
76 if (handle_) {
77 siderust_context_free(handle_);
78 }
79 }
80
83 siderust_earth_orientation_model_t out{};
84 check_status(siderust_context_get_model(handle_, &out), "OwnedFfiContext::model");
85 return static_cast<EarthOrientationModel>(out);
86 }
87
88 const siderust_context_t *get() const { return handle_; }
89
90private:
91 siderust_context_t *handle_ = nullptr;
92};
93
94} // namespace detail
95
96} // namespace siderust
constexpr AstroContext(EarthOrientationModel model)
constexpr EarthOrientationModel model() const
constexpr AstroContext()=default
constexpr AstroContext with_model() const
static AstroContext from_default_ffi()
Create an AstroContext reflecting the Rust library's built-in default.
OwnedFfiContext & operator=(const OwnedFfiContext &)=delete
OwnedFfiContext(const OwnedFfiContext &)=delete
OwnedFfiContext(EarthOrientationModel model)
const siderust_context_t * get() const
OwnedFfiContext(const AstroContext &ctx)
OwnedFfiContext()
Create a context using the Rust library's built-in default model.
EarthOrientationModel model() const
Query the Earth-orientation model stored inside this FFI context handle.
Error handling and utility base for the siderust C++ wrapper.
void check_status(siderust_status_t status, const char *operation)
Definition ffi_core.hpp:111
EarthOrientationModel
Definition ffi_core.hpp:195
static constexpr EarthOrientationModel model_id
static constexpr EarthOrientationModel model_id
static constexpr EarthOrientationModel model_id
static constexpr EarthOrientationModel model_id