params.cpp
来自「此文件包含了在linux下实现tpr-tree索引的源代码」· C++ 代码 · 共 127 行
CPP
127 行
//--------------------------------------------------------------------// params.cpp// ---------- // A simple processor of parameter files// Implemented: TParams//// Moving point workload generator v 1.1 // Copyright(c) 1999-2001, Aalborg University//#include "params.h"#include <iostream.h>#include <string.h>#include <stdio.h>#include <stdlib.h>#include <ctype.h>#define isnamechar(a) (isalnum(a) || (a) == '_')//------------------------------------------------TParams::TParams (const char* fname) : error(false), silent(false){ FILE* pf; int len; if ((pf = fopen (fname, "rt")) == NULL) { cout << endl << "GENERATOR Error: Unable to open the parameters file " << fname << endl; exit (1); } fseek (pf, 0L, SEEK_END); len = (int) ftell (pf); rewind (pf); buffer = new char[len+1]; fread (buffer, len, 1, pf); buffer[len] = '\x0'; fclose (pf);}//------------------------------------------------TParams::~TParams(){ delete buffer;}//------------------------------------------------// strname - Function for locating the name in the string,// name being defind the same way as identifier is defined// in most programming languages//static char* strname (char* buffer, const char* name){ char* p = buffer; int len = strlen (name); do { p = strstr (++p, name); } while (p && (p[-1] != '\n' || isnamechar(p[len]))); return p;}//------------------------------------------------// getRaw - returned string is internal buffer and// is valid only until the subsequent call to getRaw.// If end != NULL then pointer to the ending semicolon of// parameter is returned in end.// Returns NULL if parameter cannot be found.//char* TParams::getRaw (const char* pname, char** end){ static char ret[50]; int l; char* e; char* p = strname (buffer, pname); if (p) p = strchr(p, ':'); if (!p) { if (!silent) cout << endl << "GENERATOR Warning: Cannot find the parameter " << pname << endl; return NULL; } e = strchr (++p, ';'); if (!e) e = strchr(p, '\n'); l = e - p < 50 ? e - p : 49; memcpy (ret, p, l); ret[l] = '\x0'; if (end) *end = e; return ret;}//------------------------------------------------long TParams::getInt (const char* pname){ char* tmp = getRaw (pname); error = !tmp; return tmp ? atol (tmp) : 0;}//------------------------------------------------double TParams::getFloat (const char* pname){ char* tmp = getRaw (pname); error = !tmp; return tmp ? atof (tmp) : 0;}//------------------------------------------------char* TParams::getString (const char* pname){ char* tmp = getRaw (pname); error = !tmp; return tmp; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?