Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

utils.h File Reference

#include <stdio.h>
#include "base/inttypes.h"
#include <iostream>

Go to the source code of this file.

Functions

static std::ostream & debug_cpptab (std::ostream &os, size_t n)
 Tabulation: print n spaces.
std::ostream & debug_cppPrintBitstring (std::ostream &out, const uint32_t *s, size_t n)
 Print bitstring, lower bits first.
std::ostream & debug_cppPrintBitMatrix (std::ostream &out, const uint32_t *s, cindex_t dim)
 Print a matrix of bit.
std::ostream & debug_cppPrintDiffBitstrings (std::ostream &out, const uint32_t *s1, const uint32_t *s2, size_t n)
 Print diff between bitstrings, lower bits first.
std::ostream & debug_cppPrintBits (std::ostream &out, uint32_t i)
 Print bits, lower bits first.
std::ostream & debug_cppPrintDiffBits (std::ostream &out, uint32_t i, uint32_t j)
 Print diff bits of i with j, lower bits first.
std::ostream & debug_cppPrintVector (std::ostream &out, const int32_t *data, size_t size)
 Print a vector of ints.
std::ostream & debug_cppPrintRealVector (std::ostream &out, const double *data, size_t size)
 Print a vector of ints.
std::ostream & debug_cppPrintDiffVectors (std::ostream &out, const int32_t *vec1, const int32_t *vec2, size_t size)
 Print 2 vectors and highlight the difference between them.
std::ostream & debug_cppPrintMemory (std::ostream &out, size_t mem)
 Print memory quantity in human readable format with B,MB,GB units.
std::ostream & debug_cppPrintActiveSet (std::ostream &out, const uint32_t *bits, size_t intSize)
 Print the set of active "things" according to a bit vector that marks which ones are active.
void debug_randomize (void *data, size_t intSize)
 Randomize memory.
static void debug_tab (FILE *out, size_t n)
 Tabulation: print n spaces.
void debug_printBitstring (FILE *out, const uint32_t *s, size_t n)
 Print bitstring, lower bits first.
void debug_printBitMatrix (FILE *out, const uint32_t *s, cindex_t dim)
 Print a bit matrix.
void debug_printDiffBitstrings (FILE *out, const uint32_t *s1, const uint32_t *s2, size_t n)
 Print diff between bitstrings, lower bits first.
void debug_printBits (FILE *out, uint32_t i)
 Print bits, lower bits first.
void debug_printDiffBits (FILE *out, uint32_t i, uint32_t j)
 Print diff bits of i with j, lower bits first.
void debug_printVector (FILE *out, const int32_t *data, size_t size)
 Print a vector of ints.
void debug_printRealVector (FILE *out, const double *data, size_t size)
 Print a vector of ints.
void debug_printDiffVectors (FILE *out, const int32_t *vec1, const int32_t *vec2, size_t size)
 Print 2 vectors and highlight the difference between them.
void debug_printActiveSet (FILE *out, const uint32_t *bits, size_t intSize)
 Print the set of active "things" according to a bit vector that marks which ones are active.
const char * debug_shortName (const char *filename, const char *test)
 Return sub-string of filename.
static const char * debug_shortSource (const char *filename)
void debug_generateBits (uint32_t *bits, size_t bitSize, size_t nbits, BOOL bit1)
 Generate random bits.
void debug_fixGeneratedBits (uint32_t *bits, size_t bitSize, size_t bitStringSize)
 Fix generated bits (typically by debug_generateBits) so that the index of the highest bit < bitStringSize.
BOOL debug_bits2indexTableOK (const uint32_t *bits, size_t n, const uint32_t *table, size_t nbSet)
 Test if a the unpacking of a bit table gives the given index table as a result.
void debug_printMemory (FILE *out, size_t mem)
 Print memory quantity in human readable format with B,MB,GB units.
void debug_spin (FILE *out)
 Print a spinning bar on a given output.


Function Documentation

BOOL debug_bits2indexTableOK const uint32_t *  bits,
size_t  n,
const uint32_t *  table,
size_t  nbSet
 

Test if a the unpacking of a bit table gives the given index table as a result.

