| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- #include "StdAfx.h"
- #include "FlowTemplate.h"
- #include "CellBase.h"
- #include "IFlowDataProvider.h"
- #include <regex>
- CFlowTemplate::CFlowTemplate(void) : m_Type(FLOW_UNKNOWN), m_Concurrency(1)
- {
- m_CellMap.InitHashTable(MAX_LENGTH_HASH);
- }
- CFlowTemplate::~CFlowTemplate(void)
- {
- __release();
- }
- /*****************************************************************
- **【函数名称】 __release
- **【函数功能】 释放所有cell
- **【参数】
- **【返回值】
- ****************************************************************/
- void CFlowTemplate::__release( void )
- {
- if(!m_CellMap.IsEmpty())
- {
- int Key = 0;
- CCellBase *pCell = NULL;
- POSITION pos = m_CellMap.GetStartPosition();
- while(pos != NULL)
- {
- m_CellMap.GetNextAssoc(pos, Key, pCell);
- if(pCell != NULL)
- delete pCell;
- }
- m_CellMap.RemoveAll();
- }
- }
- /*****************************************************************
- **【函数名称】 fillData
- **【函数功能】 解析流程文件为数据字段赋值
- **【参数】 Provider:数据提供者对象
- **【返回值】
- ****************************************************************/
- bool CFlowTemplate::fillData( IFlowDataProvider& Provider )
- {
- if(!Provider.getData(FLOW_ATTRIBUTE_NAME, m_Name))
- return false;
- CString Data;
- if(!Provider.getData(FLOW_ATTRIBUTE_TYPE, Data))
- return false;
- if(Data == FLOW_TYPE_STR_NORMAL)
- m_Type = FLOW_NORMAL;
- else if(Data == FLOW_TYPE_STR_AUTO)
- m_Type = FLOW_AUTO;
- else
- m_Type = FLOW_SUB;
- if(!Provider.getData(FLOW_ATTRIBUTE_MATCHED_NUM, m_MatchedNum))
- return false;
- if(!Provider.getData(FLOW_ATTRIBUTE_ASSO_LINE, m_MatchedLine))
- return false;
- if(m_Type == FLOW_AUTO)
- {
- if(!Provider.getData(FLOW_ATTRIBUTE_CONCURRENCY, Data))
- return false;
- else
- {
- sscanf_s(Data, _T("%d"), &m_Concurrency);
- if(m_Concurrency < 1)
- return false;
- }
- }
- return true;
- }
- /*****************************************************************
- **【函数名称】 accept
- **【函数功能】 填充cell map
- **【参数】 CellPos:节点编号
- pCell:节点对象
- **【返回值】
- ****************************************************************/
- void CFlowTemplate::accept( int CellPos, CCellBase* pCell )
- {
- ASSERT(pCell != NULL);
- m_CellMap.SetAt(CellPos, pCell);
- }
- /*****************************************************************
- **【函数名称】 getCellPos
- **【函数功能】 根据节点名称查找节点
- **【参数】 CellName:节点名称
- **【返回值】
- ****************************************************************/
- int CFlowTemplate::getCellPos( const CString& CellName )
- {
- int Key = 0;
- CCellBase *pCell = NULL;
- POSITION pos = m_CellMap.GetStartPosition();
-
- while(pos != NULL)
- {
- m_CellMap.GetNextAssoc(pos, Key, pCell);
- if(pCell->name() == CellName)
- return pCell->position();
- }
- return 0;
- }
- /*****************************************************************
- **【函数名称】 findCell
- **【函数功能】 根据节点编号查找节点
- **【参数】 CellPos:节点编号
- **【返回值】 节点对象
- ****************************************************************/
- CCellBase* CFlowTemplate::findCell( int CellPos )
- {
- CCellBase *pCell = NULL;
- m_CellMap.Lookup(CellPos, pCell);
- if(pCell != NULL)
- return pCell->copy();
- return NULL;
- }
- /*****************************************************************
- **【函数名称】 matchLine
- **【函数功能】 匹配线路
- **【参数】 TrunkId:外线Id
- **【返回值】 0:不匹配;1:匹配;-1为默认流程
- ****************************************************************/
- int CFlowTemplate::matchLine( UINT TrunkId )
- {
- if(m_MatchedLine.IsEmpty())
- return 0;
- if(m_MatchedLine == "|-1|" )
- return -1;
- CString Temp;
- Temp.Format("|%lu|", TrunkId);
- if(m_MatchedLine.Find(Temp) != -1)
- return 1;
- return 0;
- }
- /*****************************************************************
- **【函数名称】 matchCaller
- **【函数功能】 根据主叫号码分析流程的适用性
- **【参数】 Caller:主叫号码
- **【返回值】 匹配true,否则false
- ****************************************************************/
- bool CFlowTemplate::matchCaller( LPCTSTR Caller )
- {
- std::string CallerString(Caller);
- std::regex Reg(m_MatchedNum);
- std::smatch Res;
- bool IsMatched = false;
- IsMatched = std::regex_match(CallerString, Res, Reg);
- return IsMatched;
- }
- /*****************************************************************
- **【函数名称】 isMatchedPreCall
- **【函数功能】 是否适用预测呼叫
- **【参数】
- **【返回值】 匹配true,否则false
- ****************************************************************/
- bool CFlowTemplate::isMatchedPreCall( void ) const
- {
- if(m_MatchedLine.IsEmpty())
- return false;
- if(m_MatchedLine == "|-2|" )
- return true;
- else
- return false;
- }
|