Voxel
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator Macros Pages
Macros | Functions
helpers.h File Reference

Contains helper macros and functions. More...

#include <string>
#include <cctype>
#include <stdint.h>

Go to the source code of this file.

Macros

#define HELPERS_H
#define ARRAYLENGTH(aa)   ( sizeof( aa ) / sizeof( ( aa )[ 0 ] ) )
 Calculates the number of elements in the array aa by dividing the size of aa by the size of each element.
#define STDCALL   __stdcall
#define ALIGN(aa)   __declspec( align( aa ) )

Functions

template<typename t_Type >
t_Type Square (t_Type const &value)
 Returns the square of its argument.
template<typename t_Type >
t_Type Cube (t_Type const &value)
 Returns the cube of its argument.
std::string CollapseWhitespace (std::string const &source, char const space= ' ')
 Removes leading/trailing whitespace, and collapses internal whitespace.
uint8_t CountBits (uint8_t number)
 Returns the number of set bits in an 8-bit integer.
uint16_t CountBits (uint16_t number)
 Returns the number of set bits in a 16-bit integer.
uint32_t CountBits (uint32_t number)
 Returns the number of set bits in a 32-bit integer.
uint64_t CountBits (uint64_t number)
 Returns the number of set bits in a 64-bit integer.
unsigned int CountLowBits (uint8_t number)
 Returns the number of bits required to represent the given 8-bit integer. The number of bits required to represent 0 is taken to be 0.
unsigned int CountLowBits (uint16_t number)
 Returns the number of bits required to represent the given 16-bit integer. The number of bits required to represent 0 is taken to be 0.
unsigned int CountLowBits (uint32_t number)
 Returns the number of bits required to represent the given 32-bit integer. The number of bits required to represent 0 is taken to be 0.
unsigned int CountLowBits (uint64_t number)
 Returns the number of bits required to represent the given 64-bit integer. The number of bits required to represent 0 is taken to be 0.

Detailed Description

Contains helper macros and functions.

Definition in file helpers.h.

Function Documentation

std::string CollapseWhitespace ( std::string const &  source,
char const  space = ' ' 
)
inline

Removes leading/trailing whitespace, and collapses internal whitespace.

Parameters
sourceString in which to collapse whitespace.
spaceCharacter with which to replace internal stretches of whitespace.
Returns
String with leading/trailing whitespace removed, and internal whitespace collapsed.

The purpose of this function is to make strings which may contain leading/trailing whitespace, and annoying stretches of internal space (including newlines and tabs), somewhat "cleaner" to print or display in a dialog. In addition to the removal of leading and trailing whitespace, all "stretches" of consecutive whitespace characters (found using std::isspace) in the interior of the string will be replaced with (one copy of) the given space character.

Definition at line 113 of file helpers.h.