maxRecorder.h

Go to the documentation of this file.
00001 
00015 #ifndef DLR_NUMERIC_MAXRECORDER_H
00016 #define DLR_NUMERIC_MAXRECORDER_H
00017 
00018 #include <limits>
00019 
00020 namespace dlr {
00021 
00022   namespace numeric {
00023     
00029     template<class Type, class Payload>
00030     class MaxRecorder {
00031     public:
00032 
00040       MaxRecorder() : m_max(), m_payload() {this->reset();}
00041 
00042 
00047       MaxRecorder(Type const& maxValue, Payload const& payload)
00048         : m_max(maxValue), m_payload(payload) {}
00049 
00050 
00066       bool
00067       test(const Type& value, const Payload& payload) {
00068         if(value > m_max) {
00069           m_max = value;
00070           m_payload = payload;
00071           return true;
00072         }
00073         return false;
00074       }
00075 
00076 
00084       const Type&
00085       getMax() {return m_max;}
00086 
00087 
00096       const Payload&
00097       getPayload() {return m_payload;}
00098 
00099 
00104       void
00105       reset() {
00106         if(std::numeric_limits<Type>::is_signed) {
00107           m_max = -std::numeric_limits<Type>::max();
00108         } else {
00109           m_max = std::numeric_limits<Type>::min();
00110         }
00111       }
00112 
00113     private:
00114 
00115       Type m_max;
00116       Payload m_payload;
00117 
00118     };
00119     
00120   } // namespace numeric
00121 
00122 } // namespace dlr
00123 
00124 #endif // #ifdef DLR_NUMERIC_MAXRECORDER_H

Generated on Wed Nov 25 00:42:42 2009 for dlrUtilities Utility Library by  doxygen 1.5.8