本文整理汇总了C++中Args::getFile方法的典型用法代码示例。如果您正苦于以下问题:C++ Args::getFile方法的具体用法?C++ Args::getFile怎么用?C++ Args::getFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Args
的用法示例。
在下文中一共展示了Args::getFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv) {
QTextStream qout(stdout, QIODevice::WriteOnly);
QTextStream qerr(stderr, QIODevice::WriteOnly);
QTextStream qin(stdin, QIODevice::ReadOnly);
Args args;
args.add(new Arg("h", "help", Arg::setTrue, QVariant(false)));
args.add(new Arg("v", "verbose", Arg::setTrue, QVariant(false)));
//args.add(new Arg("i", "input-file", Arg::readableFile, QVariant("/var/log/postgresql.log")));
args.add(new Arg("i", "input-file", Arg::readableFile,
QVariant("/var/log/postgresql/postgresql-9.1-main.log")));
args.add(new Arg("o", "output-file", Arg::writableFile,
QVariant("report.html")));
args.add(new Arg("u", "users", Arg::toString, QVariant()));
args.add(new Arg("d", "databases", Arg::toString, QVariant()));
args.add(new Arg("top", Arg::toInt, QVariant(20)));
args.add(new Arg("t", "query-types", Arg::toString,
QVariant("SELECT,UPDATE,INSERT,DELETE")));
if(!args.parse(argc, argv)) {
args.help();
return -1;
}
QStringList users = args.getStringList("users");
QStringList databases = args.getStringList("databases");
QStringList query_types = args.getStringList("query-types");
int ret;
QString line;
int start_index;
int stop_index;
int old_query_id;
int new_query_id;
int old_line_id;
int new_line_id;
QString database;
QString user;
QString statement;
uint duration;
QFile input_file;
ret = args.getFile(&input_file, "input-file", QIODevice::ReadOnly | QIODevice::Text);
if(ret)return ret;
QFile output_file;
ret = args.getFile(&output_file, "output-file", QIODevice::WriteOnly | QIODevice::Text);
if(ret)return ret;
QTextStream output(&output_file);
/* display the top N queries */
int top = args.getInt("top");
Queries queries;
old_query_id = -1;
old_line_id = -0;
statement = "";
duration = 0;
QTime timer;
timer.start();
uint lines = 0;
if(input_file.atEnd()) {
qerr << "The input file (" << input_file.fileName();
qerr << ") seems to be empty" << endl;
}
while (!input_file.atEnd()) {
line = input_file.readLine(4096);
lines++;
if(lines % 1000 == 0) {
qout << "Read " << lines << " lines." << endl;
qout.flush();
}
if(line[0] == '\t') {
statement.append(line);
continue;
}
start_index = line.indexOf("[", 15);
start_index = line.indexOf("[", start_index + 3) + 1;
stop_index = line.indexOf("-", start_index);
new_query_id = line.mid(start_index, stop_index - start_index).toInt();
start_index = stop_index + 1;
stop_index = line.indexOf("]", start_index);
new_line_id = line.mid(start_index, stop_index - start_index).toInt();
if(new_query_id != old_query_id || old_line_id < new_line_id) {
old_query_id = new_query_id;
QString hashStatement = Query::normalize(statement);
statement = Query::format(statement);
if((
//.........这里部分代码省略.........