Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1067076
  • 博文数量: 264
  • 博客积分: 6005
  • 博客等级: 大校
  • 技术积分: 2798
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-08 20:15
文章分类

全部博文(264)

文章存档

2011年(42)

2010年(213)

2009年(4)

2008年(2)

2007年(3)

分类:

2010-04-16 23:30:52

贴点重构的,以后我也会多写些重构的文章,因为,我觉得重构时做软件的必须学的东西。而现实是大家对重构不怎么感兴趣,但是重构确实是非常重要的,不然代码就会慢慢的老死。
//
重构片段1
 switch (m_nPhase) //
    {
    case 0: //LABC
        {
            (pBaseTestItem->m_baseElementList)[Ua] = m_testvoltage;
            (pBaseTestItem->m_baseElementList)[Ub] = m_testvoltage;
            (pBaseTestItem->m_baseElementList)[Uc] = m_testvoltage;
            (pBaseTestItem->m_baseElementList)[Ia] = m_testcurrent;
            (pBaseTestItem->m_baseElementList)[Ib] = m_testcurrent;
            (pBaseTestItem->m_baseElementList)[Ic] = m_testcurrent;
        }
        break;
    case 1: //LA
        {
            (pBaseTestItem->m_baseElementList)[Ua] = m_testvoltage;
            (pBaseTestItem->m_baseElementList)[Ub] = "0.000";
            (pBaseTestItem->m_baseElementList)[Uc] = "0.000";
            (pBaseTestItem->m_baseElementList)[Ia] = m_testcurrent;
            (pBaseTestItem->m_baseElementList)[Ib] = "0.000";
            (pBaseTestItem->m_baseElementList)[Ic] = "0.000";
        }
        break;
    case 2: //LB
        {
            (pBaseTestItem->m_baseElementList)[Ua] = "0.000";
            (pBaseTestItem->m_baseElementList)[Ub] = m_testvoltage;
            (pBaseTestItem->m_baseElementList)[Uc] = "0.000";
            (pBaseTestItem->m_baseElementList)[Ia] = "0.000";
            (pBaseTestItem->m_baseElementList)[Ib] = m_testcurrent;
            (pBaseTestItem->m_baseElementList)[Ic] = "0.000";
        }
        break;
    case 3: //LC
        {
            (pBaseTestItem->m_baseElementList)[Ua] = "0.000";
            (pBaseTestItem->m_baseElementList)[Ub] = "0.000";
            (pBaseTestItem->m_baseElementList)[Uc] = m_testvoltage;
            (pBaseTestItem->m_baseElementList)[Ia] = "0.000";
            (pBaseTestItem->m_baseElementList)[Ib] = "0.000";
            (pBaseTestItem->m_baseElementList)[Ic] = m_testcurrent;
        }
        break;
    default:
        break;

    }

//===========表驱动重构第一次====================

typedef struct {
    int nPhase; //Ïàλ, 0:LABC,1:LA,2:LB,3:LC
    bool bUa; //AÏàµçѹÊÇ·ñÉèÖÃ
    bool bUb; //BÏàµçѹÊÇ·ñÉèÖÃ
    bool bUc; //CÏàµçѹÊÇ·ñÉèÖÃ
    bool bIa; //AÏàµçÁ÷ÊÇ·ñÉèÖÃ
    bool bIb; //BÏàµçÁ÷ÊÇ·ñÉèÖÃ
    bool bIc; //CÏàµçÁ÷ÊÇ·ñÉèÖÃ
}OutPutVoltageCurrent;
OutPutVoltageCurrent outColtageCurrent[] =
{
    {0,1,1,1,1,1,1},
    {1,1,0,0,1,0,0},
    {2,0,1,0,0,1,0},
    {3,0,0,1,0,0,1}
}
void CAddItem::PM_SetOutTestVoltageCurrent(int nPhase, CBaseTestItem* pBaseTestItem, float fVoltage, float fCurrent)
{
    if (! pBaseTestItem) {
        return ;
    }
    if (outColtageCurrent[nPhase].bUa) {
        (pBaseTestItem->m_baseElementList)[Ua] = fVoltage;
    } else {
        (pBaseTestItem->m_baseElementList)[Ua] = 0.0f;
    }
    if (outColtageCurrent[nPhase].bUb) {
        (pBaseTestItem->m_baseElementList)[Ub] = fVoltage;
    } else {
        (pBaseTestItem->m_baseElementList)[Ub] = 0.0f;
    }
    if (outColtageCurrent[nPhase].bUc) {
        (pBaseTestItem->m_baseElementList)[Uc] = fVoltage;
    } else {
        (pBaseTestItem->m_baseElementList)[Uc] = 0.0f;
    }
    if (outColtageCurrent[nPhase].bIa) {
        (pBaseTestItem->m_baseElementList)[Ia] = fCurrent;
    } else {
        (pBaseTestItem->m_baseElementList)[Ia] = 0.0f;
    }
    if (outColtageCurrent[nPhase].bIb) {
        (pBaseTestItem->m_baseElementList)[Ib] = fCurrent;
    } else {
        (pBaseTestItem->m_baseElementList)[Ib] = 0.0f;
    }
    if (outColtageCurrent[nPhase].bIc) {
        (pBaseTestItem->m_baseElementList)[Ic] = fCurrent;
    } else {
        (pBaseTestItem->m_baseElementList)[Ic] = 0.0f;
    }

}

//===============第二次重构=====================

void CAddItem::PM_SetOutTestVoltageCurrent(int nPhase, CBaseTestItem* pBaseTestItem,
                                                                                  float fVoltage, float fCurrent)
{
    if (! pBaseTestItem) {
        return ;
    }
    (pBaseTestItem->m_baseElementList)[Ua] = 0.0f;
    (pBaseTestItem->m_baseElementList)[Ub] = 0.0f;
    (pBaseTestItem->m_baseElementList)[Uc] = 0.0f;
    (pBaseTestItem->m_baseElementList)[Ia] = 0.0f;
    (pBaseTestItem->m_baseElementList)[Ib] = 0.0f;
    (pBaseTestItem->m_baseElementList)[Ic] = 0.0f;
    if (outColtageCurrent[nPhase].bUa) {
        (pBaseTestItem->m_baseElementList)[Ua] = fVoltage;
    }
    if (outColtageCurrent[nPhase].bUb) {
        (pBaseTestItem->m_baseElementList)[Ub] = fVoltage;
    }
    if (outColtageCurrent[nPhase].bUc) {
        (pBaseTestItem->m_baseElementList)[Uc] = fVoltage;
    }
    if (outColtageCurrent[nPhase].bIa) {
        (pBaseTestItem->m_baseElementList)[Ia] = fCurrent;
    }
    if (outColtageCurrent[nPhase].bIb) {
        (pBaseTestItem->m_baseElementList)[Ib] = fCurrent;
    }
    if (outColtageCurrent[nPhase].bIc) {
        (pBaseTestItem->m_baseElementList)[Ic] = fCurrent;
    }
}

其实上面的代码还可以进一步重构,但是我觉得没有必要再深入了,因为要重构的其它地方还很多。重构要的是稳步小进。

阅读(761) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~