Parameters:
table,: index redirection table
nbSet,: number of used indices (check that = number of bits in 'bits')
bits,: bit array
n,: size in int of the bit array
Returns:
true if table matches bits.
Precondition:
  • table is large enough: at least uint32_t[number of bits read == n*32]
  • bits is at least a uint32_t[n]

std::ostream& debug_cppPrintActiveSet std::ostream &  out,
const uint32_t *  bits,
size_t  intSize
 

Print the set of active "things" according to a bit vector that marks which ones are active.

Parameters:
out,: where to print.
bits,: bit array.
intSize,: size in ints of the array.

std::ostream& debug_cppPrintBitMatrix std::ostream &  out,
const uint32_t *  s,
cindex_t  dim
 

Print a matrix of bit.

Parameters:
out,: output stream.
s,dim,: bit matrix dimxdim.
Precondition:
s is a uint32_t[bits2intsize(dim*dim)]

std::ostream& debug_cppPrintBits std::ostream &  out,
uint32_t  i
 

Print bits, lower bits first.

Parameters:
i,: the int to print.
out,: output stream where to print (cerr,cout)

std::ostream& debug_cppPrintBitstring std::ostream &  out,
const uint32_t *  s,
size_t  n
 

Print bitstring, lower bits first.

Parameters:
s,: start of the string.
n,: size in int of the string to
out,: output stream where to print (cerr,cout) print. int[n] will be printed as bits.

std::ostream& debug_cppPrintDiffBits std::ostream &  out,
uint32_t  i,
uint32_t  j
 

Print diff bits of i with j, lower bits first.

Parameters:
i,j,: the ints to print.
out,: output stream where to print (cerr,cout)

std::ostream& debug_cppPrintDiffBitstrings std::ostream &  out,
const uint32_t *  s1,
const uint32_t *  s2,
size_t  n
 

Print diff between bitstrings, lower bits first.

Parameters:
s1,s2,: start of the strings.
n,: size in int of the string to
out,: output stream where to print (cerr,cout) print. int[n] will be printed as bits.

std::ostream& debug_cppPrintDiffVectors std::ostream &  out,
const int32_t *  vec1,
const int32_t *  vec2,
size_t  size
 

Print 2 vectors and highlight the difference between them.

Parameters:
vec1,vec2,: the vectors to print.
size,: size of the vectors.
out,: where t print.
Precondition:
vec1 and vec2 are int32_t[size]

std::ostream& debug_cppPrintMemory std::ostream &  out,
size_t  mem
 

Print memory quantity in human readable format with B,MB,GB units.

Parameters:
mem,: memory to print
out,: where to print.

std::ostream& debug_cppPrintRealVector std::ostream &  out,
const double *  data,
size_t  size
 

Print a vector of ints.

Parameters:
data,: the vector of ints.
size,: size of the vector.
out,: where to print.
Precondition:
data is a int32_t[size]

std::ostream& debug_cppPrintVector std::ostream &  out,
const int32_t *  data,
size_t  size
 

Print a vector of ints.

Parameters:
data,: the vector of ints.
size,: size of the vector.
out,: where to print.
Precondition:
data is a int32_t[size]

static std::ostream& debug_cpptab std::ostream &  os,
size_t  n
[inline, static]
 

Tabulation: print n spaces.

Parameters:
n,: size of the tabulation.
out,: output stream where to print (cerr, cout)

void debug_fixGeneratedBits uint32_t *  bits,
size_t  bitSize,
size_t  bitStringSize
 

Fix generated bits (typically by debug_generateBits) so that the index of the highest bit < bitStringSize.

Parameters:
bits,bitSize,: bitstring of size bitSize (ints)
bitStringSize,: size in bits of the bitstring
Precondition:
bitStringSize <= number of bits to keep == 1, otherwise bits will be lost.

void debug_generateBits uint32_t *  bits,
size_t  bitSize,
size_t  nbits,
BOOL  bit1
 

Generate random bits.

To the diffence of randomize, this function allows specifying the number of bits we want to be set.

Parameters:
bits,: bit string to write.
bitSize,: size in int of the bit string.
nbits,: nb of bits to set.
bit1,: to force the 1st bit to be set, if == 0, does not force anything, if == 1 force 1st bit to 1.
Precondition:
:
  • nbits <= 32*bitSize otherwise it is not possible to meet the specification
  • bits is a uint32_t[bitSize]

