Occasionally users may wish to declare and implement an observer template class that can then be used by several user observers. This method can allow each of the user's observers to share a common observer notification function code base.
The example below uses this technique to derive a user object sentinel (object observer or watcher) template class from the oaObserver template class. The sentinel template class has the following features and functionality:
template <class T> class ObjSentinel : public oaObserver<T> { public: ObjSentinel() : oaObserver<T> (1, false) {} ~ObjSentinel() {} void onPostCreate (T *object); void onPreModify (T *object, typename oaTraits<T>::modTypeType modType); void onPreDestroy (T *object); private: static ObjSentinel<oaNet> m_netSentinel; static ObjSentinel<oaTerm> m_termSentinel; static ObjSentinel<oaInst> m_instSentinel; static ObjSentinel<oaOccTerm> m_itermSentinel; };template<class T> inline void> ObjSentinel<T>::onPostCreate(T *object) { throw NetException(cObjChange); } template<class T> inline void ObjSentinel<T>::onPreModify(T *object, typename oaTraits<T>::modTypeType modType) { throw NetException(cObjChange); }
template<class T> inline void ObjSentinel<T>::onPreDestroy(T *object) { throw NetException(cObjChange); }
Return to Programmers Guide topics
Copyright © 2001-2010 Cadence Design Systems, Inc.
All rights reserved.