template.cpp

来自「J-Alice是一个用C++实现的Ailcebot的克隆。它可以做为一个mini」· C++ 代码 · 共 55 行

CPP
55
字号
/** * Before using Template, even though slower, I think used less * memory without this class .. can't remember. */#include "Template.h"#include "Kernel.h"//	Can't do the auto-reloading from inside the Template function .. it's just//	plain wrong!//	Need a static function to reload the AIML (if required), then forward the//	request on to the actual Template .. somehow :Pvector<string> Template::filenames;vector<long> Template::filesizes;string Template::fetch() {	//	Get the filename ..	const char *filename = Template::getFilename(filenameIx);	//	When have <template/>	if (end == start) {		return "";	}	int length = end - start;	ifstream fin(filename, ios::in | ios::binary);	char *input = new char[length+1];	if(!fin.good())		return "Error reading file";	fin.seekg(start);	fin.read(input, length);	fin.close();	input[length] = '\0';	string ret(input);	delete [] input;	return ret;}const char *Template::getFilename(int index) {	return filenames[index].c_str();}void Template::reloadFile(int index) {	string fn = filenames[index];	long fs = filesizes[index];	ifstream fin;	fin.open(fn.c_str(), ios::in | ios::binary);	fin.seekg(0, ios::end);	int s = fin.tellg();	if (s != fs) {		//	Reload .. return true		filesizes[index] = s;		Kernel::load(fn);	}}

⌨️ 快捷键说明

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