void debug_printActiveSet FILE *  out,
const uint32_t *  bits,
size_t  intSize
 

Print the set of active "things" according to a bit vector that marks which ones are active.

Parameters:
out,: where to print.
bits,: bit array.
intSize,: size in ints of the array.

void debug_printBitMatrix FILE *  out,
const uint32_t *  s,
cindex_t  dim
 

Print a bit matrix.

Parameters:
s,dim,: bit matrix dimxdim.
out,: output stream.
Precondition:
s is a uint32_t[bits2intsize(dim*dim)]

void debug_printBits FILE *  out,
uint32_t  i
 

Print bits, lower bits first.

Parameters:
i,: the int to print.
out,: output stream where to print (stderr,stdout)

void debug_printBitstring FILE *  out,
const uint32_t *  s,
size_t  n
 

Print bitstring, lower bits first.

Parameters:
s,: start of the string.
n,: size in int of the string to
out,: output stream where to print (stderr,stdout) print. int[n] will be printed as bits.

void debug_printDiffBits FILE *  out,
uint32_t  i,
uint32_t  j
 

Print diff bits of i with j, lower bits first.

Parameters:
i,j,: the ints to print.
out,: output stream where to print (stderr,stdout)

void debug_printDiffBitstrings FILE *  out,
const uint32_t *  s1,
const uint32_t *  s2,
size_t  n
 

Print diff between bitstrings, lower bits first.

Parameters:
s1,s2,: start of the strings.
n,: size in int of the string to
out,: output stream where to print (stderr,stdout) print. int[n] will be printed as bits.

void debug_printDiffVectors FILE *  out,
const int32_t *  vec1,
const int32_t *  vec2,
size_t  size
 

Print 2 vectors and highlight the difference between them.

Parameters:
vec1,vec2,: the vectors to print.
size,: size of the vectors.
out,: where t print.
Precondition:
vec1 and vec2 are int32_t[size]

void debug_printMemory FILE *  out,
size_t  mem
 

Print memory quantity in human readable format with B,MB,GB units.

Parameters:
mem,: memory to print
out,: where to print.

void debug_printRealVector FILE *  out,
const double *  data,
size_t  size
 

Print a vector of ints.

Parameters:
data,: the vector of ints.
size,: size of the vector.
out,: where to print.
Precondition:
data is a int32_t[size]

void debug_printVector FILE *  out,
const int32_t *  data,
size_t  size
 

Print a vector of ints.

Parameters:
data,: the vector of ints.
size,: size of the vector.
out,: where to print.
Precondition:
data is a int32_t[size]

void debug_randomize void *  data,
size_t  intSize
 

Randomize memory.

Write random numbers (rand()) in memory. NOTE: one should call seed(something) to initialize the random generator beforehand.

Parameters:
data,: where to write.
intSize,: size to write in int. Will write int[intSize].
Postcondition:
((int*)data)[intSize] is randomized.

const char* debug_shortName const char *  filename,
const char *  test
 

Return sub-string of filename.

No allocation, it is just a pointer offset.

Parameters:
filename,: filename to truncate.
test,: test directory name (typically "tests/") NOTE: the test is done as a strncmp(xx, test, strlen(test)) so if '/' is ommitted, then we test for the beginning of the name only.
Precondition:
filename != NULL && test != NULL
Returns:
pointer in filename to truncate from absolute path to module path. e.g.: "somewhere/hop/foo.c" -> "hop/foo.c" "somewhere/tests/foo.c" -> "somewhere/tests/foo.c" "long/path/here/foo.cpp" -> "here/foo.cpp"

static const char* debug_shortSource const char *  filename  )  [inline, static]
 

void debug_spin FILE *  out  ) 
 

Print a spinning bar on a given output.

Successive calls will make the bar spin.

Parameters:
out,: stream for output.

static void debug_tab FILE *  out,
size_t  n
[inline, static]
 

Tabulation: print n spaces.

Parameters:
n,: size of the tabulation.
out,: output stream where to print (stderr,stdout)


Generated on Fri Jun 30 00:02:51 2006 for Module debug by  doxygen 1.4.2