10#ifndef UTIL_SYSTEM_HEADER
11#define UTIL_SYSTEM_HEADER
30void sleep (std::size_t msec);
58 char const* date,
char const* time);
98 std::this_thread::sleep_for(std::chrono::milliseconds(msec));
104 sleep((std::size_t)(secs * 1000.0f));
110 std::srand(std::time(
nullptr));
122 return (
float)std::rand() / (float)RAND_MAX;
142#if defined(_WIN32) || defined(__CYGWIN__)
143# define HOST_BYTEORDER_LE
149#if defined(__APPLE__)
150# if defined(__ppc__) || defined(__ppc64__)
151# define HOST_BYTEORDER_BE
153# define HOST_BYTEORDER_LE
157#if defined(__linux__)
159# if __BYTE_ORDER == __LITTLE_ENDIAN
160# define HOST_BYTEORDER_LE
162# define HOST_BYTEORDER_BE
166#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
167# include <machine/endian.h>
168# if BYTE_ORDER == LITTLE_ENDIAN
169# define HOST_BYTEORDER_LE
171# define HOST_BYTEORDER_BE
176# include <sys/byteorder.h>
177# if defined(_LITTLE_ENDIAN)
178# define HOST_BYTEORDER_LE
180# define HOST_BYTEORDER_BE
186byte_swap<2> (
char* data)
193byte_swap<4> (
char* data)
201byte_swap<8> (
char* data)
209#if defined(HOST_BYTEORDER_LE) && defined(HOST_BYTEORDER_BE)
210# error "Host endianess can not be both LE and BE!"
211#elif defined(HOST_BYTEORDER_LE)
225 byte_swap<sizeof(T)>(
reinterpret_cast<char*
>(©));
229#elif defined(HOST_BYTEORDER_BE)
236 byte_swap<sizeof(T)>(
reinterpret_cast<char*
>(©));
248# error "Couldn't determine host endianess!"
255 T data_little_endian;
256 stream->read(
reinterpret_cast<char*
>(&data_little_endian),
sizeof(T));
257 return letoh(data_little_endian);
void swap(mve::Image< T > &a, mve::Image< T > &b)
Specialization of std::swap for efficient image swapping.
void print_stack_trace(void)
Prints a stack trace.
T read_binary_little_endian(std::istream *stream)
Reads little endian according to host order conversion.
void byte_swap(char *data)
Swaps little/big endianess of the operand.
void signal_segfault_handler(int code)
Handles signal SIGSEGV (segmentation fault) printing a stack trace.
void sleep_sec(float secs)
Sleeps the given amount of seconds.
int rand_int(void)
Returns a random number in [0, 2^31].
void print_build_timestamp(char const *application_name, char const *date, char const *time)
Prints the application name and the given date and time strings.
void rand_init(void)
Initializes the random number generator.
void sleep(std::size_t msec)
Sleeps the given amount of milli seconds.
void rand_seed(int seed)
Initializes the random number generator with a given seed.
void register_segfault_handler(void)
Registers signal SIGSEGV (segmentation fault) handler.
float rand_float(void)
Returns a floating point random number in [0, 1].
T betoh(T const &x)
Big endian to host order conversion.
T letoh(T const &x)
Little endian to host order conversion.
#define UTIL_NAMESPACE_BEGIN
#define UTIL_NAMESPACE_END
#define UTIL_SYSTEM_NAMESPACE_BEGIN
#define UTIL_SYSTEM_NAMESPACE_END