util
pushvalue.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef PUSHVALUE_H
00020 #define PUSHVALUE_H
00021
00028 template<class Value>
00029 class PushValue {
00030 public:
00031 PushValue( Value& ptr, const Value& push = Value() ) : m_ptr(ptr) {
00032 m_oldPtr = m_ptr;
00033 m_ptr = push;
00034 }
00035 ~PushValue() {
00036 m_ptr = m_oldPtr;
00037 }
00038 private:
00039 Value& m_ptr;
00040 Value m_oldPtr;
00041 };
00042
00044 template<class Value>
00045 class PushPositiveValue {
00046 public:
00047 PushPositiveValue( Value& ptr, const Value& push = Value() ) : m_ptr(ptr) {
00048 m_oldPtr = m_ptr;
00049 if( push ) {
00050 m_ptr = push;
00051 }
00052 }
00053 ~PushPositiveValue() {
00054 m_ptr = m_oldPtr;
00055 }
00056 private:
00057 Value& m_ptr;
00058 Value m_oldPtr;
00059 };
00060
00061 #endif