Tools.h File Reference

Set of useful functions, in particular to convert data to/from string. More...

Defines

#define EXTRACT_BIT(n, i)   ((n&(1<<i))?1:0)

Functions

template<typename T >
bool isnan (const T &value)
template<typename T >
bool isinf (const T &value)
template<typename T >
bool isninf (const T &value)
std::pair< double, double > stDev (const std::vector< double > &)
std::pair< long double, long
double > 
stDevLD (const std::vector< long double > &)
double roundDecimal (double toRound, unsigned short places)
template<class T >
void clearVectorOfPointers (std::vector< T * > &vec)
template<class T >
std::ostream & operator<< (std::ostream &os, const std::vector< T > &v)
size_t splitFrom (std::string s, std::string sep, std::vector< std::string > &v)
unsigned long ones32 (register unsigned long x)
unsigned long lzc (register unsigned long x)
unsigned long tzc (register unsigned long x)
template<class T >
FromStringTo (const std::string &s)
template<class T >
std::string ToStringFrom (const T &t)
template<class T >
std::string ToStringFrom (const std::vector< T > &t)
std::string dateToString ()
std::string padSpaces (const std::string &toPad, const size_t &pads)
template<class T >
std::string vecToString (const std::vector< T > &vec)

Detailed Description

Set of useful functions, in particular to convert data to/from string.

Author:
Sebastien Varrette <Sebastien.Varrette@imag.fr> Marek Ostaszewski <Marek.Ostaszewski@uni.lu>
Date:
Thu Dec 27 2007

Copyright (c) 2007 Sebastien Varrette, Marek Ostaszewski (see COPYING)


Define Documentation

#define EXTRACT_BIT ( n,
 )     ((n&(1<<i))?1:0)

Function Documentation

template<class T >
void clearVectorOfPointers ( std::vector< T * > &  vec  )  [inline]

Manages clearing the vector of pointers (

Parameters:
vec). For every element invokes destructor and then changes the pointer to NULL.
std::string dateToString (  ) 
template<class T >
T FromStringTo ( const std::string &  s  )  [inline]

FromStringTo convert a string to a value of type T Example : int i = FromStringTo<int>(s)

Parameters:
s string to convert
Returns:
value of type T corresponding to the conversion of s to this type
template<typename T >
bool isinf ( const T &  value  )  [inline]
template<typename T >
bool isnan ( const T &  value  )  [inline]
template<typename T >
bool isninf ( const T &  value  )  [inline]
unsigned long lzc ( register unsigned long  x  )  [inline]

Count the number of leading zeroes in a 32-bit wide integer.

Code taken from the "Leading Zero Count" algorithm at http://aggregate.org/MAGIC/

Parameters:
x the value to test.
Returns:
the number of leading zeroes in x.
unsigned long ones32 ( register unsigned long  x  )  [inline]

Count the number of bits that are set in a 32-bit wide integer.

Code taken from the "Population Count (Ones Count)" algorithm at http://aggregate.org/MAGIC/

Note: this solution appears to be faster even compared to the "Parallel Count" and "MIT HACKMEM Count" from: http://www-db.stanford.edu/~manku/bitcount/bitcount.html

Parameters:
x the value to test.
Returns:
the number of bits that are set in x.
template<class T >
std::ostream& operator<< ( std::ostream &  os,
const std::vector< T > &  v 
) [inline]

Helpful function to print directly the content of a vector in an output stream

std::string padSpaces ( const std::string &  toPad,
const size_t &  pads 
)
double roundDecimal ( double  toRound,
unsigned short  places 
)
size_t splitFrom ( std::string  s,
std::string  sep,
std::vector< std::string > &  v 
)

Split the string s, using a list of separators specified in sep. The result is stored in the vector v.

Parameters:
s the string to split
sep list of separators to consider, " ." for instance to consider ' ' and '.' as separators
v the vectors containing the result of the split
Returns:
number of elements in v
std::pair<double,double> stDev ( const std::vector< double > &   ) 
std::pair<long double,long double> stDevLD ( const std::vector< long double > &   ) 
template<class T >
std::string ToStringFrom ( const std::vector< T > &  t  )  [inline]
template<class T >
std::string ToStringFrom ( const T &  t  )  [inline]

ToStringFrom convert any value v of type T to string Exemple: string s = ToStringFrom(14)

Parameters:
t value to convert
Returns:
a string corresponding to v
unsigned long tzc ( register unsigned long  x  )  [inline]

Count the number of trailing zeroes in a 32-bit wide integer.

Code taken from the "Trailing Zero Count" algorithm at http://aggregate.org/MAGIC/

Parameters:
x the value to test.
Returns:
the number of trailing zeroes in x.
template<class T >
std::string vecToString ( const std::vector< T > &  vec  )  [inline]

Generated on Fri Dec 11 22:28:17 2009 for LibGEP by  doxygen 1.6.1