• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Welcome to ErranLi's Blog!

              C++博客 :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
              106 Posts :: 1 Stories :: 97 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(12)

            搜索

            •  

            積分與排名

            • 積分 - 175924
            • 排名 - 151

            最新評(píng)論

            閱讀排行榜

            在此聊聊我設(shè)計(jì)數(shù)據(jù)實(shí)體的一些小伎倆^_^ .........     

            為了方便數(shù)據(jù)的組織.運(yùn)算以及數(shù)據(jù)實(shí)體類(lèi)的使用, 一般我會(huì)把所有數(shù)據(jù)實(shí)體從同一個(gè)實(shí)體基類(lèi)繼承而來(lái), 基類(lèi)里有一些常用的函數(shù), 以類(lèi)CEntiy為例說(shuō)明如下
            :

            1.    CEntity(const CEntity& ent);

            首先當(dāng)然是拷貝構(gòu)造函數(shù), 在實(shí)際使用實(shí)體過(guò)程中這個(gè)函數(shù)很有用, 當(dāng)然在CEntity的派生類(lèi)中我也會(huì)去實(shí)現(xiàn)其派生類(lèi)的拷貝構(gòu)造函數(shù)
            .


            2.    virtual ~CEntity();

             
            析構(gòu)函數(shù), 這個(gè)就不必說(shuō)了,
            virtual


            3.  virtual CString GetTypeID(void) const;

            此函數(shù)返回一個(gè)CString類(lèi)型的實(shí)體標(biāo)識(shí), 以標(biāo)明到底是那個(gè)類(lèi), 在基類(lèi)中我一般這樣實(shí)現(xiàn): return  _T("ENT_UNKNOW");   很顯然我會(huì)在CEntity的每一個(gè)派生類(lèi)中重載這個(gè)函數(shù), 有了這個(gè)函數(shù), 就可以很方便的從一個(gè)基類(lèi)的指針知道其實(shí)例化的到底是哪一個(gè)派生類(lèi)的對(duì)象這樣就可以很方便的管理系統(tǒng)中多個(gè)相似數(shù)據(jù)實(shí)體就可以把所有的數(shù)據(jù)實(shí)體實(shí)例化為基類(lèi)的指針關(guān)于數(shù)據(jù)實(shí)體的接口都可以用基類(lèi)的指針或者引用類(lèi)型而不用去擔(dān)心他到底是那個(gè)派生類(lèi)的對(duì)象當(dāng)然也可以 virtual int GetTypeID(void) const;  virtual DWORD GetTypeID(void) const; virtual DWORD GetClassID(void) const;等等。

            4.        virtual void Initiate(void);

            數(shù)據(jù)初始化。 初始化數(shù)據(jù)實(shí)體的數(shù)據(jù).

             

            5  virtual void Reset(void);

            數(shù)據(jù)復(fù)位操作。把數(shù)據(jù)實(shí)體復(fù)位到某一狀態(tài).

             

            5.        virtual CEntity * Clone(void) const;

            克隆數(shù)據(jù)實(shí)體. 這個(gè)函數(shù)一般這樣實(shí)現(xiàn): return new CEntity(*this);

             

            6.        virtual void Serialize(CArchive& ar);

            數(shù)據(jù)串行化. 以實(shí)現(xiàn)數(shù)據(jù)實(shí)體左右移方式的對(duì)數(shù)據(jù)實(shí)體賦值,保存等操作. 常把其與CMemFile一起使用,感覺(jué)效果很好.唯一不足的是解決數(shù)據(jù)實(shí)體版本升級(jí)時(shí)的數(shù)據(jù)一致性的問(wèn)題很麻煩.


            7.        virtual BOOL DataSet(const CEntity& ent);

            刷新數(shù)據(jù),實(shí)現(xiàn)數(shù)據(jù)實(shí)體之間的賦值操作.這個(gè)函數(shù)主要是為了解決上一篇所提的問(wèn)題( C++隨筆關(guān)于virtual poperator = ( 05-22 01:09) ). 可以把他設(shè)為protected類(lèi)型, operator=結(jié)合起來(lái)使用, poperator =調(diào)用.


            8.           const CEntity& operator=(const CEntity& ent);

            賦值操作.在派生類(lèi)中也會(huì)重載operator=, 不是重載基類(lèi)的operator=.


            9.        另外如果存在數(shù)據(jù)比較的話, 會(huì)重載operator==操作符.

             friend bool operator==(const CEntity& ent1, const CEntity& ent2);

             friend bool operator!=(const CEntity& ent1, const CEntity& ent2);

             

            謝謝關(guān)注~~~

            以下附三相電流電壓數(shù)據(jù)實(shí)體部分實(shí)現(xiàn)代碼:

             

            class CThreePhaseEntity: public CEntity

            {

            public:

                   CThreePhaseEntity ();

                   CThreePhaseEntity (const CSixPhaseEntity& ent);

                   ~CSixPhaseEntity();

            public:

                   CString GetTypeID(void) const;

                   void Initiate(void);

                   void Reset(void);

             

            public:

                   CEntity * Clone(void) const;

                   void Serialize(CArchive& ar);

                   BOOL DataSet(const CEntity& ent);

             

            public:

                   const CSixPhaseEntity& operator=(const CSixPhaseEntity& ent);

                   friend bool operator==(const CSixPhaseEntity& ent1, const CSixPhaseEntity& ent2);

                   friend bool operator!=(const CSixPhaseEntity& ent1, const CSixPhaseEntity& ent2);

             

            public:

            // 獲取三相數(shù)據(jù) , 內(nèi)聯(lián)函數(shù)

                   const float& GetSixPhaseData(int nDateType, int nPhaseMark) const;

                   // 修改三相數(shù)據(jù) , 內(nèi)聯(lián)函數(shù)

                   void SetSixPhaseData(int nDataType, int nPhaseMark, const float& fData);

             

            private:   

                   float m_gfRange[3];  // 幅值 ,

                   float m_gfPhase[3];  // 相位 ,

                   float m_gfFrequency[3];  // 頻率

            };

             

             

             

            ///******cpp 文件

             

            CThreePhaseEntity:: CThreePhaseEntity ()

            {

                   Initiate();

            }

             

            CThreePhaseEntity:: CThreePhaseEntity (const CThreePhaseEntity & ent)

            {

                   for(int i=0; i<3; i++)

                   {

                          m_gfRange[i] = ent.m_gfRange[i];

                          m_gfPhase[i] = ent.m_gfPhase[i];

                          m_gfFrequency[i] = ent.m_gfFrequency[i];

                   }

            }

             

            CThreePhaseEntity::~ CThreePhaseEntity ()

            {

            }

             

            CString CThreePhaseEntity::GetTypeID(void) const

            {

                   return _T("ENT_THREEPHASE ");

            }

             

            void CThreePhaseEntity::Initiate()

            {

                   for(int i=0; i<3; i++)

                   {

                          m_gfRange[i] = 0.0f;

                          m_gfPhase[i] = 0.0f;

                          m_gfFrequency[i] = 0.0f;

                   }

            }

             

            void CThreePhaseEntity::Reset(void)

            {

                   for(int i=0; i<3; i++)

                   {

                          m_gfRange[i] = 57.740f;

            m_gfFrequency[i] = 50.0f;

            }

            m_ gfPhase [0] = 0.0f

            m_ gfPhase [1] = -120.0f

            m_ gfPhase [2] = 120.0f

            }

             

            void CThreePhaseEntity::Serialize(CArchive& ar)

            {

                   if(ar.IsStoring())

                   {

                          for(int i=0; i<3; i++)

            {

            ar<<m_gfRange[i]<<m_gfPhase[i]<<m_gfFrequency[i];

            }

                   }

                   else

                   {

                          for(int i=0; i<3; i++)

            {

            ar>>m_gfRange[i]>>m_gfPhase[i]>>m_gfFrequency[i];

            }

                   }

            }

             

            BOOL CThreePhaseEntity::DataSet(const CEntity& ent)

            {

                   if(GetTypeID() != ent.GetTypeID()) return FALSE;

                  

                   const CThreePhaseEntity * pEnt = reinterpret_cast<const CThreePhaseEntity *>(&ent);

             

                   (*this) = (*pEnt);

             

                   return TRUE;

            }

             

            CEntity * CThreePhaseEntity::Clone(void) const

            {

                   return new CThreePhaseEntity (*this);

            }

             

            const CThreePhaseEntity & CThreePhaseEntity::operator=(const CThreePhaseEntity & ent)

            {

                   if(this == &ent) return *this;

             

                   for(int i=0; i<3; i++)

                   {

                          m_gfRange[i] = ent.m_gfRange[i];

                          m_gfPhase[i] = ent.m_gfPhase[i];

                          m_gfFrequency[i] = ent.m_gfFrequency[i];

                   }

             

                   return *this;

            }

             

            bool operator==(const CThreePhaseEntity & ent1, const CThreePhaseEntity & ent2)

            {

                   for(int i=0; i<3; i++)

                   {

                          if(ent1.m_gfRange[i] != ent2.m_gfRange[i]) return false;

                          if(ent1.m_gfPhase[i] != ent2.m_gfPhase[i]) return false;

                          if(ent1.m_gfFrequency[i] != ent2.m_gfFrequency[i]) return false;

                   }

             

                   return true;

            }

             

            bool operator!=(const CThreePhaseEntity & ent1, const CThreePhaseEntity & ent2)

            {

                   return (ent1 == ent2) ? false : true;

            }

            posted on 2006-05-30 23:14 erran 閱讀(668) 評(píng)論(0)  編輯 收藏 引用 所屬分類(lèi): C & C++
            国产午夜精品理论片久久影视 | 久久99久久99精品免视看动漫| 亚洲国产美女精品久久久久∴ | 韩国三级中文字幕hd久久精品| 精品久久久久中文字幕一区| 久久久久免费精品国产| 日本免费一区二区久久人人澡| 狠狠色丁香婷婷综合久久来| 久久免费国产精品一区二区| 国产精品久久久久一区二区三区| 久久夜色精品国产www| 亚洲精品NV久久久久久久久久| 婷婷久久综合九色综合绿巨人 | 久久综合综合久久综合| 婷婷五月深深久久精品| 亚洲国产成人久久综合一| 久久久噜噜噜久久中文字幕色伊伊| 午夜精品久久久久久| 中文无码久久精品| 国产精品伊人久久伊人电影 | 久久水蜜桃亚洲av无码精品麻豆| MM131亚洲国产美女久久| 国产国产成人久久精品| 久久久久久综合网天天| 99热成人精品免费久久| 精品综合久久久久久97| 嫩草影院久久99| 久久亚洲sm情趣捆绑调教| 国产91久久精品一区二区| 欧美亚洲日本久久精品| 久久精品国产免费一区| 久久久www免费人成精品| 婷婷久久综合九色综合98| 一97日本道伊人久久综合影院| 久久99精品久久久久子伦| 四虎国产精品成人免费久久| 色偷偷888欧美精品久久久| 久久狠狠高潮亚洲精品| 精品久久久一二三区| 国产精品99久久不卡| 精品九九久久国内精品|