PageRenderTime 38ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Lib/ruby/timeval.i

#
Swig | 69 lines | 53 code | 8 blank | 8 comment | 0 complexity | c8fa38d12dad434efea4ee50fe55e5dc MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /*
  2. struct timeval *
  3. time_t
  4. Ruby has builtin class Time. INPUT/OUTPUT typemap for timeval and
  5. time_t is provided.
  6. */
  7. %{
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. #ifdef HAVE_SYS_TIME_H
  12. # include <sys/time.h>
  13. struct timeval rb_time_timeval(VALUE);
  14. #endif
  15. #ifdef __cplusplus
  16. }
  17. #endif
  18. %}
  19. %typemap(in) struct timeval *INPUT (struct timeval temp)
  20. {
  21. if (NIL_P($input))
  22. $1 = NULL;
  23. else {
  24. temp = rb_time_timeval($input);
  25. $1 = &temp;
  26. }
  27. }
  28. %typemap(in,numinputs=0) struct timeval *OUTPUT(struct timeval temp)
  29. {
  30. $1 = &temp;
  31. }
  32. %typemap(argout) struct timeval *OUTPUT
  33. {
  34. $result = rb_time_new($1->tv_sec, $1->tv_usec);
  35. }
  36. %typemap(out) struct timeval *
  37. {
  38. $result = rb_time_new($1->tv_sec, $1->tv_usec);
  39. }
  40. %typemap(out) struct timespec *
  41. {
  42. $result = rb_time_new($1->tv_sec, $1->tv_nsec / 1000);
  43. }
  44. // time_t
  45. %typemap(in) time_t
  46. {
  47. if (NIL_P($input))
  48. $1 = (time_t)-1;
  49. else
  50. $1 = NUM2LONG(rb_funcall($input, rb_intern("tv_sec"), 0));
  51. }
  52. %typemap(typecheck) time_t
  53. {
  54. $1 = (NIL_P($input) || TYPE(rb_funcall($input, rb_intern("respond_to?"), 1, ID2SYM(rb_intern("tv_sec")))) == T_TRUE);
  55. }
  56. %typemap(out) time_t
  57. {
  58. $result = rb_time_new($1, 0);
  59. }