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"
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 | |
Interface of auxilliary utility functions for SDHLibrary-CPP.
Definition in file util.h.
| #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"; } }
See also DEFINE_TO_CASECOMMAND_MSG
| #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"; } }
See also DEFINE_TO_CASECOMMAND
| void apply | ( | Function | f, | 
| Tp & | sequence | ||
| ) | 
| Function apply | ( | Function | f, | 
| InputIterator | first, | ||
| InputIterator | last | ||
| ) | 
Apply a function to every element of a sequence.
| first | An input iterator. | 
| last | An input iterator. | 
| f | A unary function object. | 
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. 
| 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, ..)
| Tp map | ( | Function | f, | 
| Tp | sequence | ||
| ) | 
| 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
| stream | - the output stream to insert into | 
| v | - the vector of objects to insert into stream | 
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";
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 #include <sdh/util.h> std::vector<int> v; SDH::operator<<( std::cout << "this is a std::vector: ", v ) << "\n";
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
| 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!