From 39ddb2ee0e1a12a869a476b5582f584bdab21ea0 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Tue, 24 Sep 2013 00:42:42 +0200 Subject: [PATCH] Moved GsweSignInfo to its own sources --- docs/reference/swe-glib/Makefile.am | 1 + docs/reference/swe-glib/swe-glib-docs.xml | 1 + docs/reference/swe-glib/swe-glib-sections.txt | 16 +- src/Makefile.am | 6 +- src/gswe-antiscion-axis-info.h | 1 + src/gswe-moment.c | 4 +- src/gswe-planet-data.h | 1 + src/gswe-sign-info-private.h | 47 ++++++ src/gswe-sign-info.c | 137 ++++++++++++++++++ src/gswe-sign-info.h | 48 ++++++ src/gswe-types.h | 16 -- src/swe-glib-private.h | 1 + src/swe-glib.c | 23 +-- src/swe-glib.h | 4 +- 14 files changed, 257 insertions(+), 49 deletions(-) create mode 100644 src/gswe-sign-info-private.h create mode 100644 src/gswe-sign-info.c create mode 100644 src/gswe-sign-info.h diff --git a/docs/reference/swe-glib/Makefile.am b/docs/reference/swe-glib/Makefile.am index fe5818e..703f53d 100644 --- a/docs/reference/swe-glib/Makefile.am +++ b/docs/reference/swe-glib/Makefile.am @@ -62,6 +62,7 @@ IGNORE_HFILES = \ swe-glib-private.h \ gswe-enumtypes.h \ gswe-moon-phase-data-private.h \ + gswe-sign-info-private.h \ gswe-planet-info-private.h \ gswe-planet-data-private.h \ gswe-aspect-info-private.h \ diff --git a/docs/reference/swe-glib/swe-glib-docs.xml b/docs/reference/swe-glib/swe-glib-docs.xml index 673bf8f..f5ecd6f 100644 --- a/docs/reference/swe-glib/swe-glib-docs.xml +++ b/docs/reference/swe-glib/swe-glib-docs.xml @@ -19,6 +19,7 @@ SWE-GLib + diff --git a/docs/reference/swe-glib/swe-glib-sections.txt b/docs/reference/swe-glib/swe-glib-sections.txt index d737f61..7983390 100644 --- a/docs/reference/swe-glib/swe-glib-sections.txt +++ b/docs/reference/swe-glib/swe-glib-sections.txt @@ -55,6 +55,18 @@ GSWE_TYPE_MOON_PHASE_DATA gswe_moon_phase_data_get_type +
+gswe-sign-info +GsweSignInfo +gswe_sign_info_get_element +gswe_sign_info_get_name +gswe_sign_info_get_quality +gswe_sign_info_get_sign + +GSWE_TYPE_SIGN_INFO +gswe_sign_info_get_type +
+
gswe-planet-info GswePlanetInfo @@ -189,7 +201,6 @@ GsweElement GsweQuality GsweHouseSystem GsweMoonPhase -GsweSignInfo GsweHouseSystemInfo GsweCoordinates GsweHouseData @@ -203,8 +214,5 @@ gswe_house_data_get_type
swe-glib gswe_init - -GSWE_TYPE_SIGN_INFO -gswe_sign_info_get_type
diff --git a/src/Makefile.am b/src/Makefile.am index c32c1fb..97408bc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -7,12 +7,13 @@ INST_H_SRC_FILES = \ swe-glib.h \ gswe-types.h \ gswe-moon-phase-data.h \ + gswe-sign-info.h \ + gswe-planet-info.h \ + gswe-planet-data.h \ gswe-aspect-info.h \ gswe-aspect-data.h \ gswe-antiscion-axis-info.h \ gswe-antiscion-data.h \ - gswe-planet-info.h \ - gswe-planet-data.h \ gswe-moment.h \ gswe-timestamp.h \ $(NULL) @@ -26,6 +27,7 @@ libswe_glib_1_0_la_SOURCES = \ swe-glib.c \ gswe-types.c \ gswe-moon-phase-data.c \ + gswe-sign-info.c \ gswe-planet-info.c \ gswe-planet-data.c \ gswe-aspect-info.c \ diff --git a/src/gswe-antiscion-axis-info.h b/src/gswe-antiscion-axis-info.h index 9bd5a80..547d71f 100644 --- a/src/gswe-antiscion-axis-info.h +++ b/src/gswe-antiscion-axis-info.h @@ -21,6 +21,7 @@ #include #include "gswe-types.h" +#include "gswe-sign-info.h" G_BEGIN_DECLS diff --git a/src/gswe-moment.c b/src/gswe-moment.c index d68bef0..b6c8ad8 100644 --- a/src/gswe-moment.c +++ b/src/gswe-moment.c @@ -759,7 +759,7 @@ gswe_moment_get_sign_planets(GsweMoment *moment, GsweZodiac sign) for (planet = moment->priv->planet_list; planet; planet = g_list_next(planet)) { GswePlanetData *pd = planet->data; - if (pd->sign->sign_id == sign) { + if (pd->sign->sign == sign) { ret = g_list_prepend(ret, pd); } } @@ -1188,7 +1188,7 @@ find_antiscion(gpointer axis_p, GsweAntiscionAxisInfo *antiscion_axis_info, Gswe } planet_orb = fmin(antiscion_data->planet1->planet_info->orb, antiscion_data->planet2->planet_info->orb); - start_point = (antiscion_axis_info->start_sign->sign_id - 1) * 30.0; + start_point = (antiscion_axis_info->start_sign->sign - 1) * 30.0; start_point += antiscion_axis_info->sign_offset; diff --git a/src/gswe-planet-data.h b/src/gswe-planet-data.h index 8c2137c..08a304b 100644 --- a/src/gswe-planet-data.h +++ b/src/gswe-planet-data.h @@ -22,6 +22,7 @@ #include "gswe-types.h" #include "gswe-planet-info.h" +#include "gswe-sign-info.h" G_BEGIN_DECLS diff --git a/src/gswe-sign-info-private.h b/src/gswe-sign-info-private.h new file mode 100644 index 0000000..e69083b --- /dev/null +++ b/src/gswe-sign-info-private.h @@ -0,0 +1,47 @@ +/* gswe-sign-info-private.h: Private parts of GsweSignInfo + * + * Copyright © 2013 Gergely Polonkai + * + * SWE-GLib is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * SWE-GLib is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this library; if not, see . + */ +#ifdef __SWE_GLIB_BUILDING__ +#ifndef __SWE_GLIB_GSWE_SIGN_INFO_PRIVATE_H__ +#define __SWE_GLIB_GSWE_SIGN_INFO_PRIVATE_H__ + +#include "gswe-types.h" + +#include "gswe-sign-info.h" + +struct _GsweSignInfo { + /* the identifier for this sign */ + GsweZodiac sign; + + /* the name of this sign */ + gchar *name; + + /* the element of the sign */ + GsweElement element; + + /* the quality of the sign */ + GsweQuality quality; +}; + +GsweSignInfo *gswe_sign_info_copy(GsweSignInfo *sign_info); +void gswe_sign_info_free(GsweSignInfo *sign_info); + +#endif /* __SWE_GLIB_GSWE_SIGN_INFO_PRIVATE_H__ */ +#else /* not defined __SWE_GLIB_BUILDING__ */ +#error __FILE__ "Can not be included, unless building SWE-GLib" +#endif /* __SWE_GLIB_BUILDING__ */ + diff --git a/src/gswe-sign-info.c b/src/gswe-sign-info.c new file mode 100644 index 0000000..07a57ac --- /dev/null +++ b/src/gswe-sign-info.c @@ -0,0 +1,137 @@ +/* gswe-sign-info.c: Zodiac sign related information + * + * Copyright © 2013 Gergely Polonkai + * + * SWE-GLib is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * SWE-GLib is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this library; if not, see . + */ +#include "gswe-types.h" + +#include "gswe-sign-info.h" +#include "gswe-sign-info-private.h" + +/** + * SECTION:gswe-sign-info + * @short_description: a structure storing information about a zodiac sign + * @title: GsweSignInfo + * @stability: Stable + * @include: swe-glib.h + * + * The #GsweSignInfo stores information about a zodiac sign. + */ + +G_DEFINE_BOXED_TYPE(GsweSignInfo, gswe_sign_info, (GBoxedCopyFunc)gswe_sign_info_copy, (GBoxedFreeFunc)gswe_sign_info_free); + +GsweSignInfo * +gswe_sign_info_copy(GsweSignInfo *sign_info) +{ + GsweSignInfo *ret; + + if (sign_info == NULL) { + return NULL; + } + + ret = g_new0(GsweSignInfo, 1); + + ret->sign = sign_info->sign; + ret->name = g_strdup(sign_info->name); + ret->element = sign_info->element; + ret->quality = sign_info->quality; + + return ret; +} + +void +gswe_sign_info_free(GsweSignInfo *sign_info) +{ + if (sign_info) { + if (sign_info->name) { + g_free(sign_info->name); + } + + g_free(sign_info); + } +} + +/** + * gswe_sign_info_get_sign: + * @sign_info: (in) (allow-none): a #GsweSignInfo + * + * Gets the sign ID that is represented by this #GsweSignInfo. + * + * Returns: the sign ID + */ +GsweZodiac +gswe_sign_info_get_sign(GsweSignInfo *sign_info) +{ + if (sign_info) { + return sign_info->sign; + } else { + return GSWE_SIGN_NONE; + } +} + +/** + * gswe_sign_info_get_name: + * @sign_info: (in) (allow-none): a #GsweSignInfo + * + * Gets the name associated with this sign. + * + * Returns: (transfer none): the name of the zodiac sign + */ +const gchar * +gswe_sign_info_get_name(GsweSignInfo *sign_info) +{ + if (sign_info) { + return sign_info->name; + } else { + return NULL; + } +} + +/** + * gswe_sign_info_get_element: + * @sign_info: (in) (allow-none): a #GsweSignInfo + * + * Gets the element this sign belongs to. + * + * Returns: the element + */ +GsweElement +gswe_sign_info_get_element(GsweSignInfo *sign_info) +{ + if (sign_info) { + return sign_info->element; + } else { + return GSWE_ELEMENT_NONE; + } +} + +/** + * gswe_sign_info_get_quality: + * @sign_info: (in) (allow-none): a #GsweSignInfo + * + * Gets the quality this sign belongs to. + * + * Returns: the quality + */ +GsweQuality +gswe_sign_info_get_quality(GsweSignInfo *sign_info) +{ + if (sign_info) { + return sign_info->quality; + } else { + return GSWE_QUALITY_NONE; + } +} + diff --git a/src/gswe-sign-info.h b/src/gswe-sign-info.h new file mode 100644 index 0000000..8a1f5f5 --- /dev/null +++ b/src/gswe-sign-info.h @@ -0,0 +1,48 @@ +/* gswe-sign-info.h: Zodiac sign related information + * + * Copyright © 2013 Gergely Polonkai + * + * SWE-GLib is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * SWE-GLib is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this library; if not, see . + */ +#ifndef __SWE_GLIB_GSWE_SIGN_INFO_H__ +#define __SWE_GLIB_GSWE_SIGN_INFO_H__ + +#include + +#include "gswe-types.h" + +G_BEGIN_DECLS + +/** + * GsweSignInfo: + * + * GsweSignInfo is an opaque structure whose members + * cannot be accessed directly. + * + * Since: 1.1 + */ +typedef struct _GsweSignInfo GsweSignInfo; + +GType gswe_sign_info_get_type(void); +#define GSWE_TYPE_SIGN_INFO (gswe_sign_info_get_type()) + +GsweZodiac gswe_sign_info_get_sign(GsweSignInfo *sign_info); +const gchar *gswe_sign_info_get_name(GsweSignInfo *sign_info); +GsweElement gswe_sign_info_get_element(GsweSignInfo *sign_info); +GsweQuality gswe_sign_info_get_quality(GsweSignInfo *sign_info); + +G_END_DECLS + +#endif /* __SWE_GLIB_GSWE_SIGN_INFO_H__ */ + diff --git a/src/gswe-types.h b/src/gswe-types.h index 515af7c..cf94d8b 100644 --- a/src/gswe-types.h +++ b/src/gswe-types.h @@ -249,22 +249,6 @@ typedef enum { GSWE_MOON_PHASE_DARK } GsweMoonPhase; -/** - * GsweSignInfo: - * @sign_id: the identifier for this sign - * @name: the name of this sign - * @element: the element of the sign - * @quality: the quality of the sign - * - * Holds information about zodiac signs known by SWE-GLib. - */ -typedef struct { - GsweZodiac sign_id; - gchar *name; - GsweElement element; - GsweQuality quality; -} GsweSignInfo; - /** * GsweHouseSystemInfo: * @system: the house system's ID diff --git a/src/swe-glib-private.h b/src/swe-glib-private.h index 3923f40..bd11548 100644 --- a/src/swe-glib-private.h +++ b/src/swe-glib-private.h @@ -20,6 +20,7 @@ #include "gswe-timestamp.h" #include "gswe-types.h" #include "gswe-moon-phase-data-private.h" +#include "gswe-sign-info-private.h" #include "gswe-planet-info-private.h" #include "gswe-planet-data-private.h" #include "gswe-aspect-info-private.h" diff --git a/src/swe-glib.c b/src/swe-glib.c index 3aed1a6..9905aab 100644 --- a/src/swe-glib.c +++ b/src/swe-glib.c @@ -55,7 +55,7 @@ GsweTimestamp *gswe_full_moon_base_date; #define ADD_SIGN(ht, v, s, n, e, q) \ (v) = g_new0(GsweSignInfo, 1); \ - (v)->sign_id = (s); \ + (v)->sign = (s); \ (v)->name = g_strdup(n); \ (v)->element = (e); \ (v)->quality = (q); \ @@ -217,24 +217,3 @@ gswe_init(void) gswe_initialized = TRUE; } -static GsweSignInfo * -gswe_sign_info_copy(GsweSignInfo *sign_info) -{ - GsweSignInfo *ret = g_new0(GsweSignInfo, 1); - - ret->sign_id = sign_info->sign_id; - ret->name = g_strdup(sign_info->name); - ret->element = sign_info->element; - ret->quality = sign_info->quality; - - return ret; -} - -static void -gswe_sign_info_free(GsweSignInfo *sign_info) -{ - g_free(sign_info->name); - g_free(sign_info); -} - -G_DEFINE_BOXED_TYPE(GsweSignInfo, gswe_sign_info, (GBoxedCopyFunc)gswe_sign_info_copy, (GBoxedFreeFunc)gswe_sign_info_free); diff --git a/src/swe-glib.h b/src/swe-glib.h index a4ef8f9..9a90d3f 100644 --- a/src/swe-glib.h +++ b/src/swe-glib.h @@ -21,6 +21,7 @@ #include #include "gswe-types.h" #include "gswe-moon-phase-data.h" +#include "gswe-sign-info.h" #include "gswe-planet-info.h" #include "gswe-planet-data.h" #include "gswe-aspect-info.h" @@ -33,8 +34,5 @@ void gswe_init(); -GType gswe_sign_info_get_type(void); -#define GSWE_TYPE_SIGN_INFO (gswe_sign_info_get_type()) - #endif /* __SWE_GLIB_H__ */