对于默认参数为空的设计技巧

来源:互联网 发布:数据挖掘要学什么 编辑:程序博客网 时间:2024/06/06 02:02

WBXTFValue CWBXTFCEvent::List(const WBXTFString& sType,const WBXTFString& sSubType)
{
 WBXTFAutoLock autoLock(m_eventlock);
 WBXTFValue val;
 BOOL bAllType = FALSE, bAllSubType = FALSE;                                   
 if(sType.length() == 0) bAllType = TRUE;
 if(sSubType.length() == 0) bAllSubType = TRUE;

 LIST_ITEM::iterator index;
 for(index=m_items.begin();index!=m_items.end();index++)
 {
  if(!bAllSubType && sSubType != (*index).sSubType)                    //把所有的例外情况在这里屏蔽
   continue;
  if(!bAllType && sType != (*index).sType)                                     //对于输入的2个参数 如果为空 则把type设为true

   continue;

  WBXTFValue tempVal;                                                                 //如果输入是List(MainType), 就不会对subType敏感
  tempVal["sType"]=(*index).sType;
  tempVal["sSubType"]=(*index).sSubType;
  tempVal["sMachine"]=(*index).sMachine;
  tempVal["uHandle"]=(DWORD)(*index).uHandle;
//  tempVal["sHandleKey"]=(*index).sHandleKey;
  val.Append(tempVal);

 }
 return val;
}

原创粉丝点击