00001 #ifndef _posix_ScopedIncrement_h
00002 #define _posix_ScopedIncrement_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <boost/noncopyable.hpp>
00023 #include <boost/function.hpp>
00024
00025 namespace qpid {
00026 namespace sys {
00027
00033 template <class T, class F=boost::function<void()> >
00034 class ScopedIncrement : boost::noncopyable
00035 {
00036 public:
00037 ScopedIncrement(T& c, F f=0)
00038 : count(c), callback(f) { ++count; }
00039 ~ScopedIncrement() { if (--count == 0 && callback) callback(); }
00040
00041 private:
00042 T& count;
00043 F callback;
00044 };
00045
00046
00048 template <class T>
00049 class ScopedDecrement : boost::noncopyable
00050 {
00051 public:
00052 ScopedDecrement(T& c) : count(c) { value = --count; }
00053 ~ScopedDecrement() { ++count; }
00054
00056 operator long() { return value; }
00057
00058 private:
00059 T& count;
00060 long value;
00061 };
00062
00063
00064 }}
00065
00066
00067 #endif // _posix_ScopedIncrement_h