Download Automatic Test Data Generation From VDM
Transcript
D
PROGRAM CODE
D.1
The SmartPtr template
template<class X> inline void swap(SmartPtr<X>& a, SmartPtr<X>& b) {
a.swap(b);
}
template<class X>
inline bool operator<(const SmartPtr<X> a, const SmartPtr<X> b) {
return a.get() < b.get();
}
template<class X>
inline bool operator>(const SmartPtr<X> a, const SmartPtr<X> b) {
return a.get() > b.get();
}
template<class X>
inline bool operator<=(const SmartPtr<X> a, const SmartPtr<X> b) {
return a.get() <= b.get();
}
template<class X>
inline bool operator>=(const SmartPtr<X> a, const SmartPtr<X> b) {
return a.get() >= b.get();
};
// allow comparison with pointers
template<class X>
inline bool operator==(const SmartPtr<X> a, const X* b) {
return a.get() == b;
}
template<class X>
inline bool operator==(const X* a, const SmartPtr<X> b) {
return a == b.get();
}
template<class X>
inline bool operator!=(const SmartPtr<X> a, const X* b) {
return a.get() != b;
}
template<class X>
inline bool operator!=(const X* a, const SmartPtr<X> b) {
72
Revision: 1.43