Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

genericalgs.h

Go to the documentation of this file.
00001 
00007 #ifndef __GENERICALGS_H__
00008 #define __GENERICALGS_H__
00009 
00010 #include <algorithm>
00011 
00018 #ifndef ISEQ
00019 #define ISEQ(container) (container).begin(),(container).end()
00020 #endif
00021 
00022 
00028 #ifndef callMemberFunction
00029 #define callMemberFunction(object,ptrToMember)  ((object).*(ptrToMember))
00030 #endif
00031 
00032 
00034 namespace Generic {
00035 
00036 
00037 
00039 template <class T>
00040 inline const T crop(const T lower, const T upper, const T x) {
00041   return std::max(lower,std::min(upper,x));
00042 }
00043   
00044 
00045  
00050 template <class T>
00051 inline const T wrap(const T lower, const T upper, const T x) {
00052   const T range=upper-lower;
00053   return lower + (T)fmod(x-lower + 2*range*(1-floor(x/(2*range))),
00054                          range);
00055 }
00056  
00057 
00058  
00063 template<class Container>
00064 void delete_contents(Container& c)
00065 {
00066   while(!c.empty()) {
00067     delete c.back();
00068     c.pop_back();
00069   }
00070 }
00071 
00072 
00073 
00078 template <class ForwardIterator, class T>
00079 void lower_threshold(ForwardIterator first, ForwardIterator last,
00080                      const T& threshold, const T& new_value)
00081 {  for (; first != last; ++first) if (*first < threshold) *first=new_value;  }
00082 
00083 
00084 
00089 template <class ForwardIterator, class T>
00090 void upper_threshold(ForwardIterator first, ForwardIterator last,
00091                      const T& threshold, const T& new_value)
00092 {  for (; first != last; ++first) if (*first > threshold) *first=new_value;  }
00093 
00094 
00095 
00096 } /* namespace Generic */ 
00097 #endif

Generated at Mon Aug 21 00:30:54 2000 for RF-LISSOM by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000