diff --git a/docs/reference/swe-glib/swe-glib-sections.txt b/docs/reference/swe-glib/swe-glib-sections.txt index b475ba6..8be021c 100644 --- a/docs/reference/swe-glib/swe-glib-sections.txt +++ b/docs/reference/swe-glib/swe-glib-sections.txt @@ -60,6 +60,7 @@ gswe_moon_phase_data_get_type
gswe-sign-info GsweSignInfo +gswe_find_sign_info_by_id gswe_sign_info_new gswe_sign_info_ref gswe_sign_info_unref @@ -79,6 +80,7 @@ gswe_sign_info_get_type
gswe-planet-info GswePlanetInfo +gswe_find_planet_info_by_id gswe_planet_info_new gswe_planet_info_ref gswe_planet_info_unref @@ -122,6 +124,7 @@ gswe_planet_data_get_type
gswe-aspect-info GsweAspectInfo +gswe_find_aspect_info_by_id gswe_aspect_info_new gswe_aspect_info_ref gswe_aspect_info_unref @@ -165,6 +168,7 @@ gswe_aspect_data_get_type
gswe-antiscion-axis-info GsweAntiscionAxisInfo +gswe_find_antiscion_axis_info_by_id gswe_antiscion_axis_info_new gswe_antiscion_axis_info_ref gswe_antiscion_axis_info_unref @@ -206,6 +210,7 @@ gswe_antiscion_data_get_type
gswe-house-system-info GsweHouseSystemInfo +gswe_find_house_system_info_by_id gswe_house_system_info_new gswe_house_system_info_ref gswe_house_system_info_unref diff --git a/src/swe-glib.c b/src/swe-glib.c index d704d58..964278a 100644 --- a/src/swe-glib.c +++ b/src/swe-glib.c @@ -241,3 +241,98 @@ gswe_init(void) gswe_init_with_dir(PKGDATADIR); } +/** + * gswe_find_planet_info_by_id: + * @planet: a planet ID registered with SWE-GLib + * @err: a GError + * + * Find the #GswePlanetInfo record registered with the id @planet. + */ +GswePlanetInfo * +gswe_find_planet_info_by_id(GswePlanet planet, GError **err) +{ + GswePlanetInfo *ret = g_hash_table_lookup(gswe_planet_info_table, GINT_TO_POINTER(planet)); + + if (ret == NULL) { + g_set_error(err, GSWE_ERROR, GSWE_ERROR_UNKNOWN_PLANET, "Planet %d is not registered", planet); + } + + return ret; +} + +/** + * gswe_find_sign_info_by_id: + * @sign: a sign ID registered with SWE-GLib + * @err: a GError + * + * Find the #GsweSignInfo record registered with the id @sign. + */ +GsweSignInfo * +gswe_find_sign_info_by_id(GsweZodiac sign, GError **err) +{ + GsweSignInfo *ret = g_hash_table_lookup(gswe_sign_info_table, GINT_TO_POINTER(sign)); + + if (ret == NULL) { + g_set_error(err, GSWE_ERROR, GSWE_ERROR_UNKNOWN_SIGN, "Sign %d is not registered", sign); + } + + return ret; +} + +/** + * gswe_find_house_system_info_by_id: + * @house_system: a house system ID registered with SWE-GLib + * @err: a GError + * + * Find the #GsweHouseSystemInfo record registered with the id @house_system. + */ +GsweHouseSystemInfo * +gswe_find_house_system_info_by_id(GsweHouseSystem house_system, GError **err) +{ + GsweHouseSystemInfo *ret = g_hash_table_lookup(gswe_house_system_info_table, GINT_TO_POINTER(house_system)); + + if (ret == NULL) { + g_set_error(err, GSWE_ERROR, GSWE_ERROR_UNKNOWN_HSYS, "House system %d is not registered", house_system); + } + + return ret; +} + +/** + * gswe_find_aspect_info_by_id: + * @aspect: an aspect ID registered with SWE-GLib + * @err: a GError + * + * Find the #GsweAspectInfo record registered with the id @aspect. + */ +GsweAspectInfo * +gswe_find_aspect_info_by_id(GsweAspect aspect, GError **err) +{ + GsweAspectInfo *ret = g_hash_table_lookup(gswe_aspect_info_table, GINT_TO_POINTER(aspect)); + + if (ret == NULL) { + g_set_error(err, GSWE_ERROR, GSWE_ERROR_UNKNOWN_ASPECT, "Aspect system %d is not registered", aspect); + } + + return ret; +} + +/** + * gswe_find_antiscion_axis_info_by_id: + * @antiscion_axis: an antiscion axis ID registered with SWE-GLib + * @err: a GError + * + * Find the #GsweAntiscionAxisInfo record registered with the id @antiscion_axis. + */ +GsweAntiscionAxisInfo * +gswe_find_antiscion_axis_info_by_id(GsweAntiscionAxis antiscion_axis, GError **err) +{ + GsweAntiscionAxisInfo *ret = g_hash_table_lookup(gswe_antiscion_axis_info_table, GINT_TO_POINTER(antiscion_axis)); + + if (ret == NULL) { + g_set_error(err, GSWE_ERROR, GSWE_ERROR_UNKNOWN_ANTISCION_AXIS, "Antiscion axis system %d is not registered", antiscion_axis); + } + + return ret; +} + diff --git a/src/swe-glib.h b/src/swe-glib.h index 318e5e5..adf1257 100644 --- a/src/swe-glib.h +++ b/src/swe-glib.h @@ -47,6 +47,7 @@ * @GSWE_ERROR_UNKNOWN_PLANET: the referenced planet was not added with * gswe_moment_add_planet() * @GSWE_ERROR_UNKNOWN_ANTISCION_AXIS: the given axis is unknown to SWE-GLib + * @GSWE_ERROR_UNKNOWN_ASPECT: the given aspect is unknown to SWE-GLib * * Error codes returned by the SWE-GLib functions. */ @@ -61,6 +62,7 @@ typedef enum { GSWE_ERROR_UNKNOWN_SIGN, GSWE_ERROR_UNKNOWN_PLANET, GSWE_ERROR_UNKNOWN_ANTISCION_AXIS, + GSWE_ERROR_UNKNOWN_ASPECT, } GsweError; /** @@ -74,6 +76,11 @@ typedef enum { GQuark gswe_error_quark(void); void gswe_init(); +GswePlanetInfo *gswe_find_planet_info_by_id(GswePlanet planet, GError **err); +GsweSignInfo *gswe_find_sign_info_by_id(GsweZodiac sign, GError **err); +GsweHouseSystemInfo *gswe_find_house_system_info_by_id(GsweHouseSystem house_system, GError **err); +GsweAspectInfo *gswe_find_aspect_info_by_id(GsweAspect aspect, GError **err); +GsweAntiscionAxisInfo *gswe_find_antiscion_axis_info_by_id(GsweAntiscionAxis antiscion_axis, GError **err); #endif /* __SWE_GLIB_H__ */