www.pudn.com > TsapiCallRouting.rar > Rule.cpp


#include "StdAfx.h" 
#include "Rule.h" 
 
CRule::CRule(void) 
{ 
} 
 
CRule::~CRule(void) 
{ 
} 
 
 
 
CRule::CRule(const char * lowerBound, const char * upperBound, const char * destination) { 
	set(lowerBound, upperBound, destination); 
} 
 
 
CRule::CRule(char  *rule, const char *destination) { 
	set(rule, destination); 
} 
 
CRule::CRule(char * rule) { 
	set(rule); 
} 
 
 
CRule::CRule(int lowerBound, int upperBound, int destination) { 
	set(lowerBound,upperBound, destination); 
} 
 
 
void CRule::set(const char * rule) { 
 
	char *delim = "=";	 
	char str[200]; 
	strcpy(str,rule); 
	char *next_token; 
	// str = (char *)(LPCTSTR) rule; 
	char *rulePart = strtok_s(str,delim,&next_token); 
	const char *destPart; 
	if(rulePart != NULL) { 
		destPart = strtok_s(NULL, delim, &next_token); 
		if(destPart == NULL) { 
			_lowerBound = 0; 
			_upperBound = 0; 
		} else  
			set(rulePart,destPart); 
	} else { 
		_lowerBound = 0; 
		_upperBound = 0; 
	} 
} 
void CRule::set(char *  rule,  const char * destination) { 	 
 
	 
	const char *lowerBoundPart = strtok(rule,"-"); 
	const char *upperBoundPart; 
	if(lowerBoundPart != NULL) { 
        upperBoundPart = strtok(NULL,"\0" ); 
	} else { 
		lowerBoundPart=upperBoundPart = NULL; 
	} 
	set(lowerBoundPart,upperBoundPart, destination); 
	 
} 
void CRule::set(int lowerBound, int upperBound, int destination) { 
	_lowerBound = lowerBound; 
	_upperBound = upperBound; 
	_destination = destination; 
} 
 
void CRule::set(const char * lowerBound, const char * upperBound, const char * destination) { 
		if(upperBound == NULL) 
			upperBound = lowerBound; 
		if(lowerBound == NULL) 
			_lowerBound = _upperBound = 0;  
		else 
			set(atoi(lowerBound), atoi(upperBound), atoi(destination)); 
} 
 
boolean CRule::belongs(int number) { 
	 
	if(number >= _lowerBound && number <= _upperBound) { 
		return true; 
	} else { 
		return false; 
	} 
} 
 
int CRule::getLowerBound() { 
	return _lowerBound; 
} 
 
int CRule::getUpperBound() { 
	return _upperBound; 
} 
int CRule::getRoute() { 
	return _destination; 
} 
 
char * CRule::toString(char *message) { 
	sprintf(message, "Lowerbound %d, Upperbound %d, RouteTo %d", _lowerBound, _upperBound, _destination); 
	return message; 
}