• <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++博客 :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
              106 Posts :: 1 Stories :: 97 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(12)

            搜索

            •  

            積分與排名

            • 積分 - 177392
            • 排名 - 151

            最新評論

            閱讀排行榜

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

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

            1.    CEntity(const CEntity& ent);

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


            2.    virtual ~CEntity();

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


            3.  virtual CString GetTypeID(void) const;

            此函數(shù)返回一個CString類型的實體標(biāo)識, 以標(biāo)明到底是那個類, 在基類中我一般這樣實現(xiàn): return  _T("ENT_UNKNOW");   很顯然我會在CEntity的每一個派生類中重載這個函數(shù), 有了這個函數(shù), 就可以很方便的從一個基類的指針知道其實例化的到底是哪一個派生類的對象這樣就可以很方便的管理系統(tǒng)中多個相似數(shù)據(jù)實體就可以把所有的數(shù)據(jù)實體實例化為基類的指針關(guān)于數(shù)據(jù)實體的接口都可以用基類的指針或者引用類型而不用去擔(dān)心他到底是那個派生類的對象當(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ù)據(jù).

             

            5  virtual void Reset(void);

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

             

            5.        virtual CEntity * Clone(void) const;

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

             

            6.        virtual void Serialize(CArchive& ar);

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


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

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


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

            賦值操作.在派生類中也會重載operator=, 不是重載基類的operator=.


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

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

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

             

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

            以下附三相電流電壓數(shù)據(jù)實體部分實現(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 閱讀(681) 評論(0)  編輯 收藏 引用 所屬分類: C & C++
            久久91精品国产91| 中文成人久久久久影院免费观看| AV无码久久久久不卡蜜桃| 亚洲色欲久久久综合网| 高清免费久久午夜精品| 久久久综合香蕉尹人综合网| 国产综合久久久久久鬼色| 久久久久久国产精品免费免费| 国内精品久久久久影院老司| 国内精品久久久久影院一蜜桃| 国产一区二区三精品久久久无广告| 久久久亚洲欧洲日产国码是AV| 91精品日韩人妻无码久久不卡 | 久久精品成人欧美大片| 亚洲精品国产美女久久久| 99久久精品国产毛片| 久久久久免费看成人影片| 青青久久精品国产免费看| 久久久国产精品网站| 精品无码久久久久久尤物| 国产精品久久久久久久app| 精品无码久久久久久国产| 69久久精品无码一区二区| 97久久婷婷五月综合色d啪蜜芽| 亚洲а∨天堂久久精品| 久久久久亚洲精品中文字幕| 91超碰碰碰碰久久久久久综合| 7777久久亚洲中文字幕| 欧美黑人激情性久久| 亚洲αv久久久噜噜噜噜噜| 亚洲AV成人无码久久精品老人| 欧美粉嫩小泬久久久久久久| 久久夜色精品国产亚洲av| 超级碰久久免费公开视频| 国产福利电影一区二区三区久久老子无码午夜伦不 | 久久久久久久精品妇女99| 亚洲国产高清精品线久久| 中文成人久久久久影院免费观看 | 国内精品人妻无码久久久影院| 无遮挡粉嫩小泬久久久久久久 | 精品国产一区二区三区久久久狼 |