#include <stdio.h>
#include <string.h>
Go to the source code of this file.
|
| void | chomp_string (char *str) |
| |
| void | SkipNewline (FILE *file) |
| |
| int | sort_floats (const void *arg1, const void *arg2) |
| |
| int | RoundUp (int n, int block_size) |
| |
| template<typename T > |
| T | ClipToRange (const T &x, const T &lower_bound, const T &upper_bound) |
| |
| template<typename T1 , typename T2 > |
| void | UpdateRange (const T1 &x, T2 *lower_bound, T2 *upper_bound) |
| |
| template<typename T1 , typename T2 > |
| void | UpdateRange (const T1 &x_lo, const T1 &x_hi, T2 *lower_bound, T2 *upper_bound) |
| |
| template<typename T > |
| void | IntersectRange (const T &lower1, const T &upper1, T *lower2, T *upper2) |
| |
| int | Modulo (int a, int b) |
| |
| int | DivRounded (int a, int b) |
| |
| int | IntCastRounded (double x) |
| |
| void | ReverseN (void *ptr, int num_bytes) |
| |
| void | Reverse16 (void *ptr) |
| |
| void | Reverse32 (void *ptr) |
| |
| void | Reverse64 (void *ptr) |
| |
| void chomp_string |
( |
char * |
str | ) |
|
|
inline |
Definition at line 32 of file helpers.h.
33 int last_index = strlen(str) - 1;
34 while (last_index >= 0 &&
35 (str[last_index] ==
'\n' || str[last_index] ==
'\r')) {
36 str[last_index--] =
'\0';
template<typename T >
| T ClipToRange |
( |
const T & |
x, |
|
|
const T & |
lower_bound, |
|
|
const T & |
upper_bound |
|
) |
| |
|
inline |
| int DivRounded |
( |
int |
a, |
|
|
int |
b |
|
) |
| |
|
inline |
Definition at line 115 of file helpers.h.
117 return a >= 0 ? (a + b / 2) / b : (a - b / 2) / b;
int DivRounded(int a, int b)
| int IntCastRounded |
( |
double |
x | ) |
|
|
inline |
Definition at line 121 of file helpers.h.
122 return x >= 0.0 ?
static_cast<int>(x + 0.5) : -
static_cast<int>(-x + 0.5);
template<typename T >
| void IntersectRange |
( |
const T & |
lower1, |
|
|
const T & |
upper1, |
|
|
T * |
lower2, |
|
|
T * |
upper2 |
|
) |
| |
|
inline |
| int Modulo |
( |
int |
a, |
|
|
int |
b |
|
) |
| |
|
inline |
Definition at line 106 of file helpers.h.
107 return (a % b + b) % b;
| void Reverse16 |
( |
void * |
ptr | ) |
|
|
inline |
Definition at line 137 of file helpers.h.
void ReverseN(void *ptr, int num_bytes)
| void Reverse32 |
( |
void * |
ptr | ) |
|
|
inline |
Definition at line 142 of file helpers.h.
void ReverseN(void *ptr, int num_bytes)
| void Reverse64 |
( |
void * |
ptr | ) |
|
|
inline |
Definition at line 147 of file helpers.h.
void ReverseN(void *ptr, int num_bytes)
| void ReverseN |
( |
void * |
ptr, |
|
|
int |
num_bytes |
|
) |
| |
|
inline |
Definition at line 126 of file helpers.h.
127 char *cptr =
reinterpret_cast<char *
>(ptr);
128 int halfsize = num_bytes / 2;
129 for (
int i = 0; i < halfsize; ++i) {
131 cptr[i] = cptr[num_bytes - 1 - i];
132 cptr[num_bytes - 1 - i] = tmp;
| int RoundUp |
( |
int |
n, |
|
|
int |
block_size |
|
) |
| |
|
inline |
Definition at line 58 of file helpers.h.
59 return block_size * ((n + block_size - 1) / block_size);
| void SkipNewline |
( |
FILE * |
file | ) |
|
|
inline |
Definition at line 41 of file helpers.h.
42 if (fgetc(file) !=
'\n') fseek(file, -1, SEEK_CUR);
| int sort_floats |
( |
const void * |
arg1, |
|
|
const void * |
arg2 |
|
) |
| |
|
inline |
Definition at line 46 of file helpers.h.
47 float diff = *((
float *) arg1) - *((
float *) arg2);
50 }
else if (diff < 0) {
template<typename T1 , typename T2 >
| void UpdateRange |
( |
const T1 & |
x, |
|
|
T2 * |
lower_bound, |
|
|
T2 * |
upper_bound |
|
) |
| |
|
inline |
template<typename T1 , typename T2 >
| void UpdateRange |
( |
const T1 & |
x_lo, |
|
|
const T1 & |
x_hi, |
|
|
T2 * |
lower_bound, |
|
|
T2 * |
upper_bound |
|
) |
| |
|
inline |
Definition at line 83 of file helpers.h.
85 if (x_lo < *lower_bound)
87 if (x_hi > *upper_bound)