src/main/functions.h File Reference

Helping functions headers. More...

#include <ctime>
#include <cstdlib>
#include <string>
#include <iostream>
#include <map>
#include "exceptions.h"
#include "config.h"

Go to the source code of this file.

Defines

#define PACKAGE   "dreamcache"
 name of the package - 'dreamcache'
#define PREFIX   "/"
 prefix that dreamcache was configured with
#define CONFDIR   PREFIX "/etc/" PACKAGE
 location of the configuration files
#define VERSION   "0.0"
 current version of dreamcache
#define NUM_LENGTH(n)   (n ? (int) log10((float) n) + 1: 1)
 takes integer and calculates its digit count
#define MUTEX_LOCK(m)
 locks POSIX mutex
#define MUTEX_UNLOCK(m)
 unlocks POSIX mutex

Functions

double diffTimes (timeval *t1, timeval *t2)
 Calculates the difference between two given moments in time.
int extractValue (const string &s, unsigned offset, const string &confFilename, int line) throw (ConfigSemanticException)
 Extract numeric value from the given string.
std::string removeBlanks (string s)
 Trims given string from left and right side and throwing out the comment (starting in #).
bool safe_strtoull (const char *str, uint64_t *out)
 Checks whether the given string begins with a valid unsigned value and writes the value to the out parameter.
std::string pend_spaces_2_numb (unsigned long long val, unsigned count, bool append)
 Deprecated ;).
template<typename T, typename L>
ostream & operator<< (ostream &out, pair< T, L > &p)
 Writes the given pair of objects to the out output.
ostream & operator<< (ostream &out, map< int, char > &mymap)
 Writes the given map to the out output.
string configurationDirectory (char *directory=NULL)
 Returns the configuration directory read from the config.h created during configure - default: '/etc/dreamcache'.
string getPackageName ()
 Returns the package name from the config.h created during .


Detailed Description

Helping functions headers.

Definition in file functions.h.


Define Documentation

#define MUTEX_LOCK (  ) 

Value:

if (pthread_mutex_lock(&m)) { \
        perror("WARNING !!!: pthread_mutex_lock"); \
}
locks POSIX mutex

Definition at line 148 of file functions.h.

#define MUTEX_UNLOCK (  ) 

Value:

if (pthread_mutex_unlock(&m)) { \
        perror("WARNING !!!: pthread_mutex_unlock"); \
}
unlocks POSIX mutex

Definition at line 155 of file functions.h.


Function Documentation

string configurationDirectory ( char *  directory = NULL  ) 

Returns the configuration directory read from the config.h created during configure - default: '/etc/dreamcache'.

Pass argc and argv from the main() function to let user overwrite it.

Parameters:
directory pass configuration directory path to override the default

Definition at line 139 of file functions.cpp.

double diffTimes ( timeval *  t1,
timeval *  t2 
)

Calculates the difference between two given moments in time.

Returns:
the difference in seconds

Definition at line 15 of file functions.cpp.

int extractValue ( const string &  s,
unsigned  offset,
const string &  confFilename,
int  line 
) throw (ConfigSemanticException)

Extract numeric value from the given string.

Reads an integral value from the offset position of the string s and ensures there is no further input in s.

Parameters:
s string to extract numeric value from
offset offset in s from which to start extracting the value
confFilename configuration file currently read to give this information within the exception
line currently read configuration file line to give this information within the exception
Returns:
extracted value
Parameters:
s Read string
offset position of the value to be read
confFilename Configuration file currently parsed
line Line of the configuration file currently parsed
Returns:
Parsed integer
Exceptions:
ConfigSemanticException When there is no integer at given position.
Extract numeric value from the given string.

Parameters:
s Read string
offset position of the value to be read
confFilename Configuration file currently parsed
line Line of the configuration file currently parsed
Returns:
Parsed integer
Exceptions:
ConfigSemanticException When there is no integer at given position.

Definition at line 19 of file functions.cpp.

string getPackageName (  ) 

Returns the package name from the config.h created during .

/configure - default: 'dreamcache'

Definition at line 154 of file functions.cpp.

ostream& operator<< ( ostream &  out,
map< int, char > &  mymap 
)

Writes the given map to the out output.

Parameters:
out the output
mymap the map

Definition at line 128 of file functions.cpp.

template<typename T, typename L>
ostream& operator<< ( ostream &  out,
pair< T, L > &  p 
) [inline]

Writes the given pair of objects to the out output.

Parameters:
out the output
p the pair

Definition at line 124 of file functions.cpp.

std::string removeBlanks ( string  s  ) 

Trims given string from left and right side and throwing out the comment (starting in #).

Parameters:
s Input string
Returns:
string without a comment and whitespaces at both ends

Definition at line 38 of file functions.cpp.

bool safe_strtoull ( const char *  str,
uint64_t *  out 
)

Checks whether the given string begins with a valid unsigned value and writes the value to the out parameter.

Parameters:
str string to extract the value from
out 64-bit variable pointer where the value will be written

Definition at line 75 of file functions.cpp.


Generated on Fri Jan 8 10:38:13 2010 for dreamcache by  doxygen 1.5.5