[ogs-changes] dist/c++/ogs/support Class.h,1.1,1.2 Object.cpp,1.3,1.4 Object.h,1.2,1.3
Status: Alpha
Brought to you by:
elemings
|
From: <ele...@us...> - 2003-04-18 01:41:11
|
Update of /cvsroot/ogs/dist/c++/ogs/support
In directory sc8-pr-cvs1:/tmp/cvs-serv25962/c++/ogs/support
Modified Files:
Class.h Object.cpp Object.h
Log Message:
See C++ ChangeLog (Apr 17) for details.
Index: Class.h
===================================================================
RCS file: /cvsroot/ogs/dist/c++/ogs/support/Class.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Class.h 7 Jan 2003 07:41:34 -0000 1.1
--- Class.h 18 Apr 2003 01:41:07 -0000 1.2
***************
*** 36,45 ****
/**
* An object representing the class of another object. This class is
! * actually a thin wrapper for the type_info class from the <typeinfo>
! * header of the standard C++ library.
*/
class Class {
public:
! template <class C> static Class getClass ();
bool operator== (const Class& cls) const;
--- 36,46 ----
/**
* An object representing the class of another object. This class is
! * actually a thin wrapper for the type_info class declared in the
! * @<typeinfo@> header of the standard C++ library.
*/
class Class {
public:
! template <class C>
! static Class getClass ();
bool operator== (const Class& cls) const;
***************
*** 74,78 ****
* @return True if the two objects describe the same class.
*/
! inline bool Class::operator== (const Class& cls) const {
return (typeInfo == cls.typeInfo);
}
--- 75,80 ----
* @return True if the two objects describe the same class.
*/
! inline bool
! Class::operator== (const Class& cls) const {
return (typeInfo == cls.typeInfo);
}
***************
*** 85,89 ****
* @return True if each object describes a different class.
*/
! inline bool Class::operator!= (const Class& cls) const {
return (typeInfo != cls.typeInfo);
}
--- 87,92 ----
* @return True if each object describes a different class.
*/
! inline bool
! Class::operator!= (const Class& cls) const {
return (typeInfo != cls.typeInfo);
}
***************
*** 96,99 ****
--- 99,112 ----
inline std::string Class::getName () const {
return (std::string (typeInfo.name ()));
+ }
+
+ /**
+ * Determine the class of this object.
+ *
+ * @return Class of this object.
+ */
+ inline Class
+ Object::getClass () const {
+ return (Class (typeid (*this)));
}
Index: Object.cpp
===================================================================
RCS file: /cvsroot/ogs/dist/c++/ogs/support/Object.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Object.cpp 25 Mar 2003 06:13:15 -0000 1.3
--- Object.cpp 18 Apr 2003 01:41:07 -0000 1.4
***************
*** 33,43 ****
/**
! * Add an event observer.
*
* @param observer An event observer.
*/
void Object::addObserver (Observer& observer) {
! // Will std::list allow the same observer to be added more than once?
! observers.push_front (&observer);
}
--- 33,46 ----
/**
! * Add an event observer. This function adds the observer only if it is
! * not already in the list of observers for this object.
*
* @param observer An event observer.
*/
void Object::addObserver (Observer& observer) {
! Observers::iterator end = this->_observers.end ();
! if (std::find (this->_observers.begin (), end, &observer) == end) {
! _observers.push_front (&observer);
! }
}
***************
*** 48,52 ****
*/
void Object::removeObserver (Observer& observer) {
! observers.remove (&observer);
}
--- 51,55 ----
*/
void Object::removeObserver (Observer& observer) {
! this->_observers.remove (&observer);
}
***************
*** 60,69 ****
*/
void Object::notifyObservers (Event& event) {
! std::list<Observer*>::iterator itor = observers.begin ();
! while (itor != observers.end ()) {
! Observer* observer = *itor;
observer->handleEvent (event);
- ++itor;
}
}
--- 63,71 ----
*/
void Object::notifyObservers (Event& event) {
! Observers::iterator itor = this->_observers.begin ();
! while (itor != this->_observers.end ()) {
! Observer* observer = *itor++;
observer->handleEvent (event);
}
}
***************
*** 75,94 ****
*
* @return A string representation of this object.
*/
std::string Object::toString () const {
std::ostringstream ostr;
ostr << (typeid (*this)).name () << "@" << this;
! ostr << " [observers " << &observers <<
! " [size " << observers.size () << "]]";
return (ostr.str ());
- }
-
- /**
- * Determine the class of this object.
- *
- * @return Class of this object.
- */
- Class Object::getClass () const {
- return (Class (typeid (*this)));
}
--- 77,88 ----
*
* @return A string representation of this object.
+ * @todo Change this function into an operator<< function?
*/
std::string Object::toString () const {
std::ostringstream ostr;
ostr << (typeid (*this)).name () << "@" << this;
! ostr << " [observers " << &this->_observers <<
! " [size " << this->_observers.size () << "]]";
return (ostr.str ());
}
Index: Object.h
===================================================================
RCS file: /cvsroot/ogs/dist/c++/ogs/support/Object.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Object.h 18 Feb 2003 04:17:21 -0000 1.2
--- Object.h 18 Apr 2003 01:41:07 -0000 1.3
***************
*** 55,58 ****
--- 55,59 ----
Object ();
+ /** A list of observers. */
typedef std::list<Observer*> Observers;
Observers getObservers () const;
***************
*** 60,64 ****
private:
! Observers observers;
};
--- 61,65 ----
private:
! Observers _observers;
};
***************
*** 68,72 ****
* observers as an empty list.
*/
! inline Object::Object (): observers () { }
/**
--- 69,76 ----
* observers as an empty list.
*/
! inline Object::Object ():
! _observers () {
! // empty constructor body
! }
/**
***************
*** 74,80 ****
*
* @return List of observers.
*/
! inline Object::Observers Object::getObservers () const {
! return (this->observers);
}
--- 78,86 ----
*
* @return List of observers.
+ * @todo Change the return type to a const reference?
*/
! inline Object::Observers
! Object::getObservers () const {
! return (this->_observers);
}
|