The SSH host key has changed on 8 April, 2022 to this one: SHA256:573uTBSeh74kvOo0HJXi5ijdzRm8me27suzNEDlGyrQ

Made GsweHouseData a refcounted boxed type

This is to satisfy #7
pull/16/head
Gergely Polonkai 9 years ago
parent 6d88993fa3
commit 0b15005e3a
  1. 6
      docs/reference/swe-glib/swe-glib-sections.txt
  2. 7
      src/gswe-house-data-private.h
  3. 104
      src/gswe-house-data.c
  4. 8
      src/gswe-house-data.h
  5. 8
      src/gswe-moment.c

@ -216,9 +216,13 @@ gswe_house_system_info_get_type
<SECTION>
<FILE>gswe-house-data</FILE>
GsweHouseData
gswe_house_data_get_cusp_position
gswe_house_data_new
gswe_house_data_ref
gswe_house_data_unref
gswe_house_data_get_house
gswe_house_data_get_cusp_position
gswe_house_data_get_sign
gswe_house_data_get_sign_info
<SUBSECTION Standard>
GSWE_TYPE_HOUSE_DATA
gswe_house_data_get_type

@ -29,10 +29,11 @@ struct _GsweHouseData {
gdouble cusp_position;
/* the #GsweSignInfo structure associated with the sign in which the house cusp is in */
GsweSignInfo *sign;
};
GsweSignInfo *sign_info;
GsweHouseData *gswe_house_data_copy(GsweHouseData *house_data);
/* reference count */
guint refcount;
};
#endif /* __SWE_GLIB_GSWE_HOUSE_DATA_PRIVATE_H__ */
#else /* not defined __SWE_GLIB_BUILDING__ */

