⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 predicate.cpp

📁 浙江大学 RoboCup3D 2006 源代码
💻 CPP
字号:
/*************************************************************************** *   Copyright (C) 2004 - 2006 by ZJUBase                                  *
 *                                National Lab of Industrial Control Tech. * *                                Zhejiang University, China               * *                                                                         * *   Achievements of ZJUBase in RoboCup Soccer 3D Simulation League:       *
 *    In RoboCup championship,                                             *
 *      - June 2006 - 3rd place in RoboCup 2006, Bremen, Germany (lost     * *        the semi-final with a coin toss)                                 *
 *      - July 2005 - 3rd place in RoboCup 2005, Osaka, Japan (share the   * *        3rd place with team Caspian)                                     *
 *    In RoboCup local events,                                             *
 *      - April 2006 - 2nd place in RoboCup Iran Open 2006, Tehran, Iran   * *        (lost the final with a coin toss)                                *
 *      - December 2005 - 2nd place in AI Games 2005, Isfahan, Iran        *
 *      - July 2005 - champion in China Robot Competition 2005, Changzhou, * *        China                                                            *
 *      - October 2004 - champion in China Soccer Robot Competition 2004,  * *        Guangzhou, China                                                 *
*                                                                         * *   Team members:                                                         *
 *    Currently the team leader is,                                        * *           Hao JIANG (jianghao@iipc.zju.edu.cn; riveria@gmail.com)       *
 *    In the next season, the leader will be                               * *           Yifeng ZHANG (yfzhang@iipc.zju.edu.cn)                        *
 *    ZJUBase 3D agent is created by                                       * *           Dijun LUO (djluo@iipc.zju.edu.cn)                             *
 *    All the members who has ever contributed:                            * *           Jun JIANG                                                     *
 *           Xinfeng DU (xfdu@iipc.zju.edu.cn)                             *
 *           Yang ZHOU (yzhou@iipc.zju.edu.cn)                             *
 *           Zhipeng YANG                                                  *
 *           Xiang FAN                                                     *
 *                                                                         *
 *   Team Manager:                                                          *
 *      Ms. Rong XIONG (rxiong@iipc.zju.edu.cn)                            *
 *                                                                         *
 *   If you met any problems or you have something to discuss about        * *   ZJUBase. Please feel free to contact us through EMails given below.   * *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * *   This program is distributed in the hope that it will be useful,       * *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * *   GNU General Public License for more details.                          * *                                                                         * *   You should have received a copy of the GNU General Public License     * *   along with this program; if not, write to the                         * *   Free Software Foundation, Inc.,                                       * *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             * ***************************************************************************/#ifndef WIN32
#include "Predicate.h"#include <fstream>#include <iostream>using namespace std;
#define PREDICATE_DEBUG	0
ostream& operator << (ostream& os, const Predicate& pred){	if (pred.name == "" && pred.attr.size() < 1 && pred.child.size() < 1) return os;
	os << "(" << pred.name;	for (int i = 0; i < pred.attr.size(); ++ i) {		os << " " << pred.attr[i];	}	for (multimap<string,Predicate>::const_iterator it = pred.child.begin(); it != pred.child.end(); ++ it) {		os << " " << it->second;	}	os << ")";	
	return os;}
bool Parser::Parse(const string& line, Predicate& pred, int& head){	if (line[head] != '(') {		cerr << "Column " << head << " Syntax error. '(' Missing" << endl;		return false;	}
	for (++ head; head < line.size(); ++ head) {		if (string(" \t\r\n").find(line[head]) != -1) continue;		if (line[head] == ')') break;		if (line[head] == '(') {			Predicate pp;			if (Parse(line, pp, head) == false) {				return false;			}			if (pp.name != "") {				pred.AddChild(pp.name, pp);			}		} else {			int tail = head + 1;			while (tail < line.size() && string(" \t\r\n)").find(line[tail]) == -1) ++ tail;			
			if (pred.name == "") {				pred.name = line.substr(head, tail - head);			} else {				pred.AddValue(line.substr(head, tail - head));			}			
			head = tail;			if (head >= line.size() || line[head] == ')') break;		}	}	
	if (line[head] != ')') {		cerr << "Column " << head << " Syntax error. ')' Missing" << endl;		return false;	}
	return true;}
bool Parser::Parse(const string& line, Predicate& pred){	int head = 0;	pred.name = "";	pred.attr.clear();	pred.child.clear();
	return Parse(line, pred, head);}
bool Parser::Parse(const string& line, vector<Predicate>& preds){	preds.clear();	for (int head = 0; head < line.size(); ++ head) {		preds.push_back(Predicate());		if (Parse(line, preds[preds.size() - 1], head) == false) {			return false;		}	}	return true;}
#if	PREDICATE_DEBUG
int main(){	string line;	fstream in("test.txt");	getline(in, line);	line = line.substr(line.find('('));	vector <Predicate> predList;	if (Parser::Parse(line, predList) == true) {		for (int i = 0; i < predList.size(); ++ i) {			cout << predList[i] << endl;		}	}	return 0;}
#endif
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -