Instrument Neutral Distributed Interface INDI 2.2.5
indimacros.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 by Pawel Soja <[email protected]>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17*/
18
19#pragma once
20
21#if defined(_MSC_VER)
22# define _USE_MATH_DEFINES
23#endif
24#include <math.h>
25
26// ============================================================
27// Astronomical / physical constants
28// ============================================================
29#ifndef J2000
30# define J2000 2451545.0
31#endif
32#ifndef ERRMSG_SIZE
33# define ERRMSG_SIZE 1024
34#endif
35#ifndef STELLAR_DAY
36# define STELLAR_DAY 86164.098903691
37#endif
38#ifndef TRACKRATE_SIDEREAL
39# define TRACKRATE_SIDEREAL ((360.0 * 3600.0) / STELLAR_DAY)
40#endif
41#ifndef SOLAR_DAY
42# define SOLAR_DAY 86400
43#endif
44#ifndef TRACKRATE_SOLAR
45# define TRACKRATE_SOLAR ((360.0 * 3600.0) / SOLAR_DAY)
46#endif
47#ifndef TRACKRATE_LUNAR
48# define TRACKRATE_LUNAR 14.511415
49#endif
50#ifndef EARTHRADIUSEQUATORIAL
51# define EARTHRADIUSEQUATORIAL 6378137.0
52#endif
53#ifndef EARTHRADIUSPOLAR
54# define EARTHRADIUSPOLAR 6356752.0
55#endif
56#ifndef EARTHRADIUSMEAN
57# define EARTHRADIUSMEAN 6372797.0
58#endif
59#ifndef SUNMASS
60# define SUNMASS 1.98847E+30
61#endif
62#ifndef PLANK_H
63# define PLANK_H 6.62607015E-34
64#endif
65#ifndef DIRAC_H
66# define DIRAC_H (PLANK_H / (2 * M_PI))
67#endif
68#ifndef EINSTEIN_G
69# define EINSTEIN_G 6.67408E-11
70#endif
71#ifndef EULER
72# define EULER 2.71828182845904523536028747135266249775724709369995
73#endif
74#ifndef ROOT2
75# define ROOT2 1.41421356237309504880168872420969807856967187537694
76#endif
77#ifndef AIRY
78# define AIRY 1.21966
79#endif
80#ifndef ASTRONOMICALUNIT
81# define ASTRONOMICALUNIT 1.495978707E+11
82#endif
83#ifndef LIGHTSPEED
84# define LIGHTSPEED 299792458.0
85#endif
86
87// ============================================================
88// Angular / arc unit conversion macros
89// ============================================================
90#ifndef CIRCLE_DEG
91# define CIRCLE_DEG 360
92#endif
93#ifndef CIRCLE_AM
94# define CIRCLE_AM (CIRCLE_DEG * 60)
95#endif
96#ifndef CIRCLE_AS
97# define CIRCLE_AS (CIRCLE_AM * 60)
98#endif
99#ifndef RAD_AS
100# define RAD_AS (CIRCLE_AS / (M_PI * 2))
101#endif
102
103#ifndef HOURS_TO_DEG
104# define HOURS_TO_DEG(h) ((h) * 15.0)
105#endif
106#ifndef DEG_TO_HOURS
107# define DEG_TO_HOURS(d) ((d) / 15.0)
108#endif
109#ifndef ARCMIN_TO_DEG
110# define ARCMIN_TO_DEG(am) ((am) / 60.0)
111#endif
112#ifndef DEG_TO_ARCMIN
113# define DEG_TO_ARCMIN(d) ((d) * 60.0)
114#endif
115#ifndef ARCSEC_TO_DEG
116# define ARCSEC_TO_DEG(as) ((as) / 3600.0)
117#endif
118#ifndef DEG_TO_ARCSEC
119# define DEG_TO_ARCSEC(d) ((d) * 3600.0)
120#endif
121#ifndef HOURS_TO_RAD
122# define HOURS_TO_RAD(h) ((h) * M_PI / 12.0)
123#endif
124#ifndef RAD_TO_HOURS
125# define RAD_TO_HOURS(r) ((r) * 12.0 / M_PI)
126#endif
127#ifndef DEG_TO_RAD
128# define DEG_TO_RAD(d) ((d) * M_PI / 180.0)
129#endif
130#ifndef RAD_TO_DEG
131# define RAD_TO_DEG(r) ((r) * 180.0 / M_PI)
132#endif
133
134// ============================================================
135// Derived astronomical constants (depend on the above)
136// ============================================================
137#ifndef PARSEC
138# define PARSEC (ASTRONOMICALUNIT * RAD_AS)
139#endif
140#ifndef JULIAN_LY
141# define JULIAN_LY (LIGHTSPEED * SOLAR_DAY * 365)
142#endif
143#ifndef STELLAR_LY
144# define STELLAR_LY (LIGHTSPEED * STELLAR_DAY * 365)
145#endif
146
147// ============================================================
148// Photometry macros
149// ============================================================
150#ifndef FLUX
151# define FLUX(wavelength) ((wavelength) / (PLANK_H * LIGHTSPEED))
152#endif
153#ifndef CANDLE
154# define CANDLE ((1.0 / 683.0) * FLUX(555))
155#endif
156#ifndef LUMEN
157# define LUMEN(wavelength) (CANDLE / (4 * M_PI) * pow((FLUX(wavelength) / FLUX(555)), 0.25))
158#endif
159#ifndef REDSHIFT
160# define REDSHIFT(wavelength, reference) (1.0 - ((reference) / (wavelength)))
161#endif
162#ifndef DOPPLER
163# define DOPPLER(shift, speed) ((speed) * (shift))
164#endif
165
174#ifndef INDI_UNUSED
175# define INDI_UNUSED(x) (void)x
176#endif
177
182#ifdef _MSC_VER
183# include <BaseTsd.h>
184#ifndef HAVE_SSIZE_T
185typedef SSIZE_T ssize_t;
186#endif
187#else
188# include <unistd.h>
189#endif
190
194#ifndef INDI_HAS_CPP_ATTRIBUTE
195# ifdef __has_cpp_attribute
196# define INDI_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
197# else
198# define INDI_HAS_CPP_ATTRIBUTE(x) 0
199# endif
200#endif
201
205#ifndef INDI_HAS_ATTRIBUTE
206# ifdef __has_attribute
207# define INDI_HAS_ATTRIBUTE(x) __has_attribute(x)
208# else
209# define INDI_HAS_ATTRIBUTE(x) 0
210# endif
211#endif
212
234#ifndef INDI_FALLTHROUGH
235# if defined(__cplusplus)
236# if INDI_HAS_CPP_ATTRIBUTE(clang::fallthrough)
237# define INDI_FALLTHROUGH [[clang::fallthrough]]
238# elif INDI_HAS_CPP_ATTRIBUTE(gnu::fallthrough)
239# define INDI_FALLTHROUGH [[gnu::fallthrough]]
240# elif INDI_HAS_CPP_ATTRIBUTE(fallthrough)
241# define INDI_FALLTHROUGH [[fallthrough]]
242# endif
243# else
244# if INDI_HAS_ATTRIBUTE(fallthrough)
245# define INDI_FALLTHROUGH __attribute__((fallthrough))
246# else
247# define INDI_FALLTHROUGH do {} while (0)
248# endif
249# endif
250#endif
251
259#if defined(__cplusplus)
260
261#include <memory>
262
263template <typename T>
264static inline std::shared_ptr<T> make_shared_weak(T *object)
265{
266 return std::shared_ptr<T>(object, [](T*) {});
267}
268
269template <typename T>
270static inline T *getPtrHelper(T *ptr)
271{
272 return ptr;
273}
274
275template <typename Wrapper>
276static inline typename Wrapper::element_type *getPtrHelper(const Wrapper &p)
277{
278 return p.get();
279}
280
281#define DECLARE_PRIVATE(Class) \
282 inline Class##Private* d_func() { return reinterpret_cast<Class##Private *>(getPtrHelper(this->d_ptr)); } \
283 inline const Class##Private* d_func() const { return reinterpret_cast<const Class##Private *>(getPtrHelper(this->d_ptr)); } \
284 friend Class##Private;
285
286#define DECLARE_PRIVATE_D(Dptr, Class) \
287 inline Class##Private* d_func() { return reinterpret_cast<Class##Private *>(getPtrHelper(Dptr)); } \
288 inline const Class##Private* d_func() const { return reinterpret_cast<const Class##Private *>(getPtrHelper(Dptr)); } \
289 friend Class##Private;
290
291#define D_PTR(Class) Class##Private * const d = d_func()
292
293#endif
294
295// enable warnings for printf-style functions
296#ifndef ATTRIBUTE_FORMAT_PRINTF
297# if INDI_HAS_ATTRIBUTE(format)
298# define ATTRIBUTE_FORMAT_PRINTF(A, B) __attribute__((format(printf, (A), (B))))
299# else
300# define ATTRIBUTE_FORMAT_PRINTF(A, B)
301# endif
302#endif
303
304#ifdef SWIG
305# define INDI_DEPRECATED(message)
306#elif __cplusplus
307# define INDI_DEPRECATED(message) [[deprecated(message)]]
308#else
309# define INDI_DEPRECATED(message) __attribute__ ((deprecated))
310#endif