Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions
helpers.h File Reference
`#include <stdio.h>`
`#include <string.h>`

Go to the source code of this file.

## Functions
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)

## Function Documentation

void chomp_string | ( | char * | str | ) |
| inline

Definition at line 32 of file helpers.h.

{
int last_index = strlen(str) - 1;
while (last_index >= 0 &&
(str[last_index] == '\n' || str[last_index] == '\r')) {
str[last_index--] = '\0';
}
}
template<typename T >

T ClipToRange | ( | const T & | x,
|  | const T & | lower_bound,
|  | const T & | upper_bound
| ) |  |
| inline

Definition at line 64 of file helpers.h.

{
if (x < lower_bound)
return lower_bound;
if (x > upper_bound)
return upper_bound;
return x;
}

int DivRounded | ( | int | a,
|  | int | b
| ) |  |
| inline

Definition at line 115 of file helpers.h.

{
if (b < 0) return -DivRounded(a, -b);
return a >= 0 ? (a + b / 2) / b : (a - b / 2) / b;
}

int IntCastRounded | ( | double | x | ) |
| inline

Definition at line 121 of file helpers.h.

{
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

Definition at line 95 of file helpers.h.

{
if (lower1 > *lower2)
*lower2 = lower1;
if (upper1 < *upper2)
*upper2 = upper1;
}

int Modulo | ( | int | a,
|  | int | b
| ) |  |
| inline

Definition at line 106 of file helpers.h.

{
return (a % b + b) % b;
}

void Reverse16 | ( | void * | ptr | ) |
| inline

Definition at line 137 of file helpers.h.

{
ReverseN(ptr, 2);
}

void Reverse32 | ( | void * | ptr | ) |
| inline

Definition at line 142 of file helpers.h.

{
ReverseN(ptr, 4);
}

void Reverse64 | ( | void * | ptr | ) |
| inline

Definition at line 147 of file helpers.h.

{
ReverseN(ptr, 8);
}

void ReverseN | ( | void * | ptr,
|  | int | num_bytes
| ) |  |
| inline

Definition at line 126 of file helpers.h.

{
char *cptr = reinterpret_cast<char *>(ptr);
int halfsize = num_bytes / 2;
for (int i = 0; i < halfsize; ++i) {
char tmp = cptr[i];
cptr[i] = cptr[num_bytes - 1 - i];
cptr[num_bytes - 1 - i] = tmp;
}
}

int RoundUp | ( | int | n,
|  | int | block_size
| ) |  |
| inline

Definition at line 58 of file helpers.h.

{
return block_size * ((n + block_size - 1) / block_size);
}

void SkipNewline | ( | FILE * | file | ) |
| inline

Definition at line 41 of file helpers.h.

{
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.

{
float diff = *((float *) arg1) - *((float *) arg2);
if (diff > 0) {
return 1;
} else if (diff < 0) {
return -1;
} else {
return 0;
}
}
template<typename T1 , typename T2 >

void UpdateRange | ( | const T1 & | x,
|  | T2 * | lower_bound,
|  | T2 * | upper_bound
| ) |  |
| inline

Definition at line 74 of file helpers.h.

{
if (x < *lower_bound)
*lower_bound = x;
if (x > *upper_bound)
*upper_bound = x;
}
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.

{
if (x_lo < *lower_bound)
*lower_bound = x_lo;
if (x_hi > *upper_bound)
*upper_bound = x_hi;
}