Header for the time periods used in Synema frames. More...
Go to the source code of this file.
Data Structures | |
struct | time_period_t |
Time period to use for the display of a frame. More... | |
Functions | |
char * | time_period_get_display_name_type_value (int, int, gboolean) |
Returns the display name for a given time period (passed as two ints). | |
char * | time_period_get_display_name (time_period_t *, gboolean) |
Returns the display name for a given time period. | |
time_period_t * | time_period_new (int, long) |
Allocates the memory to hold a time period and fills it with the parameters. | |
void | time_period_free (time_period_t *) |
Frees the memory allocated in a time_period_t struct. | |
void | time_period_copy (time_period_t *, time_period_t *) |
Copies the data of a time period into another, already allocated. | |
int | time_period_cmp (const time_period_t *, const time_period_t *) |
Compares two time periods. |
Header for the time periods used in Synema frames.
This header files describes the time periods used in Synema frames, and the functions related to time periods manipulation
Definition in file time-period.h.
int time_period_cmp | ( | const time_period_t * | t1, | |
const time_period_t * | t2 | |||
) |
Compares two time periods.
This function compares the type and value of two time periods and tells if they are equal or different.
[in] | t1 | the first time_period_t structure |
[in] | t2 | the second time_period_t structure |
Definition at line 139 of file time-period.c.
00140 { 00141 if (t1 == NULL) 00142 return (t2 == NULL) ? 0 : -1; 00143 00144 if (t2 == NULL) 00145 return 1; 00146 00147 if (t1->type != t2->type) 00148 return t1->type - t2->type; 00149 else if (t1->type == LIVE) 00150 return 0; 00151 else if (t1->value != t2->value) 00152 return t1->value - t2->value; 00153 else 00154 return 0; 00155 }
void time_period_copy | ( | time_period_t * | src, | |
time_period_t * | dest | |||
) |
Copies the data of a time period into another, already allocated.
This function copies the data of a time period (src) into another (dest). The dest time period must already be allocated.
[in] | src | the time period to copy from |
[out] | dest | the time_period_t that will be copied into |
Definition at line 131 of file time-period.c.
void time_period_free | ( | time_period_t * | t | ) |
Frees the memory allocated in a time_period_t struct.
This function frees a time period given in parameter
[out] | t | the time period to free |
Definition at line 124 of file time-period.c.
char* time_period_get_display_name | ( | time_period_t * | period, | |
gboolean | prepend_val | |||
) |
Returns the display name for a given time period.
This function creates an human readable string for a given time period, for display purpose. You must not forget to free this string when it is not needed anymore.
[in] | period | the time period for which you want an human readable name |
[in] | prepend_val | if FALSE, only return the time unit (eg. month, year) |
Definition at line 107 of file time-period.c.
00108 { 00109 return time_period_get_display_name_type_value (period->type, period->value, prepend_val); 00110 }
char* time_period_get_display_name_type_value | ( | int | type, | |
int | value, | |||
gboolean | prepend_val | |||
) |
Returns the display name for a given time period (passed as two ints).
This function creates an human readable string for a given time period, for display purpose. You must not forget to free this string when it is not needed anymore. The difference with time_period_get_display_name is that you pass the type and value directly instead of the time period. This avoids you to create a time period when you already have the values as integer.
[in] | type | the type of the time period |
[in] | value | the value of the type period |
[in] | prepend_val | if FALSE, only return the time unit (eg. month, year) |
Definition at line 31 of file time-period.c.
00032 { 00033 g_return_val_if_fail (type >= 0, NULL); 00034 g_return_val_if_fail (type < LAST_TIME_PERIOD_T, NULL); 00035 00036 char *name = NULL; 00037 char *token = NULL; 00038 00039 switch (type) { 00040 case LIVE: 00041 return g_strdup ("Live mode"); 00042 00043 case SECOND: 00044 if (value != 1) 00045 token = g_strdup ("seconds"); 00046 else 00047 token = g_strdup ("second"); 00048 break; 00049 00050 case MINUTE: 00051 if (value != 1) 00052 token = g_strdup ("minutes"); 00053 else 00054 token = g_strdup ("minute"); 00055 break; 00056 00057 case HOUR: 00058 if (value != 1) 00059 token = g_strdup ("hours"); 00060 else 00061 token = g_strdup ("hour"); 00062 break; 00063 00064 case DAY: 00065 if (value != 1) 00066 token = g_strdup ("days"); 00067 else 00068 token = g_strdup ("day"); 00069 break; 00070 00071 case WEEK: 00072 if (value != 1) 00073 token = g_strdup ("weeks"); 00074 else 00075 token = g_strdup ("week"); 00076 break; 00077 00078 case MONTH: 00079 if (value != 1) 00080 token = g_strdup ("months"); 00081 else 00082 token = g_strdup ("month"); 00083 break; 00084 00085 case YEAR: 00086 if (value != 1) 00087 token = g_strdup ("years"); 00088 else 00089 token = g_strdup ("year"); 00090 break; 00091 default: 00092 token = g_strdup ("unknown time unit"); 00093 } 00094 00095 if (prepend_val) { 00096 // TRANSLATORS: %s is the time unit (day, week, year, etc), and %d is the number of those time units, eg. 3 weeks, 5 days. 00097 name = g_strdup_printf ("%d %s", value, token); 00098 g_free (token); 00099 return name; 00100 } else { 00101 return token; 00102 } 00103 }
time_period_t* time_period_new | ( | int | type, | |
long | val | |||
) |
Allocates the memory to hold a time period and fills it with the parameters.
This function creates a time period. You must free it with time_period_free when you don't need it anymore.
[in] | type | the time unit of the time period (WEEK, MONTH, etc) |
[in] | val | the number of time units for the time period |
Definition at line 114 of file time-period.c.
00115 { 00116 time_period_t *t = g_malloc (sizeof (time_period_t)); 00117 t->type = type; 00118 t->value = val; 00119 return t; 00120 }