util.h
Go to the documentation of this file.
1 //======================================================================
28 //======================================================================
29 
30 #ifndef UTIL_H_
31 #define UTIL_H_
32 
33 
34 //----------------------------------------------------------------------
35 // System Includes - include with <>
36 //----------------------------------------------------------------------
37 
38 #include <math.h>
39 #include <vector>
40 #include <algorithm>
41 #include <iostream>
42 
43 //----------------------------------------------------------------------
44 // Project Includes - include with ""
45 //----------------------------------------------------------------------
46 
47 #include "sdhlibrary_settings.h"
48 #include "simplevector.h"
49 
50 //----------------------------------------------------------------------
51 // Defines, enums, unions, structs,
52 //----------------------------------------------------------------------
53 
55 
56 
57 //----------------------------------------------------------------------
58 // Global variables
59 //----------------------------------------------------------------------
60 
61 
62 //----------------------------------------------------------------------
63 // Function declarations
64 //----------------------------------------------------------------------
65 
66 
67 //----------------------------------------------------------------------
68 // Class declarations
69 //----------------------------------------------------------------------
70 
71 
72 
79 //-----------------------------------------------------------------
80 
103 #define DEFINE_TO_CASECOMMAND( _c ) case _c: return (#_c)
104 
127 #define DEFINE_TO_CASECOMMAND_MSG( _c, ... ) case _c: return (#_c ": " __VA_ARGS__)
128 
132 VCC_EXPORT bool InIndex( int v, int max );
133 
134 
138 VCC_EXPORT bool InRange( double v, double min, double max );
139 
140 
146 VCC_EXPORT bool InRange( int n, double const* v, double const* min, double const* max );
147 
148 
154 VCC_EXPORT double ToRange( double v, double min, double max );
155 
156 
162 VCC_EXPORT void ToRange( int n, double* v, double const* min, double const* max );
163 
164 
170 VCC_EXPORT void ToRange( std::vector<double>& v, std::vector<double> const& min, std::vector<double> const& max );
171 
172 
178 VCC_EXPORT void ToRange( cSimpleVector& v, std::vector<double> const& min, std::vector<double> const& max );
179 
180 
184 VCC_EXPORT double Approx( double a, double b, double eps );
185 
186 
191 VCC_EXPORT bool Approx( int n, double* a, double* b, double* eps );
192 
193 
197 VCC_EXPORT double DegToRad( double d );
198 
199 
203 VCC_EXPORT double RadToDeg( double r );
204 
205 
209 VCC_EXPORT void SleepSec( double t );
210 
211 
220 template<typename Function, typename Tp>
221 void apply( Function f, Tp& sequence )
222 {
223  // concept requirements
224 
225  for ( typename Tp::iterator it = sequence.begin();
226  it < sequence.end();
227  it++ )
228  {
229  *it = f( *it );
230  }
231 }
232 //----------------------------------------------------------------------
233 
234 
247 template<typename Function, typename InputIterator>
248 Function
249 apply( Function f, InputIterator first, InputIterator last)
250 {
251  // concept requirements (not understood by gcc 3.2, thus commented out)
252  //__glibcxx_function_requires(_InputIteratorConcept<InputIterator>)
253  // __glibcxx_requires_valid_range(first, last);
254  for ( ; first != last; ++first)
255  *first = f(*first);
256 }
257 //----------------------------------------------------------------------
258 
266 template<typename Function, typename Tp>
267 Tp map(Function f, Tp sequence)
268 {
269  Tp result (sequence);
270 
271  apply( f, result );
272 
273  return result;
274 }
275 //----------------------------------------------------------------------
276 
310 template<typename T>
311 std::ostream& operator<<(std::ostream& stream, std::vector<T> const& v)
312 {
313  char const* sep = "";
314 
315  typename std::vector<T>::const_iterator it;
316  for ( it = v.begin();
317  it != v.end();
318  it++ )
319  {
320  stream << sep << *it ;
321  sep = ", ";
322  }
323 
324  return stream;
325 }
326 //----------------------------------------------------------------------
327 
329 VCC_EXPORT int CompareReleases( char const* rev1, char const* rev2 );
330 //----------------------------------------------------------------------
331 
333 template<typename T>
334 class VCC_EXPORT cSetValueTemporarily
335 {
338 public:
340  cSetValueTemporarily( T* _value_ptr, T new_value )
341  : value_ptr( _value_ptr ),
342  old_value( *value_ptr )
343  {
344  *value_ptr = new_value;
345  }
346 
349  {
350  *value_ptr = old_value;
351  }
352 };
353 
355 
357 
358 #endif
359 
360 
361 //======================================================================
362 /*
363  Here are some settings for the emacs/xemacs editor (and can be safely ignored):
364  (e.g. to explicitely set C++ mode for *.h header files)
365 
366  Local Variables:
367  mode:C++
368  mode:ELSE
369  End:
370 */
371 //======================================================================
cSetValueTemporarily::value_ptr
T * value_ptr
Definition: util.h:336
ToRange
VCC_EXPORT double ToRange(double v, double min, double max)
Definition: util.cpp:97
NAMESPACE_SDH_END
#define NAMESPACE_SDH_END
Definition: sdhlibrary_settings.h:80
InRange
VCC_EXPORT bool InRange(double v, double min, double max)
Definition: util.cpp:80
DegToRad
VCC_EXPORT double DegToRad(double d)
Definition: util.cpp:143
operator<<
std::ostream & operator<<(std::ostream &stream, std::vector< T > const &v)
Definition: util.h:311
map
Tp map(Function f, Tp sequence)
Definition: util.h:267
cSimpleVector
A simple vector implementation.
Definition: simplevector.h:91
cSetValueTemporarily
helper class to set value on construction and reset to previous value on destruction....
Definition: util.h:334
CompareReleases
VCC_EXPORT int CompareReleases(char const *rev1, char const *rev2)
compare release strings
Definition: util.cpp:236
RadToDeg
VCC_EXPORT double RadToDeg(double r)
Definition: util.cpp:149
SleepSec
VCC_EXPORT void SleepSec(double t)
Definition: util.cpp:155
cSetValueTemporarily::~cSetValueTemporarily
~cSetValueTemporarily()
DTOR: restore the remembered value.
Definition: util.h:348
simplevector.h
Interface of class #SDH::cSimpleVector.
NAMESPACE_SDH_START
#define NAMESPACE_SDH_START
Definition: sdhlibrary_settings.h:79
apply
void apply(Function f, Tp &sequence)
Definition: util.h:221
sdhlibrary_settings.h
This file contains settings to make the SDHLibrary compile on differen systems:
cSetValueTemporarily::old_value
T old_value
Definition: util.h:337
InIndex
VCC_EXPORT bool InIndex(int v, int max)
Definition: util.cpp:74
cSetValueTemporarily::cSetValueTemporarily
cSetValueTemporarily(T *_value_ptr, T new_value)
CTOR: remember current value of _value_ptr and set it to new_value.
Definition: util.h:340
Approx
VCC_EXPORT double Approx(double a, double b, double eps)
Definition: util.cpp:126


sdhlibrary_cpp
Author(s): Dirk Osswald
autogenerated on Wed Mar 2 2022 01:00:58