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

CppTools.hpp File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <typeinfo>
#include <boost/preprocessor/arithmetic/inc.hpp>
#include <boost/preprocessor/punctuation/comma_if.hpp>
#include <boost/preprocessor/repetition.hpp>
#include <iostream>
#include <stdarg.h>
#include <math.h>
#include <sys/time.h>
#include <time.h>

Include dependency graph for CppTools.hpp:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  std

Defines

#define deprecated
#define VARARG_TYPE_CONVERSION_ARGLIST(Z, INDEX, DATA)   const T ## INDEX & a ## INDEX
#define VARARG_TYPE_CONVERSION_TYPE_CONVERSION_MACRO(Z, INDEX, DATA)   VarArgTypeConversion<T ## INDEX>::Convert(a ## INDEX)
#define ThrowError_MACRO(INDEX)
#define mprintf_MACRO(INDEX)
#define SPrintf_MACRO(INDEX)

Typedefs

typedef unsigned char byte
typedef unsigned int uint

Enumerations

enum  ErrorManagementType { ERROR_USE_EXCEPTIONS, ERROR_SEGFAULT, ERROR_CALL_HANDLER }

Functions

void SetErrorManagementType (ErrorManagementType _errorManagementType, void(*_ErrorHandler)(string)=NULL)
 Change the error management policy, default is ERROR_SEGFAULT (good for debuging).
void ThrowErrorVA (const char *fmt,...)
 A Fatal error occured, print a message and fail.
 ThrowError_MACRO (1) ThrowError_MACRO(7) ThrowError_MACRO(13) ThrowError_MACRO(2) ThrowError_MACRO(8) ThrowError_MACRO(14) ThrowError_MACRO(3) ThrowError_MACRO(9) ThrowError_MACRO(15) ThrowError_MACRO(4) ThrowError_MACRO(10) ThrowError_MACRO(16) ThrowError_MACRO(5) ThrowError_MACRO(11) ThrowError_MACRO(17) ThrowError_MACRO(6) ThrowError_MACRO(12) ThrowError_MACRO(18) inline void ThrowError(const char *fmt)
 mprintf_MACRO (1) mprintf_MACRO(7) mprintf_MACRO(13) mprintf_MACRO(2) mprintf_MACRO(8) mprintf_MACRO(14) mprintf_MACRO(3) mprintf_MACRO(9) mprintf_MACRO(15) mprintf_MACRO(4) mprintf_MACRO(10) mprintf_MACRO(16) mprintf_MACRO(5) mprintf_MACRO(11) mprintf_MACRO(17) mprintf_MACRO(6) mprintf_MACRO(12) mprintf_MACRO(18) inline void mprintf(const char *fmt)
name String related tools
string 
SPrintfVA (const char *fmt,...)
 Create a string using mprintf vararg format.
 SPrintf_MACRO (1) SPrintf_MACRO(7) SPrintf_MACRO(13) SPrintf_MACRO(2) SPrintf_MACRO(8) SPrintf_MACRO(14) SPrintf_MACRO(3) SPrintf_MACRO(9) SPrintf_MACRO(15) SPrintf_MACRO(4) SPrintf_MACRO(10) SPrintf_MACRO(16) SPrintf_MACRO(5) SPrintf_MACRO(11) SPrintf_MACRO(17) SPrintf_MACRO(6) SPrintf_MACRO(12) SPrintf_MACRO(18) inline string SPrintf(const char *fmt)
void Replace (string &res, const string &s1, const string &s2)
 Replace s1 by s2 in res.
void Replace (string &res, const string &s1, const char *s2)
 Replace s1 by s2 in res, s2 can be NULL.
int Split (const string &s, char c, vector< string > &res)
 Split string s into result res. separator is c.
int Split (const string &s, vector< string > &res)
 Split string s into result res. separator is ONE whitespace.
int Split (const string &s, const string &sep, vector< string > &res)
 Split string s into result res. separator is sep.
int Read (const string &fname, string &res, bool fail=false)
 Read file into string.
void * Read (const string &fname, int *size=NULL, bool fail=false)
 Read file into void *.
void Write (const string &fname, void *data, int size, bool fail=false)
 Write binary data into file.
string Chop (const string &s, char c)
 Chops the last part of a string s that comes after the separator c.
long int LongInt (const string &s)
 Convert a string to a long int.
unsigned long int LongUInt (const string &s)
 Convert a string to a long unsigned int.
double Double (const string &s)
 Convert a string to a double.
float Float (const string &s)
 Convert a string to a float.
name Convert a list of string
arguments into a vector of
strings vector< string > 
Strings (string s1, string s2, string s3, string s4, string s5, string s6, string s7, string s8, string s9, string s10)
vector< string > Strings (string s1, string s2, string s3, string s4, string s5, string s6, string s7, string s8, string s9)
vector< string > Strings (string s1, string s2, string s3, string s4, string s5, string s6, string s7, string s8)
vector< string > Strings (string s1, string s2, string s3, string s4, string s5, string s6, string s7)
vector< string > Strings (string s1, string s2, string s3, string s4, string s5, string s6)
vector< string > Strings (string s1, string s2, string s3, string s4, string s5)
vector< string > Strings (string s1, string s2, string s3, string s4)
vector< string > Strings (string s1, string s2, string s3)
vector< string > Strings (string s1, string s2)
vector< string > Strings (string s1)
vector< string > Strings ()
name File related tools bool IsSameFile (string filename1, string filename2)
 checks if two files are identical, really the same file... same inode
bool FileIsMoreRecent (const string &filename1, const string &filename2)
 compares mtimes (modif times) of two files
string WriteTmpFile (const string &data="")
 Write data into a temp file who's name is returned.
