平民程序 - linghuye's blog

天下风云出我辈,一入江湖岁月催。皇图霸业谈笑中,不胜人生一场醉。提剑跨骑挥鬼雨,白骨如山鸟惊飞。尘事如潮人如水,只笑江湖几人回。

随笔 - 221, 文章 - 0, 评论 - 680, 引用 - 0
数据加载中……

接口继承下的实现继承

这种C++技法最先学自ATL的架构,而后却总是记不住,备之.
class DmGameCamera;
struct ISceneNode
{    
    
virtual void Release() = 0;
    
virtual void Render() = 0;
    
virtual bool IsVisible() = 0;
    
virtual bool RayPickup(const vec3_type& vBegin, const vec3_type& vDir) = 0;
    
virtual vec3_type getPositionToParent() = 0;
    
virtual void UpdateFrame(uint32 time, DmGameCamera& camera) = 0;
    
virtual void AddChildSceneNode(ISceneNode& node) = 0;
}
;

struct IModelSceneNode : public ISceneNode
{    
    
virtual void MakeVisible(bool bVisible) = 0;
}
;

template
<class T, class I = ISceneNode>
struct ISceneNodeImpl : public I
{    
    
void UpdateFrame(uint32 time, DmGameCamera& camera)
    
{
    }


    
bool RayPickup(const vec3_type& vBegin, const vec3_type& vDir)
    
{
        
return false;
    }

        
    vec3_type getPositionToParent() 
    
{
        
return vec3_type(000); 
    }


    
void AddChildSceneNode(ISceneNode& node)
    
{
    }

    
    
bool IsVisible()
    
{
        
return true
    }

    
    
void Render() 
    
{
    }

    
    
void Release() 
    
{
        T
* pThis = static_cast<T*>(this);
        delete pThis;
    }

}
;

template
<class T>
struct IModelSceneNodeImpl : public ISceneNodeImpl<T, IModelSceneNode> 
{    
    IModelSceneNodeImpl()
    
{
        m_bOutOfCamera 
= true;
    }

    
    
void MakeVisible(bool bVisible)
    
{    
        m_bOutOfCamera 
= !bVisible;
    }

    
    
bool m_bOutOfCamera;
}
;

关键在于将高级接口作为模板参数下传至基本接口的实现类模板.

posted on 2005-12-12 16:47 linghuye 阅读(439) 评论(0)  编辑 收藏 引用 所属分类: 编程札记

只有注册用户登录后才能发表评论。