Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00045
00046
00047 #ifndef UTIL_H_
00048 #define UTIL_H_
00049
00050
00051
00052
00053
00054
00055 #include <math.h>
00056 #include <vector>
00057 #include <algorithm>
00058 #include <iostream>
00059
00060
00061
00062
00063
00064 #include "sdhlibrary_settings.h"
00065 #include "simplevector.h"
00066
00067
00068
00069
00070
00071 NAMESPACE_SDH_START
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00096
00097
00120 #define DEFINE_TO_CASECOMMAND( _c ) case _c: return (#_c)
00121
00144 #define DEFINE_TO_CASECOMMAND_MSG( _c, ... ) case _c: return (#_c ": " __VA_ARGS__)
00145
00149 VCC_EXPORT bool InIndex(int v, int max);
00150
00151
00155 VCC_EXPORT bool InRange(double v, double min, double max);
00156
00157
00163 VCC_EXPORT bool InRange(int n, double const* v, double const* min, double const* max);
00164
00165
00171 VCC_EXPORT double ToRange(double v, double min, double max);
00172
00173
00179 VCC_EXPORT void ToRange(int n, double* v, double const* min, double const* max);
00180
00181
00187 VCC_EXPORT void ToRange(std::vector<double>& v, std::vector<double> const& min, std::vector<double> const& max);
00188
00189
00195 VCC_EXPORT void ToRange(cSimpleVector& v, std::vector<double> const& min, std::vector<double> const& max);
00196
00197
00201 VCC_EXPORT double Approx(double a, double b, double eps);
00202
00203
00208 VCC_EXPORT bool Approx(int n, double* a, double* b, double* eps);
00209
00210
00214 VCC_EXPORT double DegToRad(double d);
00215
00216
00220 VCC_EXPORT double RadToDeg(double r);
00221
00222
00226 VCC_EXPORT void SleepSec(double t);
00227
00228
00237 template<typename Function, typename Tp>
00238 void apply(Function f, Tp& sequence)
00239 {
00240
00241
00242 for (typename Tp::iterator it = sequence.begin();
00243 it < sequence.end();
00244 it++)
00245 {
00246 *it = f(*it);
00247 }
00248 }
00249
00250
00251
00264 template<typename Function, typename InputIterator>
00265 Function
00266 apply(Function f, InputIterator first, InputIterator last)
00267 {
00268
00269
00270
00271 for (; first != last; ++first)
00272 *first = f(*first);
00273 }
00274
00275
00283 template<typename Function, typename Tp>
00284 Tp map(Function f, Tp sequence)
00285 {
00286 Tp result(sequence);
00287
00288 apply(f, result);
00289
00290 return result;
00291 }
00292
00293
00327 template<typename T>
00328 std::ostream& operator<<(std::ostream& stream, std::vector<T> const& v)
00329 {
00330 char const* sep = "";
00331
00332 typename std::vector<T>::const_iterator it;
00333 for (it = v.begin();
00334 it != v.end();
00335 it++)
00336 {
00337 stream << sep << *it ;
00338 sep = ", ";
00339 }
00340
00341 return stream;
00342 }
00343
00344
00346 VCC_EXPORT int CompareReleases(char const* rev1, char const* rev2);
00347
00348
00350 template<typename T>
00351 class VCC_EXPORT cSetValueTemporarily
00352 {
00353 T* value_ptr;
00354 T old_value;
00355 public:
00357 cSetValueTemporarily(T* _value_ptr, T new_value)
00358 : value_ptr(_value_ptr),
00359 old_value(*value_ptr)
00360 {
00361 *value_ptr = new_value;
00362 }
00363
00365 ~cSetValueTemporarily()
00366 {
00367 *value_ptr = old_value;
00368 }
00369 };
00370
00372
00373 NAMESPACE_SDH_END
00374
00375 #endif
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388