void WriteStringToFile (const string &fname, const string &data)
 Write data into a file.
string FilenameExtension (const string &fname)
 Returns the part of the string that comes after the last '.' symbol.
string FilenamePath (const string &fname)
 Returns the path of a unix filename: all that comes before and includes the last '/'-symbol.
string FilenameBasename (const string &fname)
 Returns all that comes after the last '/'-symbol.
ostream & operator<< (ostream &out, const vector< string > &v)
 Output stream operator for vector<string>.
int FileSize (const string &fname)
 returns the size of a file (-1 on fail)
void AppendToFile (const string &fname, const string &data)
 Adds a string at the end of a file.
bool FileExists (const string &fName)
string FindFileInPath (const string &path, const string &fname)
string FindFileInPath (const vector< string > &path, const string &fname)
string FindFileInPath (const char *path, const string &fname)
name Unix commands void RemoveFile (string fname)
 Unix rm commands.
void RemoveFiles (const vector< string > &fnames)
string Command (const string &cmd)
 execute a command and put it's output in string
name External Unix programs
void 
GnuPlot (const vector< double > &x, const vector< double > &y, const string &xlabel="", const string &ylabel="")
void GnuPlot (const vector< double > &y, const string &ylabel="")
void GnuPlot (const vector< float > &x, const vector< float > &y, const string &xlabel="", const string &ylabel="")
void GnuPlot (const vector< float > &y, const string &ylabel="")
name Time related tools double DTime ()
 Current time in seconds.
double DTime (double T0)
 Current time in seconds relative to T0.
template<class T1, class T2>
name Runtime type information
bool 
IsSameType ()
 runtime type compare
string TypeNameParser (string typeName)
 will parse the string returned by typeid, and try to build something portable (very random!!)
template<class T>
string TypeName ()
template<>
string TypeName< float > ()
template<>
string TypeName< double > ()
template<>
string TypeName< byte > ()
template<>
string TypeName< int > ()
template<>
string TypeName< short int > ()
template<>
string TypeName< string > ()
name Endianess bool IsSmallEndian ()
 Returns true if most significant byte is the last byte on this system.
template<class T>
void ReverseEndian (const T &src, T &dst)
template<class Im3DValue>
name Math Im3DValue AbsoluteValue (const Im3DValue &v)
template<>
double AbsoluteValue< double > (const double &v)
template<>
float AbsoluteValue< float > (const float &v)
template<>
int AbsoluteValue< int > (const int &v)
template<>
long int AbsoluteValue< long int > (const long int &v)
template<>
short int AbsoluteValue< short int > (const short int &v)
template<>
byte AbsoluteValue< byte > (const byte &v)
double RandomDouble (double vmin, double vmax)
double RandomDouble ()

Variables

name Debug output int globalVerbose


Detailed Description

Definition in file CppTools.hpp.


Define Documentation

#define ThrowError_MACRO INDEX   ) 
 

Value:

template< BOOST_PP_ENUM_PARAMS ( INDEX  , class T  )> \
void ThrowError( const char *fmt,BOOST_PP_ENUM(INDEX,VARARG_TYPE_CONVERSION_ARGLIST, unused) ) \
{ ThrowErrorVA(fmt,BOOST_PP_ENUM(INDEX,VARARG_TYPE_CONVERSION_TYPE_CONVERSION_MACRO, unused)); }

Definition at line 90 of file CppTools.hpp.

#define mprintf_MACRO INDEX   ) 
 

Value:

template< BOOST_PP_ENUM_PARAMS ( INDEX  , class T  )> \
void mprintf( const char *fmt,BOOST_PP_ENUM(INDEX,VARARG_TYPE_CONVERSION_ARGLIST,(T,a )) ) \
{ if(globalVerbose)printf(fmt,BOOST_PP_ENUM(INDEX,VARARG_TYPE_CONVERSION_TYPE_CONVERSION_MACRO,a)); }

Definition at line 112 of file CppTools.hpp.

#define SPrintf_MACRO INDEX   ) 
 

Value:

template< BOOST_PP_ENUM_PARAMS ( INDEX  , class T  )> \
string SPrintf( const char *fmt,BOOST_PP_ENUM(INDEX,VARARG_TYPE_CONVERSION_ARGLIST,(T,a )) ) \
{ return SPrintfVA(fmt,BOOST_PP_ENUM(INDEX,VARARG_TYPE_CONVERSION_TYPE_CONVERSION_MACRO,a)); }

Definition at line 133 of file CppTools.hpp.


Function Documentation

void Replace string &  res,
const string &  s1,
const string &  s2
 

Replace s1 by s2 in res.

(this should be done much more efficiently...)

Definition at line 355 of file CppTools.cpp.

string Chop const string &  s,
char  c
 

Chops the last part of a string s that comes after the separator c.

<long-description> returns chopped string including the c character, s remains untouched.

Parameters:
s 
c 
Returns:
<returnvalue>

Definition at line 550 of file CppTools.cpp.

References Split().

string FilenameExtension const string &  fname  ) 
 

Returns the part of the string that comes after the last '.' symbol.

If there is no '.' (dot), an empty string will be returned ("");

Definition at line 495 of file CppTools.cpp.

References Split().

ostream& operator<< ostream &  out,
const vector< string > &  v
 

Output stream operator for vector<string>.

<long-description> Each element of v will be outputed on a separate line

Parameters:
v.begin( 

Definition at line 535 of file CppTools.cpp.

string TypeNameParser string  typeName  ) 
 

will parse the string returned by typeid, and try to build something portable (very random!!)

unmangling a name can be quite long, so results are cached...

Definition at line 38 of file CppTools.cpp.

References Command().


Generated on Fri Jun 17 13:36:13 2005 for ImLib3D by  doxygen 1.4.2