コード例 #1
0
ファイル: TInputFile.cpp プロジェクト: sakeel/ABCtoolbox
void TInputFile::initializeScriptAfterSimulation(my_string gotScript, my_string gotParameter){
	vector<my_string> scriptParam;
	while(!gotParameter.empty()){
		scriptParam.push_back(gotParameter.extract_sub_str(*"#"));
		gotParameter.remove(0,1);
	}
	valuesToPassToScriptAfterSimulations=new my_string[scriptParam.size()];
	numValuesToPassToScriptAfterSimulations=scriptParam.size();
	for(int i=0;i<scriptParam.size();++i){
		if(scriptParam[i].contains("SIMINPUTNAME")){
			my_string a=scriptParam[i].extract_after(11);
			if(a.empty()) valuesToPassToScriptAfterSimulations[i]=newSimulationProgramInputFilenames[0];
			else valuesToPassToScriptAfterSimulations[i]=newSimulationProgramInputFilenames[a.toInt()];
		} else {
			if(scriptParam[i]=="SIMNUM") checkParametersPassedToScriptAfterSimulations=true;
			else {
				//check priors
				if(priors->isPrior(scriptParam[i])) checkParametersPassedToScriptAfterSimulations=true;
			}
			valuesToPassToScriptAfterSimulations[i]=scriptParam[i];
		}
	}
	if(checkParametersPassedToScriptAfterSimulations) scriptAfterSimulations=new TExecuteProgram(gotScript.c_str());
	else scriptAfterSimulations=new TExecuteProgram(gotScript.c_str(), valuesToPassToScriptAfterSimulations, numValuesToPassToScriptAfterSimulations);

}
コード例 #2
0
ファイル: NFA.cpp プロジェクト: 02xiaoma/my_regex
void my_regex::NFA::create_nfa_node(const my_string &reg)
{
	// 第一遍遍历的时候主要处理\开头引出的特殊符号
	std::vector<p_element> element_vec;
	element_vec.reserve(reg.length());
	p_element elem;
	for (int i = 0; i < reg.length(); i++)
	{
		switch (reg[i])
		{
		case my_char('+'):
		case my_char('?'):
		case my_char('*'):
			elem = p_element(new num_symbol(reg[i]));
			element_vec.push_back(elem);
			break;
		case my_char('\\'):
			elem = p_element(new num_symbol(reg[++i]));// 注意,这里现在是把所有跟在反斜杠后面的字符都当作普通字符来处理
			element_vec.push_back(elem);
			break;
		case my_char('.'):
			elem = p_element(new point_symbol);
			element_vec.push_back(elem);
			break;
		case my_char('('):
			elem = p_element(new open_parentheses);
			element_vec.push_back(elem);
			break;
		case my_char(')'):
			elem = p_element(new close_parentheses);
			element_vec.push_back(elem);
			break;
		case my_char('|'):
			elem = p_element(new or_symbol);
			element_vec.push_back(elem);
			break;
		default:
			elem = p_element(new character(reg[i]));
			element_vec.push_back(elem);
			break;
		}
	}

	// 将基础元素转化为前缀表达式
	element_vec_2_prefix_exp(element_vec);
	//assert(element_vec.size() == 1);//最后只剩下一个大的前缀表达式//已经在函数里判断过了
	p_nfa_node begin(new nfa_node), end(new nfa_node);
	prefix_exp_2_nfa_node(element_vec, begin, end);
	end->accept = true;

	// todo:加入清理内存的操作
	start = begin;
}
コード例 #3
0
void add_text(tuple* t, int id, my_string key_value) {
    ++t->key_num;
    t->aid.add(id);
    t->offset.add(t->len);
    t->data = t->data + key_value;
    t->len += key_value.size();
    return;
}
コード例 #4
0
ファイル: TInputFile.cpp プロジェクト: sakeel/ABCtoolbox
//---------------------------------------------------------------------------
TInputFile::TInputFile(my_string siminputname, TPriorVector* gotPriors){
	//siminputname may contain several files....
	my_string buf, extension;
	while(!siminputname.empty()){
		buf=siminputname.extract_sub_str('#');
		siminputname.remove(0,1);
		buf.trim_blanks();
		if(!buf.empty()){
			simulationProgramInputFilenames.push_back(buf);
			extension=buf.get_file_extension();
			buf.remove_file_extension();
			buf+="-temp";
			buf+=extension;
			newSimulationProgramInputFilenames.push_back(buf);
		}
	}
   priors=gotPriors;
   checkParametersPassedToSimulationProgram=false;
   checkParametersPassedToScriptAfterSimulations=false;
}
コード例 #5
0
ファイル: NFA.cpp プロジェクト: 02xiaoma/my_regex
size_t my_regex::NFA::try_match(const my_string &str)
{
	size_t farthest = 0;//记录匹配到的最远距离
	std::vector<cp_nfa_node> current_pnodes, next_pnodes;
	current_pnodes.push_back(start);
	get_epson_closure(current_pnodes);
	bool matched = start->accept;//当前字符匹配后是否满足正则表达式
	for (auto &cur_node : current_pnodes)
	{
		matched |= cur_node->accept;
	}
	for (size_t i = 0; i < str.length(); i++)
	{
		matched = false;
		next_pnodes.clear();
		for (auto &cur_node : current_pnodes)
		{
			// 先沿着正常边走
			for (auto &n_edg : cur_node->norm_edgs)
			{
				if (n_edg.c == str[i])
				{
					next_pnodes.push_back(n_edg.p_next_node);
				}
			}

			// 小数点通配符
			for (auto &p_node : cur_node->point_edgs)
			{
				next_pnodes.push_back(p_node.p_next_node);
			}
		}
		if (next_pnodes.empty())
		{
			// 匹配不下去了,停止
			return farthest;
		}
		else
		{
			current_pnodes.swap(next_pnodes);
			get_epson_closure(current_pnodes);
			for (auto &cur_node : current_pnodes)
			{
				matched |= cur_node->accept;
			}	
			if (matched)
			{
				farthest = i+1;
			}
		}
	}
	return farthest;
}
コード例 #6
0
ファイル: TInputFile.cpp プロジェクト: sakeel/ABCtoolbox
//------------------------------------------------------------------------------
void TInputFile::initializeSimulationProgramm(my_string gotSimulationprogram, my_string gotParameter){
	vector<my_string> simParam;
	while(!gotParameter.empty()){
	    simParam.push_back(gotParameter.extract_sub_str(*"#"));
	    gotParameter.remove(0,1);
	}
	valuesToPassToSimulationProgramm=new my_string[simParam.size()];
	numValuesToPassToSimulationProgramm=simParam.size();
	for(int i=0;i<(int)simParam.size();++i){
		//check tags
		if(simParam[i].contains("SIMINPUTNAME")){
			my_string a=simParam[i].extract_after(11);
			if(a.empty()) valuesToPassToSimulationProgramm[i]=newSimulationProgramInputFilenames[0];
			else valuesToPassToSimulationProgramm[i]=newSimulationProgramInputFilenames[a.toInt()];
		} else {
			if(simParam[i]=="SIMNUM"){
				checkParametersPassedToSimulationProgram=true;
				break;
			}
			else {
				//check priors
				if(priors->isPrior(simParam[i])){
					checkParametersPassedToSimulationProgram=true;
				}
			}
			valuesToPassToSimulationProgramm[i]=simParam[i];
		}
	}
	if(gotSimulationprogram=="INTERNALGLM"){
		if(!checkParametersPassedToSimulationProgram) throw TException("The INTERNALGLM program requires model parameter tag as arguments!", _FATAL_ERROR);
		simulationProgram=new TGLM(valuesToPassToSimulationProgramm, numValuesToPassToSimulationProgramm);
	} else {
		if(checkParametersPassedToSimulationProgram) simulationProgram=new TExecuteProgram(gotSimulationprogram.c_str());
		else simulationProgram=new TExecuteProgram(gotSimulationprogram.c_str(), valuesToPassToSimulationProgramm, numValuesToPassToSimulationProgramm);
	}
}
コード例 #7
0
ファイル: TParameters.cpp プロジェクト: sakeel/ABCtoolbox
//---------------------------------------------------------------------------
TParameters::TParameters(my_string fileName, int numCommandLineParams, my_string* commandLineParams){
	ifstream is (fileName.c_str());
	if(!is) throw TException("Input file '" + fileName + "' could not be opened!", _FATAL_ERROR);
	my_string buf, my_name;
	my_string my_value;
	while(is.good() && !is.eof()){
		strstream isLine;                   // create the new stream
		buf.read_line(is);                  // read the line
		buf=buf.extract_before_doubleSlash();   // remove the commentated part
		if(!buf.empty()){
		// allocate the line to a new stream for easy reading
           isLine << buf;
			my_name.read_to_delim(isLine);
			isLine >> ws;
			my_value.read_to_delim(isLine);
			if(!my_name.empty() && !my_value.empty()){
				mapParameter[my_name]= my_value;
			}
		}
	}
コード例 #8
0
bool my_string::operator < (const my_string &a) const
{
    return strcmp(c_str(), a.c_str()) < 0;
}
コード例 #9
0
ファイル: TExecuteProgram.cpp プロジェクト: sakeel/ABCtoolbox
//---------------------------------------------------------------------------
int TExecuteProgram::execute(my_string passedParam){
	// parameters to pass have to be char*!!!!!!
	if(myPassedParamIdentifier>0 && passedParam!="") myParameter[myPassedParamIdentifier]=passedParam.c_str();
	return execute();
}
コード例 #10
0
ファイル: my_string.cpp プロジェクト: Doxxer/SPbAU-Fall-2013
my_string::my_string(my_string const &str) : data_(new char[str.length() + 1])
{
    strcpy(data_, str.c_str());
}