You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
/**
* @file WObserver.h
* @brief 观察者(观察者模式)
* @author 沙漠乌鸦
* @time 2010-01-18
*/
# pragma once
namespace wuya
{
class WSubject ;
class AFX_EXT_CLASS WObserver
{
public :
WObserver ( void ) ;
virtual ~ WObserver ( void ) ;
void SetUpdate ( bool bUpdate ) ;
bool GetUpdate ( ) ;
/** @brief 观察者更新, 设置时间标志, 并调用Update()函数 */
void UpdateNotify ( ULONGLONG ullTime ) ;
/** @brief 时间戳 */
ULONGLONG GetTimeStampObserver ( ) const ;
void SetTimeStampObserver ( ULONGLONG ullTime ) ;
private :
/**
* @brief 负责更新观察者状态、具体观察者必须重载该函数
* 若Update带参数Subject*,可以实现一个观察者观察多个目标。
* (在Update函数中判断是属于哪个目标)
* @note 例如:一个表格对象可能依赖多个数据源,本例中只实现依赖一个目标的情况。
*/
virtual void Update ( ) = 0 ;
private :
bool m_bUpdate ; ///< 是否需要更新状态
ULONGLONG m_ullTimeObserver ; ///< 时间戳
} ;
inline void WObserver : : SetUpdate ( bool bUpdate )
{
this - > m_bUpdate = bUpdate ;
}
inline bool WObserver : : GetUpdate ( )
{
return m_bUpdate ;
}
inline ULONGLONG WObserver : : GetTimeStampObserver ( ) const
{
return m_ullTimeObserver ;
}
inline void WObserver : : SetTimeStampObserver ( ULONGLONG ullTime )
{
this - > m_ullTimeObserver = ullTime ;
}
}