Classes
util.h File Reference

Interface of auxilliary utility functions for SDHLibrary-CPP. More...

#include <math.h>
#include <vector>
#include <algorithm>
#include <iostream>
#include "sdhlibrary_settings.h"
#include "simplevector.h"
Include dependency graph for util.h:

Go to the source code of this file.

Classes

class  cSetValueTemporarily< T >
 helper class to set value on construction and reset to previous value on destruction. (RAII-idiom) More...

Auxiliary functions

#define DEFINE_TO_CASECOMMAND(_c)   case _c: return (#_c)
#define DEFINE_TO_CASECOMMAND_MSG(_c,...)   case _c: return (#_c ": " __VA_ARGS__)
VCC_EXPORT bool InIndex (int v, int max)
VCC_EXPORT bool InRange (double v, double min, double max)
VCC_EXPORT bool InRange (int n, double const *v, double const *min, double const *max)
VCC_EXPORT double ToRange (double v, double min, double max)
VCC_EXPORT void ToRange (int n, double *v, double const *min, double const *max)
VCC_EXPORT void ToRange (std::vector< double > &v, std::vector< double > const &min, std::vector< double > const &max)
VCC_EXPORT void ToRange (cSimpleVector &v, std::vector< double > const &min, std::vector< double > const &max)
VCC_EXPORT double Approx (double a, double b, double eps)
VCC_EXPORT bool Approx (int n, double *a, double *b, double *eps)
VCC_EXPORT double DegToRad (double d)
VCC_EXPORT double RadToDeg (double r)
VCC_EXPORT void SleepSec (double t)
template<typename Function , typename Tp >
void apply (Function f, Tp &sequence)
template<typename Function , typename InputIterator >
Function apply (Function f, InputIterator first, InputIterator last)
template<typename Function , typename Tp >
Tp map (Function f, Tp sequence)
template<typename T >
std::ostream & operator<< (std::ostream &stream, std::vector< T > const &v)
VCC_EXPORT int CompareReleases (char const *rev1, char const *rev2)
 compare release strings

Detailed Description

Interface of auxilliary utility functions for SDHLibrary-CPP.

General file information

Author:
Dirk Osswald
Date:
2007-02-19

Copyright


Definition in file util.h.


Define Documentation

#define DEFINE_TO_CASECOMMAND (   _c)    case _c: return (#_c)

Just a macro for the very lazy programmer to convert an enum or a DEFINE macro into a case command that returns the name of the macro as string.

Usage:

 char const* eSomeEnumType_ToString( eSomeEnumType rc )
 {
   switch (rc)
   {
   DEFINE_TO_CASECOMMAND( AN_ENUM );
   DEFINE_TO_CASECOMMAND( AN_OTHER_ENUM );
   ...
   default:               return "unknown return code";
   }
 }
Remarks:
You must use the enum or macro directly (not a variable with that value) since CPP-stringification is used.

See also DEFINE_TO_CASECOMMAND_MSG

Definition at line 103 of file util.h.

