[ogs-changes] dist/c++/ogs/support Attachable.h,1.2,1.3 Object.cpp,1.4,1.5 Object.h,1.3,1.4 Observer
Status: Alpha
Brought to you by:
elemings
From: <ele...@us...> - 2003-05-02 19:06:41
|
Update of /cvsroot/ogs/dist/c++/ogs/support In directory sc8-pr-cvs1:/tmp/cvs-serv32451/ogs/support Modified Files: Attachable.h Object.cpp Object.h Observer.h Utility.h Log Message: See C++ ChangeLog (May 2) for details. Index: Attachable.h =================================================================== RCS file: /cvsroot/ogs/dist/c++/ogs/support/Attachable.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Attachable.h 15 Apr 2003 16:58:50 -0000 1.2 --- Attachable.h 2 May 2003 19:06:37 -0000 1.3 *************** *** 39,43 **** * reversible when (and if) the attachable is detached from the subject. * Attachable objects that do not modify the subject simply add ! * additional detail to the object. */ class Attachable { --- 39,48 ---- * reversible when (and if) the attachable is detached from the subject. * Attachable objects that do not modify the subject simply add ! * additional detail to the object. <P> ! * ! * Note that this interface is designed only for one to one or one to ! * many relationships depending on the object that an Attachable is ! * attached to. Many to many relationships would require a much more ! * complicated interface. */ class Attachable { Index: Object.cpp =================================================================== RCS file: /cvsroot/ogs/dist/c++/ogs/support/Object.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Object.cpp 18 Apr 2003 01:41:07 -0000 1.4 --- Object.cpp 2 May 2003 19:06:37 -0000 1.5 *************** *** 41,45 **** Observers::iterator end = this->_observers.end (); if (std::find (this->_observers.begin (), end, &observer) == end) { ! _observers.push_front (&observer); } } --- 41,45 ---- Observers::iterator end = this->_observers.end (); if (std::find (this->_observers.begin (), end, &observer) == end) { ! this->_observers.push_front (&observer); } } *************** *** 62,67 **** * @param event The event that occurred. */ ! void Object::notifyObservers (Event& event) { ! Observers::iterator itor = this->_observers.begin (); while (itor != this->_observers.end ()) { --- 62,67 ---- * @param event The event that occurred. */ ! void Object::notifyObservers (Event& event) const { ! Observers::const_iterator itor = this->_observers.begin (); while (itor != this->_observers.end ()) { Index: Object.h =================================================================== RCS file: /cvsroot/ogs/dist/c++/ogs/support/Object.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Object.h 18 Apr 2003 01:41:07 -0000 1.3 --- Object.h 2 May 2003 19:06:37 -0000 1.4 *************** *** 58,62 **** typedef std::list<Observer*> Observers; Observers getObservers () const; ! virtual void notifyObservers (Event& event); private: --- 58,62 ---- typedef std::list<Observer*> Observers; Observers getObservers () const; ! virtual void notifyObservers (Event& event) const; private: Index: Observer.h =================================================================== RCS file: /cvsroot/ogs/dist/c++/ogs/support/Observer.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Observer.h 13 Apr 2003 05:28:46 -0000 1.2 --- Observer.h 2 May 2003 19:06:37 -0000 1.3 *************** *** 52,56 **** virtual void handleEvent (Event& event) = 0; ! friend void Object::notifyObservers (Event& event); }; --- 52,56 ---- virtual void handleEvent (Event& event) = 0; ! friend void Object::notifyObservers (Event& event) const; }; Index: Utility.h =================================================================== RCS file: /cvsroot/ogs/dist/c++/ogs/support/Utility.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Utility.h 13 Apr 2003 05:28:46 -0000 1.1 --- Utility.h 2 May 2003 19:06:37 -0000 1.2 *************** *** 31,40 **** /** ! * A function object that destroys allocated memory. A Destroy object ! * destroys allocated memory by calling the delete operator on pointers. ! * These objects can be used conveniently with standard containers and ! * algorithms. */ ! struct Destroy { template <typename T> void operator() (const T* t) const; --- 31,38 ---- /** ! * A function object for the delete operator. Objects of this structure ! * are intended to be with standard library algorithms. */ ! struct Delete { template <typename T> void operator() (const T* t) const; *************** *** 42,46 **** /** ! * Destroy allocated memory. The allocated memory is destroyed by * calling the delete operator on a pointer of type T. The type T is * specified by the template parameter. --- 40,44 ---- /** ! * Delete allocated memory. The allocated memory is deleted by * calling the delete operator on a pointer of type T. The type T is * specified by the template parameter. *************** *** 49,55 **** */ template <typename T> ! void Destroy::operator() (const T* t) const { delete t; } OGS_END_SUPPORT_NAMESPACE --- 47,81 ---- */ template <typename T> ! inline void ! Delete::operator() (const T* t) const { delete t; } + + /** + * A predicate for the dynamic cast operator. This predicate determines + * if a value <code>x</code> of type <code>T1</code> can be dynamically + * cast to type <code>T2>. + */ + template <class T> + struct DynamicCast + { + typedef bool result_type; + + /** + * Determine if a value can be dynamically cast to another type. + * + * @param p A pointer to an object of type <code>U</code>. + * @return True if the pointer can be cast to type <code>T*</code>. + */ + template <class U> + bool operator() (U* p) const { + return (dynamic_cast<T const volatile*> (p) != 0); + } + + template <class U> + bool operator() (U& p) const { + return (dynamic_cast<T const volatile*> (&p) != 0); + } + }; OGS_END_SUPPORT_NAMESPACE |