예제 #1
0
//! (static)
Object* JSON::parseJSON(const std::string &s){
	Tokenizer t;

	Tokenizer::tokenList tokens;
	t.getTokens(s.c_str(),tokens);
	Tokenizer::tokenList::iterator it=tokens.begin();
	Object * result= _parseJSON(it,tokens.end());
	if(it!=tokens.end() && !Token::isA<TEndScript>(*it)){
		std::cout << "JSON Syntax Error\n";
	}
	if(result==NULL){
		result=String::create(s);
	}
//	for(it=tokens.begin();it!=tokens.end();++it){
//		Token::removeReference(*it);
//	}
	return result;
}
예제 #2
0
int main(int ac, char* av[]) {

    std::string str("");
    for(int i=1; i<ac; i++)
        str += av[i];

    std::cout << "str: '" << str << "'\n";

    std::deque<Token> tok;

    Tokenizer tokenizer;
    tok = tokenizer.getTokens(str);

    std::cout << "tok.size() = " << tok.size() << "\n";

    for (auto it = tok.begin(); it != tok.end(); it++) 
        (*it).dump();

    return EXIT_SUCCESS;
}
예제 #3
0
	void RPedigree::inputPed(string fileString){
		// Authors: Rohan L. Fernando
		// (2005) 
		// Contributors:
		const char* fname = fileString.c_str();
		cout << "reading pedigree file \n";
		if (colName.size() < 3) {
			cerr << "RPedigree::input(): colName.size() < 3 \n";
			cerr << "Did you forget the putColNames method? \n";
			throw exception("Error in RPedigree::input()");
		}
		int indIndex = colName.getIndex("individual");
		if (indIndex == -1){
			cerr << "RPedigree::input(): individual column is missing in colName \n";
			throw exception("Error in RPedigree::input()");
		}
		int sireIndex = colName.getIndex("sire");
		if (sireIndex == -1){
			cerr << "RPedigree::input(): sire column is missing in colName \n";
			throw exception("Error in RPedigree::input()");
		}
		int damIndex = colName.getIndex("dam");
		if (damIndex == -1){
			cerr << "RPedigree::input(): dam column is missing in colName \n";
			throw exception("Error in RPedigree::input()");			
		}
		unsigned numCol = colName.size();			
		double rec = 0, rec1 = 0;
		string indstr, sirestr, damstr;
		ifstream datafile(fname);
		if(!datafile){
			cout<< "Cannot open pedigree file: " << fname << endl;
			exit(1);
		}
		datafile.setf(ios::skipws);
		PNode *ptr;
		std::string sep(" \t,\n\r");
		std::string inputStr;
		Tokenizer colData;
		unsigned COUNT = 0;
		while ( getline(datafile,inputStr) ){
			colData.getTokens(inputStr,sep);
			indstr  = colData[indIndex];
			sirestr = colData[sireIndex];
			damstr  = colData[damIndex];
			rec++;
			if(rec==1000){
				cout<<rec+rec1<<"\r";
				cout.flush();
				rec1 += rec;
				rec = 0;
			}
			if (colData.size() != numCol){
				cerr << " Record " << rec1 + rec << " has " << colData.size() << " columns \n";
				cerr << " Expected " << numCol << endl;
				throw exception("Error in RPedigree::input()"); 
			}
			ptr = new PNode(indstr, sirestr, damstr);
			if (orderedPed) ptr->ind = ++COUNT;
			(*this)[indstr] = ptr;
		}
		datafile.close();
		if(orderedPed){
			seqnPed();
		}
		else {
			generateEntriesforParents();
			codePed();
		}	
		makePedVector();
		calc_inbreeding();
		fillCoder(); 
	}