#define DEFINE_TO_CASECOMMAND_MSG (   _c,
  ... 
)    case _c: return (#_c ": " __VA_ARGS__)

Just a macro for the very lazy programmer to convert an enum or a DEFINE macro and a message into a case command that returns the name of the macro and the message as string.

Usage:

 char const* eSomeEnumType_ToString( eSomeEnumType rc )
 {
   switch (rc)
   {
   DEFINE_TO_CASECOMMAND_MSG( AN_ENUM, "some mighty descriptive message" );
   DEFINE_TO_CASECOMMAND_MSG( AN_OTHER_ENUM, "guess what" );
   ...
   default:               return "unknown return code";
   }
 }
Remarks:
You must use the enum or macro directly (not a variable with that value) since CPP-stringification is used.

See also DEFINE_TO_CASECOMMAND

Definition at line 127 of file util.h.


Function Documentation

template<typename Function , typename Tp >
void apply ( Function  f,
Tp &  sequence 
)

Apply a function to every element of a sequence, the elements of the sequence are modified by f

Parameters:
fA unary function object.
sequenceThe iterable sequence to modify.

Applies the function object f to each element of the sequence.

Definition at line 221 of file util.h.

template<typename Function , typename InputIterator >
Function apply ( Function  f,
InputIterator  first,
InputIterator  last 
)

Apply a function to every element of a sequence.

Parameters:
firstAn input iterator.
lastAn input iterator.
fA unary function object.
Returns:
f.

Applies the function object f to each element in the range [first,last). f must not modify the order of the sequence. If f has a return value it is ignored.

Definition at line 249 of file util.h.

VCC_EXPORT double Approx ( double  a,
double  b,
double  eps 
)

Return True if a is approximately the same as b. I.E. |a-b| < eps

VCC_EXPORT bool Approx ( int  n,
double *  a,
double *  b,
double *  eps 
)

Return True if list/tuple/array a=(a1,a2,...) is approximately the same as b=(b1,b2,...). I.E. |a_i-b_i| < eps[i]

VCC_EXPORT int CompareReleases ( char const *  rev1,
char const *  rev2 
)

compare release strings

VCC_EXPORT double DegToRad ( double  d)

Return d in deg converted to rad

VCC_EXPORT bool InIndex ( int  v,
int  max 
)

Return True if v is in range [0 .. max[

VCC_EXPORT bool InRange ( double  v,
double  min,
double  max 
)

Return True if v is in range [min .. max]

VCC_EXPORT bool InRange ( int  n,
double const *  v,
double const *  min,
double const *  max 
)

Return True if in list/tuple/array v=(v1,v2,...) each v_i is in range [min_i..max_i] with min = (min1, min2,...) max = (max1, max2, ..)

template<typename Function , typename Tp >
Tp map ( Function  f,
Tp  sequence 
)

map a function to every element of a sequence, returning a copy with the mapped elements

Parameters:
f- A unary function object.
sequence- An iterable object.
Returns:
copy of sequence with the mapped elements

Definition at line 267 of file util.h.

template<typename T >
std::ostream& operator<< ( std::ostream &  stream,
std::vector< T > const &  v 
)

Overloaded insertion operator for vectors: a comma and space separated list of the vector elements of v is inserted into stream

Parameters:
stream- the output stream to insert into
v- the vector of objects to insert into stream
Returns:
the stream with the inserted objects
Attention:
If you use the SDH namespace then you should be aware that using this overloaded insertion operator can get tricky:
  • If you use a using namespace SDH directive then things are easy and intuitive:
         #include <sdh/util.h>
         using namespace SDH;
         std::vector<int> v;
         std::cout << "this is a std::vector: " << v << "\n";
    
  • But without the using namespace SDH accessing the operator is tricky, you have to use the 'functional' access operator<<(s,v) in order to be able to apply the scope resolution operator :: correctly:
         #include <sdh/util.h>
         std::vector<int> v;
         SDH::operator<<( std::cout << "this is a std::vector: ", v ) << "\n";
    
  • The more intuitive approaches do not work:
         std::cout << faa ;                // obviously fails with "no match for >>operator<<<< in >>std::cout << faa<<", as expected
         std::cout SDH::<< faa ;           // is a syntax error
         std::cout SDH::operator<< faa ;   // is a syntax error
         std::cout operator SDH::<< faa ;  // is a syntax error
    

Definition at line 311 of file util.h.

VCC_EXPORT double RadToDeg ( double  r)

Return r in rad converted to deg

VCC_EXPORT void SleepSec ( double  t)

Sleep for t seconds. (t is a double!)

VCC_EXPORT double ToRange ( double  v,
double  min,
double  max 
)

Return v limited to range [min .. max]. I.e. if v is < min then min is returned, or if v > max then max is returned, else v is returned

VCC_EXPORT void ToRange ( int  n,
double *  v,
double const *  min,
double const *  max 
)

Limit each v_i in v to range [min_i..max_i] with min = (min1, min2,...) max = (max1, max2, ..) This modifies *v!

VCC_EXPORT void ToRange ( std::vector< double > &  v,
std::vector< double > const &  min,
std::vector< double > const &  max 
)

Limit each v_i in v to range [min_i..max_i] with min = (min1, min2,...) max = (max1, max2, ..) This modifies v!

VCC_EXPORT void ToRange ( cSimpleVector v,
std::vector< double > const &  min,
std::vector< double > const &  max 
)

Limit each v_i in v to range [min_i..max_i] with min = (min1, min2,...) max = (max1, max2, ..) This modifies v!



schunk_sdh
Author(s): Mathias Luedtke , Florian Weisshardt
autogenerated on Thu Aug 27 2015 15:07:03