Programming tasks to Scientific Computing I
Namespaces | Classes | Functions
aol Namespace Reference

Namespaces

 color
 table of ansi color codes
 

Classes

class  Op
 

Functions

string strprintf (const char *format,...)
 Give back formatted string, analogously to sprintf, but save the long way 'round with char arrays. More...
 
void makeDirectory (const char *DirectoryName, bool verbose)
 
bool fileExists (string filename)
 
template<class T >
Min (const T a, const T b)
 
template<class T >
Max (const T a, const T b)
 
template<class T >
Clamp (const T Value, const T Min, const T Max)
 
template<class T >
Sqr (const T a)
 
template<class T >
signum (const T x)
 Signum function template, signum ( 0 ) = 0. More...
 
bool fileExists (std::string filename)
 

Function Documentation

template<class T >
T aol::Clamp ( const T  Value,
const T  Min,
const T  Max 
)
inline

Definition at line 132 of file aol.h.

132 { return ( aol::Max ( aol::Min ( Value, Max ), Min ) ); }
T Min(const T a, const T b)
Definition: aol.h:129
T Max(const T a, const T b)
Definition: aol.h:130
bool aol::fileExists ( string  filename)

Definition at line 44 of file aol.cpp.

44  {
45  struct stat buf;
46  return !stat ( filename.c_str (), &buf ) && S_ISREG ( buf.st_mode );
47 }
bool aol::fileExists ( std::string  filename)
void aol::makeDirectory ( const char *  DirectoryName,
bool  verbose 
)

Definition at line 27 of file aol.cpp.

27  {
28  struct stat directory;
29  const int statReturn = stat ( DirectoryName, &directory );
30  if ( ( statReturn == - 1 ) || !S_ISDIR ( directory.st_mode ) ) {
31  string systemCommand = "mkdir \"";
32  systemCommand += DirectoryName;
33  systemCommand += "\"";
34  if ( system ( systemCommand.c_str() ) != EXIT_SUCCESS )
35  cerr << "aol::makeDirectory: Calling '" << systemCommand << "' returned an error.\n";
36  if ( verbose )
37  cerr << "Created directory " << DirectoryName << endl;
38  } else {
39  if ( verbose )
40  cerr << "Directory " << DirectoryName << " already exists\n";
41  }
42 }
template<class T >
T aol::Max ( const T  a,
const T  b 
)
inline

Definition at line 130 of file aol.h.

130 { return ( ( a < b ) ? b : a ); }
template<class T >
T aol::Min ( const T  a,
const T  b 
)
inline

Definition at line 129 of file aol.h.

129 { return ( ( a < b ) ? a : b ); }
template<class T >
T aol::signum ( const T  x)
inline

Signum function template, signum ( 0 ) = 0.

Definition at line 137 of file aol.h.

137  {
138  if (x > 0.0) return 1;
139  else if (x == 0.0) return 0;
140  else if (x < 0.0) return -1;
141  return x; // NaN
142 }
template<class T >
T aol::Sqr ( const T  a)
inline

Definition at line 134 of file aol.h.

134 { return a * a; }
string aol::strprintf ( const char *  format,
  ... 
)

Give back formatted string, analogously to sprintf, but save the long way 'round with char arrays.

Definition at line 5 of file aol.cpp.

5  {
6  // declare variable argument list
7  va_list az;
8  // copy from my input into this list(second argument is nothing really used, but the last named argument of myself)
9  va_start(az, format);
10  // give this argument list variable to vscprintf instead of my own arguments (that is in what functions like vsprintf differ from functions like sprintf)
11  const int sizeNeeded = vsnprintf ( NULL, 0, format, az ) + 1;
12  // restore stack into clean state:
13  va_end(az);
14 
15  char *buffer = new char[sizeNeeded];
16 
17  va_start(az, format);
18  vsprintf (buffer, format, az);
19  va_end(az);
20 
21  // automatic return type conversion into string:
22  string ret = buffer;
23  delete[] buffer;
24  return ret;
25 }