util.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2007 SCHUNK GmbH & Co. KG
00003  * Copyright (c) 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *   http://www.apache.org/licenses/LICENSE-2.0
00010 
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 //======================================================================
00045 //======================================================================
00046 
00047 #ifndef UTIL_H_
00048 #define UTIL_H_
00049 
00050 
00051 //----------------------------------------------------------------------
00052 // System Includes - include with <>
00053 //----------------------------------------------------------------------
00054 
00055 #include <math.h>
00056 #include <vector>
00057 #include <algorithm>
00058 #include <iostream>
00059 
00060 //----------------------------------------------------------------------
00061 // Project Includes - include with ""
00062 //----------------------------------------------------------------------
00063 
00064 #include "sdhlibrary_settings.h"
00065 #include "simplevector.h"
00066 
00067 //----------------------------------------------------------------------
00068 // Defines, enums, unions, structs,
00069 //----------------------------------------------------------------------
00070 
00071 NAMESPACE_SDH_START
00072 
00073 
00074 //----------------------------------------------------------------------
00075 // Global variables
00076 //----------------------------------------------------------------------
00077 
00078 
00079 //----------------------------------------------------------------------
00080 // Function declarations
00081 //----------------------------------------------------------------------
00082 
00083 
00084 //----------------------------------------------------------------------
00085 // Class declarations
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   // concept requirements
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   // concept requirements (not understood by gcc 3.2, thus commented out)
00269   //__glibcxx_function_requires(_InputIteratorConcept<InputIterator>)
00270   //  __glibcxx_requires_valid_range(first, last);
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   Here are some settings for the emacs/xemacs editor (and can be safely ignored):
00381   (e.g. to explicitely set C++ mode for *.h header files)
00382 
00383   Local Variables:
00384   mode:C++
00385   mode:ELSE
00386   End:
00387 */
00388 //======================================================================


schunk_sdh
Author(s): Mathias Luedtke , Florian Weisshardt
autogenerated on Sat Jun 8 2019 20:25:21