Skip to content

Commit

Permalink
Add copy constructor in utility_time component.
Browse files Browse the repository at this point in the history
  • Loading branch information
eus committed Apr 22, 2011
1 parent 1633dca commit 1d887dc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
27 changes: 27 additions & 0 deletions utility_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ extern "C" {
/* IV */
/**
* @name Collection of conversion functions to internal representation.
* The utility_time object to store the result must always be
* initalized first.
* @{
*/
/**
Expand Down Expand Up @@ -368,6 +370,31 @@ extern "C" {
}
return internal_t;
}

/**
* Assign the internal representation of time from src to dst.
*/
static inline void utility_time_to_utility_time(const utility_time *src,
utility_time *dst)
{
dst->t.tv_sec = src->t.tv_sec;
dst->t.tv_nsec = src->t.tv_nsec;
}
/**
* Work just like utility_time_to_utility_time() except that it
* returns the result as dynamic utility_time object subject to
* automatic garbage collection.
*/
static inline utility_time *utility_time_to_utility_time_dyn(const
utility_time *
src)
{
utility_time *internal_t = utility_time_make_dyn();
if (internal_t != NULL) {
utility_time_to_utility_time(src, internal_t);
}
return internal_t;
}
/** @} End of collection of conversion functions to internal representation */

/* V */
Expand Down
5 changes: 5 additions & 0 deletions utility_time_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,10 @@ int main(int argc, char **argv, char **envp)
internal_t_dyn));
assert(endptr == &str[2]);

/* Testcase 28 */
to_utility_time(7777, ms, &internal_t);
to_timespec_gc(utility_time_to_utility_time_dyn(&internal_t), &t);
assert((t.tv_sec == 7) && (t.tv_nsec == 777000000));

return EXIT_SUCCESS;
}

0 comments on commit 1d887dc

Please sign in to comment.