@ -17,6 +17,8 @@
*/
#include "gswe-types.h"
#include "swe-glib-private.h"
#include "swe-glib.h"
#include "gswe-house-data.h"
#include "gswe-house-data-private.h"
@ -31,23 +33,69 @@
* #GsweHouseData is a structure that represents a house's position.
*/
G_DEFINE_BOXED_TYPE(GsweHouseData, gswe_house_data, (GBoxedCopyFunc)gswe_house_data_copy, (GBoxedFreeFunc)g_free);
G_DEFINE_BOXED_TYPE(GsweHouseData, gswe_house_data, (GBoxedCopyFunc)gswe_house_data_ref, (GBoxedFreeFunc)gswe_house_data_unref);
static void
gswe_house_data_free(GsweHouseData *house_data)
{
if (house_data->sign_info) {
gswe_sign_info_unref(house_data->sign_info);
}
g_free(house_data);
}
/**
* gswe_house_data_new:
*
* Creates a new #GsweHouseData with reference count set to 1.
*
* Returns: (transfer full): a new #GsweHouseData
*/
GsweHouseData *
gswe_house_data_copy(GsweHouseData *house_data)
gswe_house_data_new(void)
{
GsweHouseData *ret = g_new0(GsweHouseData, 1);
GsweHouseData *ret;
ret->house = house_data->house;
ret->cusp_position = house_data->cusp_position;
ret->sign = house_data->sign;
ret = g_new0(GsweHouseData, 1);
ret->refcount = 1;
return ret;
}
/**
* gswe_house_data_ref:
* @house_data: a #GsweHouseData
*
* Increases reference count on @house_data by one.
*
* Returns: (transfer none): the same #GsweHouseData
*/
GsweHouseData *
gswe_house_data_ref(GsweHouseData *house_data)
{
house_data->refcount++;
return house_data;
}
/**
* gswe_house_data_unref:
* @house_data: a #GsweHouseData
*
* Decreases reference count on @house_data by one. If reference count drops to zero, @house_data is freed.
*/
void
gswe_house_data_unref(GsweHouseData *house_data)
{
if (--house_data->refcount == 0) {
gswe_house_data_free(house_data);
}
}
/**
* gswe_house_data_get_house:
* @house_data: (in) (allow-none): a #GsweHouseData
* @house_data: (in): a #GsweHouseData
*
* Gets the number of the house.
*
@ -56,16 +104,12 @@ gswe_house_data_copy(GsweHouseData *house_data)
guint
gswe_house_data_get_house(GsweHouseData *house_data)
{
if (house_data) {
return house_data->house;
} else {
return 0;
}
return house_data->house;
}
/**
* gswe_house_data_get_cusp_position:
* @house_data: (in) (allow-none): a #GsweHouseData
* @house_data: (in): a #GsweHouseData
*
* Gets the position of the house's cusp.
*
@ -74,28 +118,38 @@ gswe_house_data_get_house(GsweHouseData *house_data)
gdouble
gswe_house_data_get_cusp_position(GsweHouseData *house_data)
{
if (house_data) {
return house_data->cusp_position;
} else {
return 0.0;
}
return house_data->cusp_position;
}
/**
* gswe_house_data_get_sign:
* @house_data: (in) (allow-none): a #GsweHouseData
* @house_data: a #GsweHouseData
*
* Gets the sign in which the house's cusp is.
* Gets the sign which the house's cusp is in.
*
* Returns: (transfer none): a #GsweSignInfo representing the sign
* Returns: the GsweZodiac of the house cusp's sign
*/
GsweSignInfo *
GsweZodiac
gswe_house_data_get_sign(GsweHouseData *house_data)
{
if (house_data) {
return house_data->sign;
if (house_data->sign_info) {
return house_data->sign_info->sign;
} else {
return NULL;
return GSWE_SIGN_NONE;
}
}
/**
* gswe_house_data_get_sign_info:
* @house_data: (in): a #GsweHouseData
*
* Gets the #GsweSignInfo that represents the sign which the house's cusp is in.
*
* Returns: (transfer none): a #GsweSignInfo representing the sign
*/
GsweSignInfo *
gswe_house_data_get_sign_info(GsweHouseData *house_data)
{
return house_data->sign_info;
}

@ -37,9 +37,15 @@ typedef struct _GsweHouseData GsweHouseData;
GType gswe_house_data_get_type(void);
#define GSWE_TYPE_HOUSE_DATA (gswe_house_data_get_type())
GsweHouseData *gswe_house_data_new(void);
GsweHouseData *gswe_house_data_ref(GsweHouseData *house_data);
void gswe_house_data_unref(GsweHouseData *house_data);
guint gswe_house_data_get_house(GsweHouseData *house_data);
gdouble gswe_house_data_get_cusp_position(GsweHouseData *house_data);
GsweSignInfo *gswe_house_data_get_sign(GsweHouseData *house_data);
GsweZodiac gswe_house_data_get_sign(GsweHouseData *house_data);
GsweSignInfo *gswe_house_data_get_sign_info(GsweHouseData *house_data);
G_END_DECLS

@ -201,7 +201,7 @@ gswe_moment_finalize(GObject *gobject)
{
GsweMoment *moment = GSWE_MOMENT(gobject);
g_list_free_full(moment->priv->house_list, g_free);
g_list_free_full(moment->priv->house_list, (GDestroyNotify)gswe_house_data_unref);
g_list_free_full(moment->priv->planet_list, (GDestroyNotify)gswe_planet_data_unref);
g_list_free_full(moment->priv->aspect_list, (GDestroyNotify)gswe_aspect_data_unref);
g_list_free_full(moment->priv->antiscia_list, (GDestroyNotify)gswe_antiscion_data_unref);
@ -502,7 +502,7 @@ gswe_moment_calculate_house_positions(GsweMoment *moment, GError **err)
return;
}
g_list_free_full(moment->priv->house_list, g_free);
g_list_free_full(moment->priv->house_list, (GDestroyNotify)gswe_house_data_unref);
moment->priv->house_list = NULL;
// If no house system is set, we need no calculations at all. Just leave
@ -535,13 +535,13 @@ gswe_moment_calculate_house_positions(GsweMoment *moment, GError **err)
* this should not cause trouble yet, though) */
for (i = 12; i >= 1; i--) {
GsweSignInfo *sign_info;
GsweHouseData *house_data = g_new0(GsweHouseData, 1);
GsweHouseData *house_data = gswe_house_data_new();
house_data->house = i;
house_data->cusp_position = cusps[i];
if ((sign_info = g_hash_table_lookup(gswe_sign_info_table, GINT_TO_POINTER((gint)ceilf(cusps[i] / 30.0)))) == NULL) {
g_list_free_full(moment->priv->house_list, g_free);
g_list_free_full(moment->priv->house_list, (GDestroyNotify)gswe_house_data_unref);
moment->priv->house_list = NULL;
moment->priv->house_revision = 0;
g_set_error(err, GSWE_ERROR, GSWE_ERROR_UNKNOWN_SIGN, "Calculation brought an unknown sign");

Loading…
Cancel
Save