r19458 - gnucash/trunk/src - Impove const-correctness of SchedXaction.h functions; improve documentation.
Christian Stimming
cstim at code.gnucash.org
Sat Aug 21 16:57:19 EDT 2010
Author: cstim
Date: 2010-08-21 16:57:19 -0400 (Sat, 21 Aug 2010)
New Revision: 19458
Trac: http://svn.gnucash.org/trac/changeset/19458
Modified:
gnucash/trunk/src/app-utils/gnc-sx-instance-model.c
gnucash/trunk/src/backend/xml/gnc-schedxaction-xml-v2.c
gnucash/trunk/src/engine/SchedXaction.c
gnucash/trunk/src/engine/SchedXaction.h
gnucash/trunk/src/gnome-utils/gnc-frequency.c
gnucash/trunk/src/gnome-utils/gnc-frequency.h
gnucash/trunk/src/gnome-utils/gnc-sx-list-tree-model-adapter.c
gnucash/trunk/src/gnome/dialog-sx-editor.c
gnucash/trunk/src/gnome/dialog-sx-since-last-run.c
Log:
Impove const-correctness of SchedXaction.h functions; improve documentation.
Also, replace "void *" by pointers to the actual type.
Modified: gnucash/trunk/src/app-utils/gnc-sx-instance-model.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-sx-instance-model.c 2010-08-21 19:37:49 UTC (rev 19457)
+++ gnucash/trunk/src/app-utils/gnc-sx-instance-model.c 2010-08-21 20:57:19 UTC (rev 19458)
@@ -1229,7 +1229,7 @@
if (g_list_length(instances->instance_list) == 0)
continue;
- last_occur_date = xaccSchedXactionGetLastOccurDate(instances->sx);
+ last_occur_date = (GDate*) xaccSchedXactionGetLastOccurDate(instances->sx);
instance_count = gnc_sx_get_instance_count(instances->sx, NULL);
remain_occur_count = xaccSchedXactionGetRemOccur(instances->sx);
Modified: gnucash/trunk/src/backend/xml/gnc-schedxaction-xml-v2.c
===================================================================
--- gnucash/trunk/src/backend/xml/gnc-schedxaction-xml-v2.c 2010-08-21 19:37:49 UTC (rev 19457)
+++ gnucash/trunk/src/backend/xml/gnc-schedxaction-xml-v2.c 2010-08-21 20:57:19 UTC (rev 19458)
@@ -83,7 +83,7 @@
gnc_schedXaction_dom_tree_create(SchedXaction *sx)
{
xmlNodePtr ret;
- GDate *date;
+ const GDate *date;
gint instCount;
const GncGUID *templ_acc_guid;
gboolean allow_2_2_incompat = TRUE;
@@ -169,12 +169,12 @@
/* Output deferred-instance list. */
{
xmlNodePtr instNode;
- temporalStateData *tsd;
+ SXTmpStateData *tsd;
GList *l;
for ( l = gnc_sx_get_defer_instances( sx ); l; l = l->next )
{
- tsd = (temporalStateData*)l->data;
+ tsd = (SXTmpStateData*)l->data;
instNode = xmlNewNode( NULL, BAD_CAST SX_DEFER_INSTANCE );
if ( g_date_valid( &tsd->last_date ) )
@@ -371,7 +371,7 @@
}
static void
-_fixup_recurrence_start_dates(GDate *sx_start_date, GList *schedule)
+_fixup_recurrence_start_dates(const GDate *sx_start_date, GList *schedule)
{
GList *iter;
for (iter = schedule; iter != NULL; iter = iter->next)
@@ -485,7 +485,7 @@
sx_defer_last_handler( xmlNodePtr node, gpointer gpTSD )
{
GDate *gd;
- temporalStateData *tsd = (temporalStateData*)gpTSD;
+ SXTmpStateData *tsd = (SXTmpStateData*)gpTSD;
g_return_val_if_fail( node, FALSE );
gd = dom_tree_to_gdate( node );
@@ -500,7 +500,7 @@
sx_defer_rem_occur_handler( xmlNodePtr node, gpointer gpTSD )
{
gint64 remOccur;
- temporalStateData *tsd = (temporalStateData*)gpTSD;
+ SXTmpStateData *tsd = (SXTmpStateData*)gpTSD;
g_return_val_if_fail( node, FALSE );
if ( ! dom_tree_to_integer( node, &remOccur ) )
@@ -516,7 +516,7 @@
sx_defer_inst_count_handler( xmlNodePtr node, gpointer gpTSD )
{
gint64 instCount;
- temporalStateData *tsd = (temporalStateData*)gpTSD;
+ SXTmpStateData *tsd = (SXTmpStateData*)gpTSD;
g_return_val_if_fail( node, FALSE );
if ( ! dom_tree_to_integer( node, &instCount ) )
@@ -542,11 +542,11 @@
{
struct sx_pdata *pdata = sx_pdata;
SchedXaction *sx = pdata->sx;
- temporalStateData *tsd;
+ SXTmpStateData *tsd;
g_return_val_if_fail( node, FALSE );
- tsd = g_new0( temporalStateData, 1 );
+ tsd = g_new0( SXTmpStateData, 1 );
g_assert( sx_defer_dom_handlers != NULL );
if ( !dom_tree_generic_parse( node,
sx_defer_dom_handlers,
Modified: gnucash/trunk/src/engine/SchedXaction.c
===================================================================
--- gnucash/trunk/src/engine/SchedXaction.c 2010-08-21 19:37:49 UTC (rev 19457)
+++ gnucash/trunk/src/engine/SchedXaction.c 2010-08-21 20:57:19 UTC (rev 19458)
@@ -574,8 +574,8 @@
gnc_sx_commit_edit(sx);
}
-GDate*
-xaccSchedXactionGetStartDate( SchedXaction *sx )
+const GDate*
+xaccSchedXactionGetStartDate(const SchedXaction *sx )
{
return &sx->start_date;
}
@@ -595,8 +595,8 @@
return g_date_valid( &sx->end_date );
}
-GDate*
-xaccSchedXactionGetEndDate( SchedXaction *sx )
+const GDate*
+xaccSchedXactionGetEndDate(const SchedXaction *sx )
{
return &sx->end_date;
}
@@ -622,8 +622,8 @@
gnc_sx_commit_edit(sx);
}
-GDate*
-xaccSchedXactionGetLastOccurDate( SchedXaction *sx )
+const GDate*
+xaccSchedXactionGetLastOccurDate(const SchedXaction *sx )
{
return &sx->last_date;
}
@@ -784,7 +784,7 @@
GDate
-xaccSchedXactionGetNextInstance( SchedXaction *sx, void *stateData )
+xaccSchedXactionGetNextInstance(const SchedXaction *sx, SXTmpStateData *stateData )
{
GDate last_occur, next_occur, tmpDate;
@@ -799,7 +799,7 @@
if ( stateData != NULL )
{
- temporalStateData *tsd = (temporalStateData*)stateData;
+ SXTmpStateData *tsd = (SXTmpStateData*)stateData;
last_occur = tsd->last_date;
}
@@ -831,7 +831,7 @@
/* out-of-bounds check */
if ( xaccSchedXactionHasEndDate( sx ) )
{
- GDate *end_date = xaccSchedXactionGetEndDate( sx );
+ const GDate *end_date = xaccSchedXactionGetEndDate( sx );
if ( g_date_compare( &next_occur, end_date ) > 0 )
{
g_debug("next_occur past end date");
@@ -842,7 +842,7 @@
{
if ( stateData )
{
- temporalStateData *tsd = (temporalStateData*)stateData;
+ SXTmpStateData *tsd = (SXTmpStateData*)stateData;
if ( tsd->num_occur_rem == 0 )
{
g_debug("no more occurances remain");
@@ -862,9 +862,9 @@
}
GDate
-xaccSchedXactionGetInstanceAfter( SchedXaction *sx,
+xaccSchedXactionGetInstanceAfter( const SchedXaction *sx,
GDate *date,
- void *stateData )
+ SXTmpStateData *stateData )
{
GDate prev_occur, next_occur;
@@ -876,7 +876,7 @@
if ( stateData != NULL )
{
- temporalStateData *tsd = (temporalStateData*)stateData;
+ SXTmpStateData *tsd = (SXTmpStateData*)stateData;
prev_occur = tsd->last_date;
}
@@ -891,9 +891,7 @@
if ( xaccSchedXactionHasEndDate( sx ) )
{
- GDate *end_date;
-
- end_date = xaccSchedXactionGetEndDate( sx );
+ const GDate *end_date = xaccSchedXactionGetEndDate( sx );
if ( g_date_compare( &next_occur, end_date ) > 0 )
{
g_date_clear( &next_occur, 1 );
@@ -903,7 +901,7 @@
{
if ( stateData )
{
- temporalStateData *tsd = (temporalStateData*)stateData;
+ SXTmpStateData *tsd = (SXTmpStateData*)stateData;
if ( tsd->num_occur_rem == 0 )
{
g_date_clear( &next_occur, 1 );
@@ -921,14 +919,14 @@
}
gint
-gnc_sx_get_instance_count( const SchedXaction *sx, void *stateData )
+gnc_sx_get_instance_count( const SchedXaction *sx, SXTmpStateData *stateData )
{
gint toRet = -1;
- temporalStateData *tsd;
+ SXTmpStateData *tsd;
if ( stateData )
{
- tsd = (temporalStateData*)stateData;
+ tsd = (SXTmpStateData*)stateData;
toRet = tsd->num_inst;
}
else
@@ -1061,22 +1059,22 @@
}
}
-void*
-gnc_sx_create_temporal_state( SchedXaction *sx )
+SXTmpStateData*
+gnc_sx_create_temporal_state(const SchedXaction *sx )
{
- temporalStateData *toRet =
- g_new0( temporalStateData, 1 );
+ SXTmpStateData *toRet =
+ g_new0( SXTmpStateData, 1 );
toRet->last_date = sx->last_date;
toRet->num_occur_rem = sx->num_occurances_remain;
toRet->num_inst = sx->instance_num;
- return (void*)toRet;
+ return toRet;
}
void
-gnc_sx_incr_temporal_state( SchedXaction *sx, void *stateData )
+gnc_sx_incr_temporal_state(const SchedXaction *sx, SXTmpStateData *stateData )
{
GDate unused;
- temporalStateData *tsd = (temporalStateData*)stateData;
+ SXTmpStateData *tsd = (SXTmpStateData*)stateData;
g_date_clear( &unused, 1 );
tsd->last_date =
@@ -1091,9 +1089,9 @@
}
void
-gnc_sx_revert_to_temporal_state( SchedXaction *sx, void *stateData )
+gnc_sx_revert_to_temporal_state( SchedXaction *sx, SXTmpStateData *stateData )
{
- temporalStateData *tsd = (temporalStateData*)stateData;
+ SXTmpStateData *tsd = (SXTmpStateData*)stateData;
gnc_sx_begin_edit(sx);
sx->last_date = tsd->last_date;
sx->num_occurances_remain = tsd->num_occur_rem;
@@ -1103,27 +1101,27 @@
}
void
-gnc_sx_destroy_temporal_state( void *stateData )
+gnc_sx_destroy_temporal_state( SXTmpStateData *stateData )
{
- g_free( (temporalStateData*)stateData );
+ g_free( (SXTmpStateData*)stateData );
}
-void*
-gnc_sx_clone_temporal_state( void *stateData )
+SXTmpStateData*
+gnc_sx_clone_temporal_state( SXTmpStateData *stateData )
{
- temporalStateData *toRet, *tsd;
- tsd = (temporalStateData*)stateData;
- toRet = g_memdup( tsd, sizeof( temporalStateData ) );
- return (void*)toRet;
+ SXTmpStateData *toRet, *tsd;
+ tsd = (SXTmpStateData*)stateData;
+ toRet = g_memdup( tsd, sizeof( SXTmpStateData ) );
+ return toRet;
}
static
gint
_temporal_state_data_cmp( gconstpointer a, gconstpointer b )
{
- temporalStateData *tsd_a, *tsd_b;
- tsd_a = (temporalStateData*)a;
- tsd_b = (temporalStateData*)b;
+ SXTmpStateData *tsd_a, *tsd_b;
+ tsd_a = (SXTmpStateData*)a;
+ tsd_b = (SXTmpStateData*)b;
if ( !tsd_a && !tsd_b )
return 0;
Modified: gnucash/trunk/src/engine/SchedXaction.h
===================================================================
--- gnucash/trunk/src/engine/SchedXaction.h 2010-08-21 19:37:49 UTC (rev 19457)
+++ gnucash/trunk/src/engine/SchedXaction.h 2010-08-21 20:57:19 UTC (rev 19458)
@@ -113,9 +113,9 @@
Account *template_acct;
- /** The list of deferred SX instances. This list is of temporalStateData
+ /** The list of deferred SX instances. This list is of SXTmpStateData
* instances. */
- GList /* <temporalStateData*> */ *deferredList;
+ GList /* <SXTmpStateData*> */ *deferredList;
};
struct _SchedXactionClass
@@ -124,12 +124,12 @@
};
/** Just the variable temporal bits from the SX structure. */
-typedef struct _temporalStateData
+typedef struct _SXTmpStateData
{
GDate last_date;
gint num_occur_rem;
gint num_inst;
-} temporalStateData;
+} SXTmpStateData;
#define xaccSchedXactionSetGUID(X,G) qof_instance_set_guid(QOF_INSTANCE(X),(G))
@@ -160,20 +160,20 @@
*/
void xaccSchedXactionSetName( SchedXaction *sx, const gchar *newName );
-GDate* xaccSchedXactionGetStartDate( SchedXaction *sx );
+const GDate* xaccSchedXactionGetStartDate(const SchedXaction *sx );
void xaccSchedXactionSetStartDate( SchedXaction *sx, GDate* newStart );
int xaccSchedXactionHasEndDate( const SchedXaction *sx );
/**
* Returns invalid date when there is no end-date specified.
*/
-GDate* xaccSchedXactionGetEndDate( SchedXaction *sx );
+const GDate* xaccSchedXactionGetEndDate(const SchedXaction *sx );
/**
* Set to an invalid GDate to turn off 'end-date' definition.
*/
void xaccSchedXactionSetEndDate( SchedXaction *sx, GDate* newEnd );
-GDate* xaccSchedXactionGetLastOccurDate( SchedXaction *sx );
+const GDate* xaccSchedXactionGetLastOccurDate(const SchedXaction *sx );
void xaccSchedXactionSetLastOccurDate( SchedXaction *sx, GDate* newLastOccur );
/**
@@ -189,7 +189,7 @@
gint xaccSchedXactionGetRemOccur( const SchedXaction *sx );
void xaccSchedXactionSetRemOccur( SchedXaction *sx, gint numRemain );
-/** \brief Set the instance count.
+/** \brief Get the instance count.
*
* This is incremented by one for every created
* instance of the SX. Returns the instance num of the SX unless stateData
@@ -198,7 +198,7 @@
* @param sx The instance whose state should be retrieved.
* @param stateData may be NULL.
*/
-gint gnc_sx_get_instance_count( const SchedXaction *sx, /*@ null @*/ void *stateData );
+gint gnc_sx_get_instance_count( const SchedXaction *sx, /*@ null @*/ SXTmpStateData *stateData );
/**
* Sets the instance count to something other than the default. As the
* default is the incorrect value '0', callers should DTRT here.
@@ -233,16 +233,32 @@
* SX without having to rollback all the individual state changes.
@{
*/
-void *gnc_sx_create_temporal_state( SchedXaction *sx );
-void gnc_sx_incr_temporal_state( SchedXaction *sx, void *stateData );
+/** Allocates a new SXTmpStateData object and fills it with the
+ * current state of the given sx.
+ */
+SXTmpStateData *gnc_sx_create_temporal_state(const SchedXaction *sx );
+
+/** Calculates the next occurrence of the given SX and stores that
+ * occurence in the remporalStateDate. The SX is unchanged. */
+void gnc_sx_incr_temporal_state(const SchedXaction *sx, SXTmpStateData *stateData );
+
+/** Sets the state of the given SX to the state of the given
+ * SXTmpStateData. In that sense, this function does not "revert"
+ * but instead it copies the state from the SXTmpStateData to the
+ * real SX.. */
void gnc_sx_revert_to_temporal_state( SchedXaction *sx,
- void *stateData );
-void gnc_sx_destroy_temporal_state( void *stateData );
-/** \brief Allocates and returns a copy of the given temporal state.
+ SXTmpStateData *stateData );
- * Destroy with gnc_sx_destroy_temporal_state(), as you'd expect.
+/** Frees the given stateDate object. */
+void gnc_sx_destroy_temporal_state( SXTmpStateData *stateData );
+
+/** \brief Allocates and returns a one-by-one copy of the given
+ * temporal state.
+ *
+ * The caller must destroy the returned object with
+ * gnc_sx_destroy_temporal_state() after usage.
*/
-void *gnc_sx_clone_temporal_state( void *stateData );
+SXTmpStateData *gnc_sx_clone_temporal_state( SXTmpStateData *stateData );
/** @} */
/** \brief Returns the next occurrence of a scheduled transaction.
@@ -256,10 +272,10 @@
* for possible action without modifying the SX state until action is
* actually taken.
*/
-GDate xaccSchedXactionGetNextInstance( SchedXaction *sx, void *stateData );
-GDate xaccSchedXactionGetInstanceAfter( SchedXaction *sx,
- GDate *date,
- void *stateData );
+GDate xaccSchedXactionGetNextInstance(const SchedXaction *sx, SXTmpStateData *stateData );
+GDate xaccSchedXactionGetInstanceAfter(const SchedXaction *sx,
+ GDate *date,
+ SXTmpStateData *stateData );
/** \brief Set the schedxaction's template transaction.
Modified: gnucash/trunk/src/gnome/dialog-sx-editor.c
===================================================================
--- gnucash/trunk/src/gnome/dialog-sx-editor.c 2010-08-21 19:37:49 UTC (rev 19457)
+++ gnucash/trunk/src/gnome/dialog-sx-editor.c 2010-08-21 20:57:19 UTC (rev 19458)
@@ -1382,7 +1382,7 @@
time_t tmpDate;
SplitRegister *splitReg;
struct tm *tmpTm;
- GDate *gd;
+ const GDate *gd;
gint daysInAdvance;
gboolean enabledState, autoCreateState, notifyState;
@@ -1623,7 +1623,7 @@
/* Deal with the fact that this SX may have been run before [the
* calendar should only show upcoming instances]... */
{
- GDate *last_sx_inst;
+ const GDate *last_sx_inst;
last_sx_inst = xaccSchedXactionGetLastOccurDate(sxed->sx);
if (g_date_valid(last_sx_inst)
Modified: gnucash/trunk/src/gnome/dialog-sx-since-last-run.c
===================================================================
--- gnucash/trunk/src/gnome/dialog-sx-since-last-run.c 2010-08-21 19:37:49 UTC (rev 19457)
+++ gnucash/trunk/src/gnome/dialog-sx-since-last-run.c 2010-08-21 20:57:19 UTC (rev 19458)
@@ -445,7 +445,7 @@
char last_occur_date_buf[MAX_DATE_LENGTH+1];
{
- GDate *last_occur = xaccSchedXactionGetLastOccurDate(instances->sx);
+ const GDate *last_occur = xaccSchedXactionGetLastOccurDate(instances->sx);
if (last_occur == NULL || !g_date_valid(last_occur))
{
g_stpcpy(last_occur_date_buf, _("Never"));
Modified: gnucash/trunk/src/gnome-utils/gnc-frequency.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-frequency.c 2010-08-21 19:37:49 UTC (rev 19457)
+++ gnucash/trunk/src/gnome-utils/gnc-frequency.c 2010-08-21 20:57:19 UTC (rev 19458)
@@ -313,13 +313,13 @@
}
GtkWidget*
-gnc_frequency_new_from_recurrence(GList *recurrences, GDate *start_date)
+gnc_frequency_new_from_recurrence(GList *recurrences, const GDate *start_date)
{
return gnc_frequency_new(recurrences, start_date);
}
GtkWidget*
-gnc_frequency_new(GList *recurrences, GDate *start_date)
+gnc_frequency_new(GList *recurrences, const GDate *start_date)
{
GncFrequency *toRet;
toRet = g_object_new(gnc_frequency_get_type(), NULL);
@@ -369,13 +369,13 @@
}
void
-gnc_frequency_setup_recurrence(GncFrequency *gf, GList *recurrences, GDate *start_date)
+gnc_frequency_setup_recurrence(GncFrequency *gf, GList *recurrences, const GDate *start_date)
{
gnc_frequency_setup(gf, recurrences, start_date);
}
void
-gnc_frequency_setup(GncFrequency *gf, GList *recurrences, GDate *start_date)
+gnc_frequency_setup(GncFrequency *gf, GList *recurrences, const GDate *start_date)
{
gboolean made_changes = FALSE;
Modified: gnucash/trunk/src/gnome-utils/gnc-frequency.h
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-frequency.h 2010-08-21 19:37:49 UTC (rev 19457)
+++ gnucash/trunk/src/gnome-utils/gnc-frequency.h 2010-08-21 20:57:19 UTC (rev 19458)
@@ -69,8 +69,8 @@
/**
* Either or both param may be NULL for reasonable defaults.
**/
-GtkWidget* gnc_frequency_new(GList *recurrences, GDate *start_date);
-GtkWidget* gnc_frequency_new_from_recurrence(GList *recurrences, GDate *start_date);
+GtkWidget* gnc_frequency_new(GList *recurrences, const GDate *start_date);
+GtkWidget* gnc_frequency_new_from_recurrence(GList *recurrences, const GDate *start_date);
void gnc_frequency_init(GncFrequency *gf);
@@ -79,8 +79,8 @@
* If the FreqSpec is NULL, then no change is made to the widget menus.
* If the date is NULL, then no change is made to the widget date field.
**/
-void gnc_frequency_setup(GncFrequency *gf, GList *recurrences, GDate *start_date);
-void gnc_frequency_setup_recurrence(GncFrequency *gf, GList *recurrences, GDate *start_date);
+void gnc_frequency_setup(GncFrequency *gf, GList *recurrences, const GDate *start_date);
+void gnc_frequency_setup_recurrence(GncFrequency *gf, GList *recurrences, const GDate *start_date);
/**
* Saves the state of the GncFrequency widget.
Modified: gnucash/trunk/src/gnome-utils/gnc-sx-list-tree-model-adapter.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-sx-list-tree-model-adapter.c 2010-08-21 19:37:49 UTC (rev 19457)
+++ gnucash/trunk/src/gnome-utils/gnc-sx-list-tree-model-adapter.c 2010-08-21 20:57:19 UTC (rev 19458)
@@ -401,7 +401,7 @@
}
static gint
-_safe_invalidable_date_compare(GDate *a, GDate *b)
+_safe_invalidable_date_compare(const GDate *a, const GDate *b)
{
if (!g_date_valid(a) && !g_date_valid(b))
{
@@ -483,7 +483,7 @@
}
static void
-_format_conditional_date(GDate *date, char *date_buf, int buf_max_length)
+_format_conditional_date(const GDate *date, char *date_buf, int buf_max_length)
{
if (date == NULL || !g_date_valid(date))
{
More information about the gnucash-changes
mailing list