From bc7a755c193dc48671f7c97d3f17e48a94fca958 Mon Sep 17 00:00:00 2001 From: Nicola Fontana Date: Fri, 29 Jan 2010 16:33:18 +0100 Subject: [PATCH] [AdgPoint] Renamed APIs to fulfill guidelines The following APIs have been renamed: adg_point_set => adg_point_set_pair adg_point_set_explicit => adg_point_set_pair_explicit adg_point_set_from_model => adg_point_set_pair_from_model adg_point_pair => adg_point_get_pair Also, the functions have been reordered in the usual way (setter before getter). --- adg/adg-adim.c | 16 ++++---- adg/adg-dim.c | 18 ++++---- adg/adg-point.c | 125 ++++++++++++++++++++++++++++++-------------------------- adg/adg-point.h | 34 +++++++-------- 4 files changed, 100 insertions(+), 93 deletions(-) diff --git a/adg/adg-adim.c b/adg/adg-adim.c index f04a1c0b..ffd99e02 100644 --- a/adg/adg-adim.c +++ b/adg/adg-adim.c @@ -385,7 +385,7 @@ adg_adim_set_org(AdgADim *adim, const AdgPair *org1, const AdgPair *org2) if (data->org1 == NULL) data->org1 = adg_point_new(); - adg_point_set(data->org1, org1); + adg_point_set_pair(data->org1, org1); g_object_notify(object, "org1"); } @@ -394,7 +394,7 @@ adg_adim_set_org(AdgADim *adim, const AdgPair *org1, const AdgPair *org2) if (data->org2 == NULL) data->org2 = adg_point_new(); - adg_point_set(data->org2, org2); + adg_point_set_pair(data->org2, org2); g_object_notify(object, "org2"); } @@ -470,7 +470,7 @@ adg_adim_set_org_from_model(AdgADim *adim, AdgModel *model, if (data->org1 == NULL) data->org1 = adg_point_new(); - adg_point_set_from_model(data->org1, model, org1); + adg_point_set_pair_from_model(data->org1, model, org1); g_object_notify(object, "org1"); } @@ -479,7 +479,7 @@ adg_adim_set_org_from_model(AdgADim *adim, AdgModel *model, if (data->org2 == NULL) data->org2 = adg_point_new(); - adg_point_set_from_model(data->org2, model, org2); + adg_point_set_pair_from_model(data->org2, model, org2); g_object_notify(object, "org2"); } @@ -505,7 +505,7 @@ adg_adim_get_org1(AdgADim *adim) data = adim->data; - return adg_point_pair(data->org1); + return adg_point_get_pair(data->org1); } /** @@ -526,7 +526,7 @@ adg_adim_get_org2(AdgADim *adim) data = adim->data; - return adg_point_pair(data->org2); + return adg_point_get_pair(data->org2); } @@ -850,8 +850,8 @@ get_info(AdgADim *adim, CpmlVector vector[], ref1 = adg_dim_get_ref1(dim); ref2 = adg_dim_get_ref2(dim); - cpml_pair_sub(cpml_pair_copy(&vector[0], ref1), adg_point_pair(data->org1)); - cpml_pair_sub(cpml_pair_copy(&vector[2], ref2), adg_point_pair(data->org2)); + cpml_pair_sub(cpml_pair_copy(&vector[0], ref1), adg_point_get_pair(data->org1)); + cpml_pair_sub(cpml_pair_copy(&vector[2], ref2), adg_point_get_pair(data->org2)); factor = vector[0].x * vector[2].y - vector[0].y * vector[2].x; if (factor == 0) diff --git a/adg/adg-dim.c b/adg/adg-dim.c index da2320cc..283876c2 100644 --- a/adg/adg-dim.c +++ b/adg/adg-dim.c @@ -411,7 +411,7 @@ adg_dim_set_ref(AdgDim *dim, const AdgPair *ref1, const AdgPair *ref2) if (data->ref1 == NULL) data->ref1 = adg_point_new(); - adg_point_set(data->ref1, ref1); + adg_point_set_pair(data->ref1, ref1); g_object_notify(object, "ref1"); } @@ -420,7 +420,7 @@ adg_dim_set_ref(AdgDim *dim, const AdgPair *ref1, const AdgPair *ref2) if (data->ref2 == NULL) data->ref2 = adg_point_new(); - adg_point_set(data->ref2, ref2); + adg_point_set_pair(data->ref2, ref2); g_object_notify(object, "ref2"); } @@ -496,7 +496,7 @@ adg_dim_set_ref_from_model(AdgDim *dim, AdgModel *model, if (data->ref1 == NULL) data->ref1 = adg_point_new(); - adg_point_set_from_model(data->ref1, model, ref1); + adg_point_set_pair_from_model(data->ref1, model, ref1); g_object_notify(object, "ref1"); } @@ -505,7 +505,7 @@ adg_dim_set_ref_from_model(AdgDim *dim, AdgModel *model, if (data->ref2 == NULL) data->ref2 = adg_point_new(); - adg_point_set_from_model(data->ref2, model, ref2); + adg_point_set_pair_from_model(data->ref2, model, ref2); g_object_notify(object, "ref2"); } @@ -531,7 +531,7 @@ adg_dim_get_ref1(AdgDim *dim) data = dim->data; - return adg_point_pair(data->ref1); + return adg_point_get_pair(data->ref1); } /** @@ -552,7 +552,7 @@ adg_dim_get_ref2(AdgDim *dim) data = dim->data; - return adg_point_pair(data->ref2); + return adg_point_get_pair(data->ref2); } /** @@ -575,7 +575,7 @@ adg_dim_set_pos(AdgDim *dim, const AdgPair *pos) if (data->pos == NULL) data->pos = adg_point_new(); - adg_point_set(data->pos, pos); + adg_point_set_pair(data->pos, pos); g_object_notify((GObject *) dim, "pos"); } @@ -622,7 +622,7 @@ adg_dim_set_pos_from_model(AdgDim *dim, AdgModel *model, const gchar *pos) if (data->pos == NULL) data->pos = adg_point_new(); - adg_point_set_from_model(data->pos, model, pos); + adg_point_set_pair_from_model(data->pos, model, pos); g_object_notify((GObject *) dim, "pos"); } @@ -645,7 +645,7 @@ adg_dim_get_pos(AdgDim *dim) data = dim->data; - return adg_point_pair(data->pos); + return adg_point_get_pair(data->pos); } /** diff --git a/adg/adg-point.c b/adg/adg-point.c index 8a4efaf8..5ed147d8 100644 --- a/adg/adg-point.c +++ b/adg/adg-point.c @@ -25,12 +25,12 @@ * @short_description: A struct holding x, y coordinates * (either named or explicit) * - * AdgPoint is an opaque structure that manages 2D coordinates, either - * set explicitely throught adg_point_set() and adg_point_set_explicit() - * or taken from a model with adg_point_set_from_model(). It can be - * thought as an #AdgPair on steroid, because it adds named pair - * support to a simple pair, thus enabling coordinates depending - * on #AdgModel instances. + * AdgPoint is an opaque structure that manages 2D coordinates, + * either set explicitely throught adg_point_set_pair() and + * adg_point_set_pair_explicit() or taken from a model with + * adg_point_set_pair_from_model(). It can be thought as an + * #AdgPair on steroid, because it adds named pair support to + * a simple pair, enabling coordinates depending on #AdgModel. **/ /** @@ -75,7 +75,7 @@ adg_point_get_type(void) * reference to the old model is dropped. Similary, if @src is linked * to a model, a new reference to this new model is added. * - * Returns: @point + * Returns: @point or %NULL on error **/ AdgPoint * adg_point_copy(AdgPoint *point, const AdgPoint *src) @@ -99,6 +99,9 @@ adg_point_copy(AdgPoint *point, const AdgPoint *src) * Duplicates @point. This operation also adds a new reference * to the internal model if @point is linked to a named pair. * + * The returned value should be freed with adg_point_destroy() + * when no longer needed. + * * Returns: the duplicated #AdgPoint struct or %NULL on errors **/ AdgPoint * @@ -118,6 +121,9 @@ adg_point_dup(const AdgPoint *point) * Creates a new empty #AdgPoint. The returned pointer * should be freed with adg_point_destroy() when no longer needed. * + * The returned value should be freed with adg_point_destroy() + * when no longer needed. + * * Returns: a newly created #AdgPoint **/ AdgPoint * @@ -138,55 +144,13 @@ adg_point_destroy(AdgPoint *point) { g_return_if_fail(point != NULL); - adg_point_set_from_model(point, NULL, NULL); + adg_point_set_pair_from_model(point, NULL, NULL); g_free(point); } /** - * adg_point_pair: - * @point: an #AdgPoint - * - * #AdgPoint is an evolution of the pair concept, but internally the - * relevant data is still stored in an #AdgPair struct. This function - * gets this struct, optionally updating the internal value from the - * linked named pair if necessary. - * - * Returns: the pair of @point - **/ -const AdgPair * -adg_point_pair(AdgPoint *point) -{ - g_return_val_if_fail(point != NULL, NULL); - - if (!point->is_uptodate) { - const AdgPair *pair; - - if (point->model == NULL) { - /* A point with explicit coordinates not up to date - * is an unexpected condition */ - g_warning(_("%s: trying to get a pair from an undefined point"), - G_STRLOC); - return NULL; - } - - pair = adg_model_get_named_pair(point->model, point->name); - - if (pair == NULL) { - g_warning(_("%s: `%s' named pair not found in `%s' model instance"), - G_STRLOC, point->name, - g_type_name(G_TYPE_FROM_INSTANCE(point->model))); - return NULL; - } - - cpml_pair_copy(&point->pair, pair); - } - - return (AdgPair *) point; -} - -/** - * adg_point_set: + * adg_point_set_pair: * @point: an #AdgPoint * @pair: the #AdgPair to use * @@ -195,30 +159,30 @@ adg_point_pair(AdgPoint *point) * dropped before setting the pair. **/ void -adg_point_set(AdgPoint *point, const AdgPair *pair) +adg_point_set_pair(AdgPoint *point, const AdgPair *pair) { g_return_if_fail(point != NULL); g_return_if_fail(pair != NULL); - adg_point_set_explicit(point, pair->x, pair->y); + adg_point_set_pair_explicit(point, pair->x, pair->y); } /** - * adg_point_set_explicit: + * adg_point_set_pair_explicit: * @point: an #AdgPoint * @x: the x coordinate of the point * @y: the y coordinate of the point * - * Works in the same way of adg_point_set() but accept direct numbers + * Works in the same way of adg_point_set_pair() but accept direct numbers * instead of an #AdgPair structure. **/ void -adg_point_set_explicit(AdgPoint *point, gdouble x, gdouble y) +adg_point_set_pair_explicit(AdgPoint *point, gdouble x, gdouble y) { g_return_if_fail(point != NULL); /* Unlink the named pair dependency, if any */ - adg_point_set_from_model(point, NULL, NULL); + adg_point_set_pair_from_model(point, NULL, NULL); point->pair.x = x; point->pair.y = y; @@ -226,7 +190,7 @@ adg_point_set_explicit(AdgPoint *point, gdouble x, gdouble y) } /** - * adg_point_set_from_model: + * adg_point_set_pair_from_model: * @point: an #AdgPoint * @model: the #AdgModel * @name: the id of a named pair in @model @@ -240,7 +204,8 @@ adg_point_set_explicit(AdgPoint *point, gdouble x, gdouble y) * between @point and the named pair is dropped. **/ void -adg_point_set_from_model(AdgPoint *point, AdgModel *model, const gchar *name) +adg_point_set_pair_from_model(AdgPoint *point, + AdgModel *model, const gchar *name) { g_return_if_fail(point != NULL); g_return_if_fail(model == NULL || name != NULL); @@ -276,6 +241,48 @@ adg_point_set_from_model(AdgPoint *point, AdgModel *model, const gchar *name) } /** + * adg_point_get_pair: + * @point: an #AdgPoint + * + * #AdgPoint is an evolution of the pair concept, but internally the + * relevant data is still stored in an #AdgPair struct. This function + * gets this struct, optionally updating the internal value from the + * linked named pair if necessary. + * + * Returns: the pair of @point + **/ +const AdgPair * +adg_point_get_pair(AdgPoint *point) +{ + g_return_val_if_fail(point != NULL, NULL); + + if (!point->is_uptodate) { + const AdgPair *pair; + + if (point->model == NULL) { + /* A point with explicit coordinates not up to date + * is an unexpected condition */ + g_warning(_("%s: trying to get a pair from an undefined point"), + G_STRLOC); + return NULL; + } + + pair = adg_model_get_named_pair(point->model, point->name); + + if (pair == NULL) { + g_warning(_("%s: `%s' named pair not found in `%s' model instance"), + G_STRLOC, point->name, + g_type_name(G_TYPE_FROM_INSTANCE(point->model))); + return NULL; + } + + cpml_pair_copy(&point->pair, pair); + } + + return (AdgPair *) point; +} + +/** * adg_point_invalidate: * @point: an #AdgPoint * diff --git a/adg/adg-point.h b/adg/adg-point.h index e4f3ab04..d66f4677 100644 --- a/adg/adg-point.h +++ b/adg/adg-point.h @@ -33,23 +33,23 @@ G_BEGIN_DECLS typedef struct _AdgPoint AdgPoint; -GType adg_point_get_type (void) G_GNUC_CONST; - -AdgPoint * adg_point_copy (AdgPoint *point, - const AdgPoint *src); -AdgPoint * adg_point_new (void); -AdgPoint * adg_point_dup (const AdgPoint *point); -void adg_point_destroy (AdgPoint *point); -const AdgPair * adg_point_pair (AdgPoint *point); -void adg_point_set (AdgPoint *point, - const AdgPair *pair); -void adg_point_set_explicit (AdgPoint *point, - gdouble x, - gdouble y); -void adg_point_set_from_model(AdgPoint *point, - AdgModel *model, - const gchar *name); -void adg_point_invalidate (AdgPoint *point); +GType adg_point_get_type (void) G_GNUC_CONST; + +AdgPoint * adg_point_copy (AdgPoint *point, + const AdgPoint *src); +AdgPoint * adg_point_new (void); +AdgPoint * adg_point_dup (const AdgPoint *point); +void adg_point_destroy (AdgPoint *point); +void adg_point_set_pair (AdgPoint *point, + const AdgPair *pair); +void adg_point_set_pair_explicit (AdgPoint *point, + gdouble x, + gdouble y); +void adg_point_set_pair_from_model (AdgPoint *point, + AdgModel *model, + const gchar *name); +const AdgPair * adg_point_get_pair (AdgPoint *point); +void adg_point_invalidate (AdgPoint *point); G_END_DECLS -- 2.11.4.GIT