From 197f6922c78805b8081bd772eaecd32b7b2ab5a0 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Mon, 23 Sep 2013 00:03:10 +0200 Subject: [PATCH] Outsourced GsweMoonPhaseData to its own sources This messed up documentation, still checking why --- docs/reference/swe-glib/Makefile.am | 2 +- docs/reference/swe-glib/swe-glib-sections.txt | 12 ++ src/Makefile.am | 18 +-- src/gswe-moment.h | 2 + src/gswe-moon-phase-data-private.h | 39 ++++++ src/gswe-moon-phase-data.c | 113 ++++++++++++++++++ src/gswe-moon-phase-data.h | 48 ++++++++ src/gswe-types.c | 12 -- src/gswe-types.h | 15 --- src/swe-glib-private.h | 1 + 10 files changed, 226 insertions(+), 36 deletions(-) create mode 100644 src/gswe-moon-phase-data-private.h create mode 100644 src/gswe-moon-phase-data.c create mode 100644 src/gswe-moon-phase-data.h diff --git a/docs/reference/swe-glib/Makefile.am b/docs/reference/swe-glib/Makefile.am index c9cea52..02f9b64 100644 --- a/docs/reference/swe-glib/Makefile.am +++ b/docs/reference/swe-glib/Makefile.am @@ -58,7 +58,7 @@ EXTRA_HFILES= # Header files or dirs to ignore when scanning. Use base file/dir names # e.g. IGNORE_HFILES=gtkdebug.h gtkintl.h private_code -IGNORE_HFILES=swe-glib-private.h gswe-enumtypes.h +IGNORE_HFILES=swe-glib-private.h gswe-enumtypes.h gswe-moon-phase-data-private.h # Images to copy into HTML directory. # e.g. HTML_IMAGES=$(top_srcdir)/gtk/stock-icons/stock_about_24.png diff --git a/docs/reference/swe-glib/swe-glib-sections.txt b/docs/reference/swe-glib/swe-glib-sections.txt index 807c57c..ec1cedf 100644 --- a/docs/reference/swe-glib/swe-glib-sections.txt +++ b/docs/reference/swe-glib/swe-glib-sections.txt @@ -43,6 +43,18 @@ GsweMomentPrivate gswe_moment_get_type +
+gswe-moon-phase-data +gswe_moon_phase_data_set_phase +gswe_moon_phase_data_get_phase +gswe_moon_phase_data_set_illumination +gswe_moon_phase_data_get_illumination +GsweMoonPhaseData + +GSWE_TYPE_MOON_PHASE_DATA +gswe_moon_phase_data_get_type +
+
gswe-timestamp GsweTimestamp diff --git a/src/Makefile.am b/src/Makefile.am index 65c7ba7..e29af73 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -4,9 +4,10 @@ AM_CPPFLAGS = -DG_LOG_DOMAIN=\"SWE-GLib\" -DLOCALEDIR=\"$(localedir)\" -D__SWE_G lib_LTLIBRARIES = libswe-glib-1.0.la INST_H_SRC_FILES = \ - swe-glib.h \ - gswe-types.h \ - gswe-moment.h \ + swe-glib.h \ + gswe-types.h \ + gswe-moon-phase-data.h \ + gswe-moment.h \ gswe-timestamp.h INST_H_BUILT_FILES = \ @@ -15,11 +16,12 @@ INST_H_BUILT_FILES = \ gswe_enum_headers = gswe-timestamp.h gswe-types.h libswe_glib_1_0_la_SOURCES = \ - swe-glib.c \ - gswe-types.c \ - gswe-moment.c \ - gswe-timestamp.c \ - gswe-enumtypes.c \ + swe-glib.c \ + gswe-types.c \ + gswe-moon-phase-data.c \ + gswe-moment.c \ + gswe-timestamp.c \ + gswe-enumtypes.c \ $(NULL) libswe_glib_1_0_la_CFLAGS = $(GLIB_CFLAGS) $(GOBJECT_CFLAGS) -Wall libswe_glib_1_0_la_LIBADD = $(GLIB_LIBS) $(GOBJECT_LIBS) $(LIBSWE_LIBS) diff --git a/src/gswe-moment.h b/src/gswe-moment.h index 5360009..90d4e6e 100644 --- a/src/gswe-moment.h +++ b/src/gswe-moment.h @@ -21,6 +21,8 @@ #include #include "gswe-timestamp.h" +#include "gswe-moon-phase-data.h" +#include "gswe-types.h" #define GSWE_TYPE_MOMENT (gswe_moment_get_type()) #define GSWE_MOMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GSWE_TYPE_MOMENT, GsweMoment)) diff --git a/src/gswe-moon-phase-data-private.h b/src/gswe-moon-phase-data-private.h new file mode 100644 index 0000000..e60acf7 --- /dev/null +++ b/src/gswe-moon-phase-data-private.h @@ -0,0 +1,39 @@ +/* gswe-moon-phase-data-private.h: Private parts of GsweMoonPhaseData + * + * 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_MOON_PHASE_DATA_PRIVATE_H__ +#define __SWE_GLIB_GSWE_MOON_PHASE_DATA_PRIVATE_H__ + +#include "gswe-moon-phase-data.h" +#include "gswe-types.h" + +struct _GsweMoonPhaseData { + /* the actual phase of the Moon */ + GsweMoonPhase phase; + + /* the illumination percentage of the Moon */ + gdouble illumination; +}; + +GsweMoonPhaseData *gswe_moon_phase_data_copy(GsweMoonPhaseData *moon_phase_data); + +#endif /* __SWE_GLIB_GSWE_MOON_PHASE_DATA_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-moon-phase-data.c b/src/gswe-moon-phase-data.c new file mode 100644 index 0000000..b2e9b72 --- /dev/null +++ b/src/gswe-moon-phase-data.c @@ -0,0 +1,113 @@ +/* gswe-moon-phase-data.c: Moon phase representation + * + * 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-moon-phase-data.h" +#include "gswe-moon-phase-data-private.h" + +/** + * SECTION:gswe-moon-phase-data + * @short_description: a structure representing the phase of the Moon + * @title: GsweMoonPhaseData + * @stability: Stable + * @include: swe-glib/swe-glib.h + * @see_also: #GsweMoonPhase + * + * #GsweMoonPhaseData is a structure that represents the actual phase of the + * Moon, including its illumination percentage. + */ + +G_DEFINE_BOXED_TYPE(GsweMoonPhaseData, gswe_moon_phase_data, (GBoxedCopyFunc)gswe_moon_phase_data_copy, (GBoxedFreeFunc)g_free); + +GsweMoonPhaseData * +gswe_moon_phase_data_copy(GsweMoonPhaseData *moon_phase_data) +{ + GsweMoonPhaseData *ret = g_new0(struct _GsweMoonPhaseData, 1); + + ret->phase = moon_phase_data->phase; + ret->illumination = moon_phase_data->illumination; + + return ret; +} + +/** + * gswe_moon_phase_data_set_phase: + * @moon_phase_data: a GsweMoonPhaseData + * @phase: the phase to set + * + * Sets the phase of the Moon in the given GsweMoonPhaseData. + */ +void +gswe_moon_phase_data_set_phase(GsweMoonPhaseData *moon_phase_data, GsweMoonPhase phase) +{ + if (moon_phase_data) { + moon_phase_data->phase = phase; + } +} + +/** + * gswe_moon_phase_data_get_phase: + * @moon_phase_data: a GsweMoonPhaseData + * + * Gets the phase of the Moon in the given GsweMoonPhaseData. + * + * Returns: the Moon phase + */ +GsweMoonPhase +gswe_moon_phase_data_get_phase(GsweMoonPhaseData *moon_phase_data) +{ + if (moon_phase_data) { + return moon_phase_data->phase; + } else { + return GSWE_MOON_PHASE_NONE; + } +} + +/** + * gswe_moon_phase_data_set_illumination: + * @moon_phase_data: a GsweMoonPhaseData + * @illumination: the illumination to set + * + * Sets the illumination percentage in the given GsweMoonPhaseData. + */ +void +gswe_moon_phase_data_set_illumination(GsweMoonPhaseData *moon_phase_data, gdouble illumination) +{ + if (moon_phase_data) { + moon_phase_data->illumination = illumination; + } +} + +/** + * gswe_moon_phase_data_get_illumination: + * @moon_phase_data: a GsweMoonPhaseData + * + * Gets the illumination percentage from the given GsweMoonPhaseData. + * + * Returns: the illumination percentage + */ +gdouble +gswe_moon_phase_data_get_illumination(GsweMoonPhaseData *moon_phase_data) +{ + if (moon_phase_data) { + return moon_phase_data->illumination; + } else { + return 0.0; + } +} + diff --git a/src/gswe-moon-phase-data.h b/src/gswe-moon-phase-data.h new file mode 100644 index 0000000..ddff08b --- /dev/null +++ b/src/gswe-moon-phase-data.h @@ -0,0 +1,48 @@ +/* gswe-moon-phase-data.h: Moon phase representation + * + * 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_MOON_PHASE_DATA_H__ +#define __SWE_GLIB_GSWE_MOON_PHASE_DATA_H__ + +#include + +#include "gswe-types.h" + +G_BEGIN_DECLS + +/** + * GsweMoonPhaseData: + * + * GsweMoonPhaseData is an opaque structure whose members + * cannot be accessed directly. + * + * Since: 1.1 + */ +typedef struct _GsweMoonPhaseData GsweMoonPhaseData; + +void gswe_moon_phase_data_set_phase(GsweMoonPhaseData *moon_phase_data, GsweMoonPhase phase); +GsweMoonPhase gswe_moon_phase_data_get_phase(GsweMoonPhaseData *moon_phase_data); +void gswe_moon_phase_data_set_illumination(GsweMoonPhaseData *moon_phase_data, gdouble illumination); +gdouble gswe_moon_phase_data_get_illumination(GsweMoonPhaseData *moon_phase_data); + +GType gswe_moon_phase_data_get_type(void); +#define GSWE_TYPE_MOON_PHASE_DATA (gswe_moon_phase_data_get_type()) + +G_END_DECLS + +#endif /* __SWE_GLIB_GSWE_MOON_PHASE_DATA_H__ */ + diff --git a/src/gswe-types.c b/src/gswe-types.c index 6c23d8e..9fe62f8 100644 --- a/src/gswe-types.c +++ b/src/gswe-types.c @@ -17,18 +17,6 @@ */ #include "gswe-types.h" -static GsweMoonPhaseData * -gswe_moon_phase_data_copy(GsweMoonPhaseData *moon_phase_data) -{ - GsweMoonPhaseData *ret = g_new0(GsweMoonPhaseData, 1); - - ret->phase = moon_phase_data->phase; - ret->illumination = moon_phase_data->illumination; - - return ret; -} - -G_DEFINE_BOXED_TYPE(GsweMoonPhaseData, gswe_moon_phase_data, (GBoxedCopyFunc)gswe_moon_phase_data_copy, (GBoxedFreeFunc)g_free); static GswePlanetData * gswe_planet_data_copy(GswePlanetData *planet_data) diff --git a/src/gswe-types.h b/src/gswe-types.h index 129dbd0..3add4cb 100644 --- a/src/gswe-types.h +++ b/src/gswe-types.h @@ -353,21 +353,6 @@ typedef struct { gboolean middle_axis; } GsweAntiscionAxisInfo; -/** - * GsweMoonPhaseData: - * @phase: the current phase of the Moon - * @illumination: the portion of the Moon that is currently illuminated - * - * Holds information of a Moon phase. - */ -typedef struct { - GsweMoonPhase phase; - gdouble illumination; -} GsweMoonPhaseData; - -GType gswe_moon_phase_data_get_type(void); -#define GSWE_TYPE_MOON_PHASE_DATA (gswe_moon_phase_data_get_type()) - /** * GswePlanetData: * @planet_id: A GswePlanet, the identifier of the planet diff --git a/src/swe-glib-private.h b/src/swe-glib-private.h index d6f966e..d5bd40b 100644 --- a/src/swe-glib-private.h +++ b/src/swe-glib-private.h @@ -19,6 +19,7 @@ #include "gswe-timestamp.h" #include "gswe-types.h" +#include "gswe-moon-phase-data-private.h" extern gchar *gswe_ephe_path; extern GsweTimestamp *gswe_full_moon_base_date;