util.h
Go to the documentation of this file.
00001 //======================================================================
00028 //======================================================================
00029 
00030 #ifndef UTIL_H_
00031 #define UTIL_H_
00032 
00033 
00034 //----------------------------------------------------------------------
00035 // System Includes - include with <>
00036 //----------------------------------------------------------------------
00037 
00038 #include <math.h>
00039 #include <vector>
00040 #include <algorithm>
00041 #include <iostream>
00042 
00043 //----------------------------------------------------------------------
00044 // Project Includes - include with ""
00045 //----------------------------------------------------------------------
00046 
00047 #include "sdhlibrary_settings.h"
00048 #include "simplevector.h"
00049 
00050 //----------------------------------------------------------------------
00051 // Defines, enums, unions, structs,
00052 //----------------------------------------------------------------------
00053 
00054 NAMESPACE_SDH_START
00055 
00056 
00057 //----------------------------------------------------------------------
00058 // Global variables
00059 //----------------------------------------------------------------------
00060 
00061 
00062 //----------------------------------------------------------------------
00063 // Function declarations
00064 //----------------------------------------------------------------------
00065 
00066 
00067 //----------------------------------------------------------------------
00068 // Class declarations
00069 //----------------------------------------------------------------------
00070 
00071 
00072 
00079 //-----------------------------------------------------------------
00080 
00103 #define DEFINE_TO_CASECOMMAND( _c ) case _c: return (#_c)
00104 
00127 #define DEFINE_TO_CASECOMMAND_MSG( _c, ... ) case _c: return (#_c ": " __VA_ARGS__)
00128 
00132 VCC_EXPORT bool InIndex( int v, int max );
00133 
00134 
00138 VCC_EXPORT bool InRange( double v, double min, double max );
00139 
00140 
00146 VCC_EXPORT bool InRange( int n, double const* v, double const* min, double const* max );
00147 
00148 
00154 VCC_EXPORT double ToRange( double v, double min, double max );
00155 
00156 
00162 VCC_EXPORT void ToRange( int n, double* v, double const* min, double const* max );
00163 
00164 
00170 VCC_EXPORT void ToRange( std::vector<double>& v, std::vector<double> const& min, std::vector<double> const& max );
00171 
00172 
00178 VCC_EXPORT void ToRange( cSimpleVector& v, std::vector<double> const& min, std::vector<double> const& max );
00179 
00180 
00184 VCC_EXPORT double Approx( double a, double b, double eps );
00185 
00186 
00191 VCC_EXPORT bool Approx( int n, double* a, double* b, double* eps );
00192 
00193 
00197 VCC_EXPORT double DegToRad( double d );
00198 
00199 
00203 VCC_EXPORT double RadToDeg( double r );
00204 
00205 
00209 VCC_EXPORT void SleepSec( double t );
00210 
00211 
00220 template<typename Function, typename Tp>
00221 void apply( Function f, Tp& sequence )
00222 {
00223     // concept requirements
00224 
00225     for ( typename Tp::iterator it = sequence.begin();
00226           it < sequence.end();
00227           it++ )
00228     {
00229         *it = f( *it );
00230     }
00231 }
00232 //----------------------------------------------------------------------
00233 
00234 
00247 template<typename Function, typename InputIterator>
00248 Function
00249 apply( Function f, InputIterator first, InputIterator last)
00250 {
00251     // concept requirements (not understood by gcc 3.2, thus commented out)
00252     //__glibcxx_function_requires(_InputIteratorConcept<InputIterator>)
00253     //  __glibcxx_requires_valid_range(first, last);
00254   for ( ; first != last; ++first)
00255         *first = f(*first);
00256 }
00257 //----------------------------------------------------------------------
00258 
00266 template<typename Function, typename Tp>
00267 Tp map(Function f, Tp sequence)
00268 {
00269     Tp result (sequence);
00270 
00271     apply( f, result );
00272 
00273     return result;
00274 }
00275 //----------------------------------------------------------------------
00276 
00310 template<typename T>
00311 std::ostream& operator<<(std::ostream& stream, std::vector<T> const& v)
00312 {
00313     char const* sep = "";
00314 
00315     typename std::vector<T>::const_iterator it;
00316     for ( it = v.begin();
00317           it != v.end();
00318           it++ )
00319     {
00320         stream << sep << *it ;
00321         sep = ", ";
00322     }
00323 
00324     return stream;
00325 }
00326 //----------------------------------------------------------------------
00327 
00329 VCC_EXPORT int CompareReleases( char const* rev1, char const* rev2 );
00330 //----------------------------------------------------------------------
00331 
00333 template<typename T>
00334 class VCC_EXPORT cSetValueTemporarily
00335 {
00336     T* value_ptr;
00337     T  old_value;
00338 public:
00340     cSetValueTemporarily( T* _value_ptr, T new_value )
00341     : value_ptr( _value_ptr ),
00342       old_value( *value_ptr )
00343     {
00344         *value_ptr = new_value;
00345     }
00346 
00348     ~cSetValueTemporarily()
00349     {
00350         *value_ptr = old_value;
00351     }
00352 };
00353 
00355 
00356 NAMESPACE_SDH_END
00357 
00358 #endif
00359 
00360 
00361 //======================================================================
00362 /*
00363   Here are some settings for the emacs/xemacs editor (and can be safely ignored):
00364   (e.g. to explicitely set C++ mode for *.h header files)
00365 
00366   Local Variables:
00367   mode:C++
00368   mode:ELSE
00369   End:
00370 */
00371 //======================================================================
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


schunk_sdh
Author(s): Florian Weisshardt
autogenerated on Tue Mar 5 2013 14:44:11