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 
00058       bool
00059       test(const Type& value, const Payload& payload) {
00060         if(value > m_max) {
00061           m_max = value;
00062           m_payload = payload;
00063           return true;
00064         }
00065         return false;
00066       }
00067 
00068 
00076       const Type&
00077       getMax() {return m_max;}
00078 
00079 
00088       const Payload&
00089       getPayload() {return m_payload;}
00090 
00091 
00096       void
00097       reset() {
00098         if(std::numeric_limits<Type>::is_signed) {
00099           m_max = -std::numeric_limits<Type>::max();
00100         } else {
00101           m_max = std::numeric_limits<Type>::min();
00102         }
00103       }
00104 
00105     private:
00106 
00107       Type m_max;
00108       Payload m_payload;
00109 
00110     };
00111 
00112   } // namespace numeric
00113 
00114 } // namespace dlr
00115 
00116 #endif // #ifdef DLR_NUMERIC_MAXRECORDER_H

Generated on Tue Jan 6 17:52:07 2009 for dlrUtilities Utility Library by  doxygen 1.5.6