www.mxdraw.com
内容索引主面
前一个向上下一个
AsdkDataManager 模板

实现了一个模板,用该模板可以与控件文档帮定一个数据对象

C++
template <class T>
class AsdkDataManager : public McApDocManagerReactor;

McApDocument.h

例如:控件内部mxdraw.dll中部分代码

    // 类定义,重载了createData,deleteData实现自己数据对象的分配和释放
    class IntelliCmdDocDataContainer : public AsdkDataManager<IntelliCmdDocData*>
    {
    protected:
        virtual IntelliCmdDocData* createData(McApDocument* pDoc);
        virtual void deleteData(IntelliCmdDocData* data);

    public:
        static IntelliCmdDocDataContainer& Instance()
        {
            return s_instance;
        }
    private:
        static IntelliCmdDocDataContainer s_instance;       // 文档数据实例对象
    };

    // 类实现
    IntelliCmdDocDataContainer IntelliCmdDocDataContainer::s_instance;
    IntelliCmdDocData* IntelliCmdDocDataContainer::createData(McApDocument* pDoc)
    {
        COcxDoc* pOcxDoc = MX_CAST(pDoc->Doc(),COcxDoc);
        MXASSERT(pOcxDoc != NULL);

        IntelliCmdDocData* pRet = new IntelliCmdDocData(pOcxDoc);
        return pRet;
    }

    void IntelliCmdDocDataContainer::deleteData(IntelliCmdDocData* data)
    {
        delete data;
    }

    //  对数据的使用和访问 IntelliCmdDocDataContainer::Instance().docData(pArxDoc->McApDoc()) 返回的是IntelliCmdDocData*
    //  Select是IntelliCmdDocData的函数
    MxDocArx* pArxDoc = hOcx->GetDoc();
    IntelliSelect* pInteliSelect 
    = IntelliCmdDocDataContainer::Instance().docData(pArxDoc->McApDoc())->Select();
    if(pInteliSelect == NULL)
    {
        return FALSE;
    }

sampleExAppExApp.sln中的代码,与文档帮定一个CDrawFlag对象

    class CDrawFlagContainer : public AsdkDataManager<CDrawFlag*>
    {
    protected:
        virtual CDrawFlag* createData(McApDocument* pDoc);
        virtual void deleteData(CDrawFlag* data);

    public:
        static CDrawFlagContainer& Instance()
        {
            return s_instance;
        }
    private:
        static CDrawFlagContainer s_instance;       // 文档数据实例对象
    };

    // 类实现
    CDrawFlagContainer CDrawFlagContainer::s_instance;
    CDrawFlag* CDrawFlagContainer::createData(McApDocument* pDoc)
    {
        MxDraw::MXDRAWOCXHANDLE hOcx =  MxDraw::GetOcxHandleFormDatabase(pDoc->database());
        ASSERT(hOcx != NULL);

        CDrawFlag* pRet = new CDrawFlag(hOcx);
        return pRet;
    }

    void CDrawFlagContainer::deleteData(CDrawFlag* data)
    {
        data->UnRegist();
        delete data;
    }

    // 使用
    CDrawFlag* pDraw 
    = CDrawFlagContainer::Instance().docData();
Copyright (c) 2010. All rights reserved.
你认为该帮助怎么样? 发送反馈信息!