| 1 | package SPVM::Sys::Time::Timespec; | ||
| 2 | |||
| 3 | 1; | ||
| 4 | |||
| 5 | =head1 Name | ||
| 6 | |||
| 7 | SPVM::Sys::Time::Timespec - struct timespec in the C language | ||
| 8 | |||
| 9 | =head1 Description | ||
| 10 | |||
| 11 | Sys::Time::Timespec class in L<SPVM> represents L<struct timespec|https://linux.die.net/man/2/clock_gettime> in the C language. | ||
| 12 | |||
| 13 | =head1 Usage | ||
| 14 | |||
| 15 | use Sys::Time::Timespec; | ||
| 16 | |||
| 17 | my $ts = Sys::Time::Timespec->new; | ||
| 18 | |||
| 19 | my $ts = Sys::Time::Timespec->new(5, 300_000_000); | ||
| 20 | |||
| 21 | my $ts_sec = $ts->tv_sec; | ||
| 22 | $ts->set_tv_sec(12); | ||
| 23 | |||
| 24 | my $ts_nsec = $ts->tv_nsec; | ||
| 25 | $ts->set_tv_nsec(34); | ||
| 26 | |||
| 27 | =head1 Interfaces | ||
| 28 | |||
| 29 | =over 2 | ||
| 30 | |||
| 31 | =item * L<Cloneable|SPVM::Cloneable> | ||
| 32 | |||
| 33 | =back | ||
| 34 | |||
| 35 | =head1 Class Methods | ||
| 36 | |||
| 37 | =head2 new | ||
| 38 | |||
| 39 | C<static method new : L<Sys::Time::Timespec|SPVM::Sys::Time::Timespec> ($tv_sec : long = 0, $tv_nsec : long = 0);> | ||
| 40 | |||
| 41 | Creates a new L<Sys::Time::Timespec|SPVM::Sys::Time::Timespec> object with the given L</"tv_sec"> and L</"tv_nsec">. | ||
| 42 | |||
| 43 | Before creating the object, this method calls L</"check"> to validate the range of the arguments. If the arguments are invalid (e.g., L</"tv_nsec"> is out of the range [0, 999,999,999]), an exception is thrown. | ||
| 44 | |||
| 45 | The internal L<struct timespec|https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/time.h.html> is allocated in memory and managed by this object. | ||
| 46 | |||
| 47 | Example: | ||
| 48 | |||
| 49 | my $ts = Sys::Time::Timespec->new(1737158400L, 500L); | ||
| 50 | |||
| 51 | =head2 check | ||
| 52 | |||
| 53 | C<static method check : void ($tv_sec : long, $tv_nsec : long);> | ||
| 54 | |||
| 55 | Validates the range of the given L</"tv_sec"> and L</"tv_nsec">. | ||
| 56 | |||
| 57 | If L</"tv_nsec"> is not greater than or equal to 0 and less than or equal to 999,999,999, an exception is thrown. | ||
| 58 | |||
| 59 | =head1 Instance Methods | ||
| 60 | |||
| 61 | =head2 tv_sec | ||
| 62 | |||
| 63 | C<method tv_sec : long ()> | ||
| 64 | |||
| 65 | Returns C<tv_sec>. | ||
| 66 | |||
| 67 | =head2 set_tv_sec | ||
| 68 | |||
| 69 | C<method set_tv_sec : void ($ts_sec : long);> | ||
| 70 | |||
| 71 | Sets C<tv_sec>. | ||
| 72 | |||
| 73 | =head2 tv_nsec | ||
| 74 | |||
| 75 | C<method tv_nsec : long ()> | ||
| 76 | |||
| 77 | Returns C<tv_nsec>. | ||
| 78 | |||
| 79 | =head2 set_tv_nsec | ||
| 80 | |||
| 81 | C<method set_tv_nsec : void ($ts_nsec : long);> | ||
| 82 | |||
| 83 | Sets C<tv_nsec>. | ||
| 84 | |||
| 85 | =head2 clone | ||
| 86 | |||
| 87 | C<method clone : L<Sys::Time::Timespec|SPVM::Sys::Time::Timespec> ();> | ||
| 88 | |||
| 89 | Creates a new L<Sys::Time::Timespec|SPVM::Sys::Time::Timespec> object that is a copy of the current instance. | ||
| 90 | |||
| 91 | The new object will have the same L</"tv_sec"> and L</"tv_nsec"> values as the original. | ||
| 92 | |||
| 93 | =head2 DESTROY | ||
| 94 | |||
| 95 | C<native method DESTROY : void ();> | ||
| 96 | |||
| 97 | The destructor. | ||
| 98 | |||
| 99 | =head1 See Also | ||
| 100 | |||
| 101 | =over 2 | ||
| 102 | |||
| 103 | =item * L<Sys|SPVM::Sys> | ||
| 104 | |||
| 105 | =back | ||
| 106 | |||
| 107 | =head1 Copyright & License | ||
| 108 | |||
| 109 | Copyright (c) 2023 Yuki Kimoto | ||
| 110 | |||
| 111 | MIT License | ||
| 112 |