00001
00009 #ifndef _OVERFLOW_H
00010 #define _OVERFLOW_H
00011
00012 #include <limits>
00013 #include <map>
00014
00015 namespace ace {
00016
00023 template<class _KeyType, class _ValueType>
00024 class Overflow {
00027 typedef typename std::map<_KeyType, _ValueType> _overflows_map_t;
00030 static const _ValueType _max_value;
00033 _overflows_map_t _overflows_map;
00034 public:
00039 void add(_KeyType key, _ValueType value) {
00040 typename _overflows_map_t::iterator iter = _overflows_map.lower_bound(key);
00041 if ( iter->first == key ) {
00042 iter->second = add_to_maximum(iter->second, value);
00043 } else {
00044 _overflows_map.insert(iter, typename _overflows_map_t::value_type(key, value));
00045 }
00046 }
00052 static _ValueType add_to_maximum(_ValueType a, _ValueType b) {
00053 return ((_max_value - a) < b ) ? _max_value : a + b;
00054 }
00058 inline _ValueType get(_KeyType key) { return _overflows_map[key]; }
00059 };
00060
00061 template<class _KeyType, class _ValueType>
00062 const _ValueType Overflow<_KeyType, _ValueType>::_max_value = std::numeric_limits<_ValueType>::max();
00063
00064 }
00065
00066 #endif