Elapsed time representation.

Introduced properties

private fun -(other: Timespec): Timespec

realtime :: Timespec :: -

Subtract other from self
private init copy_of(other: Timespec): Timespec

realtime :: Timespec :: copy_of

Init a new Timespec copied from another.
private fun microsec: Int

realtime :: Timespec :: microsec

Elapsed time in microseconds, with both whole seconds and the rest
private fun millisec: Int

realtime :: Timespec :: millisec

Elapsed time in milliseconds, with both whole seconds and the rest
private fun minus(a: Timespec, b: Timespec)

realtime :: Timespec :: minus

Set self to a - b
private init monotonic_now: Timespec

realtime :: Timespec :: monotonic_now

Init a new Timespec from now.
private fun nanosec: Int

realtime :: Timespec :: nanosec

Rest of the elapsed time (a fraction of a second).
private init new(s: Int, ns: Int): Timespec

realtime :: Timespec :: new

Init a new Timespec from s seconds and ns nanoseconds.
private fun sec: Int

realtime :: Timespec :: sec

Number of whole seconds of elapsed time.
private fun to_f: Float

realtime :: Timespec :: to_f

Number of seconds as a Float
private fun update

realtime :: Timespec :: update

Update self clock.

Redefined properties

redef type SELF: Timespec

realtime $ Timespec :: SELF

Type of this instance, automatically specialized in every class
redef fun to_s: String

realtime $ Timespec :: to_s

User readable representation of self.

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
private fun -(other: Timespec): Timespec

realtime :: Timespec :: -

Subtract other from self
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
fun address_is_null: Bool

core :: Pointer :: address_is_null

Is the address behind this Object at NULL?
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
private init copy_of(other: Timespec): Timespec

realtime :: Timespec :: copy_of

Init a new Timespec copied from another.
fun free

core :: Pointer :: free

Free the memory pointed by this pointer
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
private fun microsec: Int

realtime :: Timespec :: microsec

Elapsed time in microseconds, with both whole seconds and the rest
private fun millisec: Int

realtime :: Timespec :: millisec

Elapsed time in milliseconds, with both whole seconds and the rest
private fun minus(a: Timespec, b: Timespec)

realtime :: Timespec :: minus

Set self to a - b
private init monotonic_now: Timespec

realtime :: Timespec :: monotonic_now

Init a new Timespec from now.
private fun nanosec: Int

realtime :: Timespec :: nanosec

Rest of the elapsed time (a fraction of a second).
private intern fun native_class_name: CString

core :: Object :: native_class_name

The class name of the object in CString format.
private fun native_equals(o: Pointer): Bool

core :: Pointer :: native_equals

private init new(s: Int, ns: Int): Timespec

realtime :: Timespec :: new

Init a new Timespec from s seconds and ns nanoseconds.
init nul: Pointer

core :: Pointer :: nul

C NULL pointer
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
private fun premultiply_alpha(width: Int, height: Int)

core :: Pointer :: premultiply_alpha

Multiply RGB values by their alpha value
private fun sec: Int

realtime :: Timespec :: sec

Number of whole seconds of elapsed time.
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
private fun to_f: Float

realtime :: Timespec :: to_f

Number of seconds as a Float
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
private fun update

realtime :: Timespec :: update

Update self clock.
package_diagram realtime::realtime::Timespec Timespec core::Pointer Pointer realtime::realtime::Timespec->core::Pointer core::Object Object core::Pointer->core::Object ...core::Object ... ...core::Object->core::Object

Ancestors

interface Object

core :: Object

The root of the class hierarchy.

Parents

extern class Pointer

core :: Pointer

Pointer classes are used to manipulate extern C structures.

Class definitions

realtime $ Timespec
# Elapsed time representation.
private extern class Timespec `{struct timespec*`}

	# Init a new Timespec from `s` seconds and `ns` nanoseconds.
	new ( s, ns : Int ) `{
		struct timespec* tv = malloc( sizeof(struct timespec) );
		tv->tv_sec = s; tv->tv_nsec = ns;
		return tv;
	`}

	# Init a new Timespec from now.
	new monotonic_now `{
		struct timespec* tv = malloc( sizeof(struct timespec) );
		nit_clock_gettime( CLOCK_MONOTONIC, tv );
		return tv;
	`}

	# Init a new Timespec copied from another.
	new copy_of( other : Timespec ) `{
		struct timespec* tv = malloc( sizeof(struct timespec) );
		tv->tv_sec = other->tv_sec;
		tv->tv_nsec = other->tv_nsec;
		return tv;
	`}

	# Update `self` clock.
	fun update `{
		nit_clock_gettime(CLOCK_MONOTONIC, self);
	`}

	# Subtract `other` from `self`
	fun -(other: Timespec): Timespec `{
		time_t s = self->tv_sec - other->tv_sec;
		long ns = self->tv_nsec - other->tv_nsec;
		if (ns < 0) {
			s -= 1;
			ns += 1000000000l;
		}
		struct timespec* tv = malloc(sizeof(struct timespec));
		tv->tv_sec = s; tv->tv_nsec = ns;
		return tv;
	`}

	# Set `self` to `a` - `b`
	fun minus(a, b: Timespec) `{
		time_t s = a->tv_sec - b->tv_sec;
		long ns = a->tv_nsec - b->tv_nsec;
		if (ns < 0) {
			s -= 1;
			ns += 1000000000l;
		}
		self->tv_sec = s;
		self->tv_nsec = ns;
	`}

	# Number of whole seconds of elapsed time.
	fun sec : Int `{
		return self->tv_sec;
	`}

	# Rest of the elapsed time (a fraction of a second).
	#
	# Number of nanoseconds.
	fun nanosec : Int `{
		return self->tv_nsec;
	`}

	# Elapsed time in microseconds, with both whole seconds and the rest
	#
	# May cause an `Int` overflow, use only with a low number of seconds.
	fun microsec: Int `{
		return self->tv_sec*1000000 + self->tv_nsec/1000;
	`}

	# Elapsed time in milliseconds, with both whole seconds and the rest
	#
	# May cause an `Int` overflow, use only with a low number of seconds.
	fun millisec: Int `{
		return self->tv_sec*1000 + self->tv_nsec/1000000;
	`}

	# Number of seconds as a `Float`
	#
	# Incurs a loss of precision, but the result is pretty to print.
	fun to_f: Float `{
		return (double)self->tv_sec + 0.000000001 * self->tv_nsec;
	`}

	redef fun to_s do return "{to_f}s"
end
lib/realtime/realtime.nit:58,1--147,3