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

            常用鏈接

            留言簿(12)

            搜索

            •  

            積分與排名

            • 積分 - 174947
            • 排名 - 151

            最新評論

            閱讀排行榜

            在此聊聊我設計數據實體的一些小伎倆^_^ .........     

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

            1.    CEntity(const CEntity& ent);

            首先當然是拷貝構造函數, 在實際使用實體過程中這個函數很有用, 當然在CEntity的派生類中我也會去實現其派生類的拷貝構造函數
            .


            2.    virtual ~CEntity();

             
            析構函數, 這個就不必說了,
            virtual


            3.  virtual CString GetTypeID(void) const;

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

            4.        virtual void Initiate(void);

            數據初始化。 初始化數據實體的數據.

             

            5  virtual void Reset(void);

            數據復位操作。把數據實體復位到某一狀態.

             

            5.        virtual CEntity * Clone(void) const;

            克隆數據實體. 這個函數一般這樣實現: return new CEntity(*this);

             

            6.        virtual void Serialize(CArchive& ar);

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


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

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


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

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


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

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

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

             

            謝謝關注~~~

            以下附三相電流電壓數據實體部分實現代碼:

             

            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:

            // 獲取三相數據 , 內聯函數

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

                   // 修改三相數據 , 內聯函數

                   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 閱讀(661) 評論(0)  編輯 收藏 引用 所屬分類: C & C++
            久久精品亚洲一区二区三区浴池| 国内精品久久久久久久亚洲| 亚洲国产日韩综合久久精品| 国产精品gz久久久| 久久精品国产精品亚洲下载| 国产精品久久久久一区二区三区| 精品久久久久久国产| 一本色道久久88加勒比—综合| 99久久成人18免费网站| 一级a性色生活片久久无| 久久久久久久久久久久中文字幕 | 99久久国产综合精品网成人影院 | 精品综合久久久久久97超人| 亚洲国产精品久久久久| 久久精品日日躁夜夜躁欧美| 一级做a爰片久久毛片16| 亚洲色欲久久久综合网| 久久青青草原精品国产软件| 久久精品亚洲中文字幕无码麻豆| 一本久久免费视频| 久久天天躁狠狠躁夜夜2020| 青青草原1769久久免费播放| 久久久久亚洲av无码专区喷水 | 天天做夜夜做久久做狠狠| 久久ww精品w免费人成| 亚洲国产小视频精品久久久三级| 日本免费久久久久久久网站| 婷婷五月深深久久精品| 久久久噜噜噜久久中文字幕色伊伊| 99久久精品免费看国产一区二区三区| 久久亚洲精品中文字幕| 狠狠色丁香久久婷婷综合| 国产精品综合久久第一页| 成人资源影音先锋久久资源网| 色综合久久中文字幕综合网| 99久久人人爽亚洲精品美女| 久久99精品久久久久久久久久| 亚洲国产精品久久电影欧美| 久久香综合精品久久伊人| 伊人久久成人成综合网222| 国内精品伊人久久久久妇|