-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.cpp
122 lines (113 loc) · 4.56 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* Copyright (C) 2015 Tenindra Abeywickrama
*
* This file is part of Road Network kNN Experimental Evaluation.
*
* Road Network kNN Experimental Evaluation is free software; you can
* redistribute it and/or modify it under the terms of the GNU Affero
* General Public License as published by the Free Software Foundation;
* either version 3 of the License, or (at your option) any later version.
*
* Road Network kNN Experimental Evaluation 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with Road Network kNN Experimental Evaluation; see
* LICENSE.txt; if not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include <unistd.h>
#include <getopt.h>
#include <vector>
#include <string>
#include "utility/utility.h"
#include "common.h"
#include "command/Command.h"
#include "command/GraphCommand.h"
#include "command/GenerateSampleSetCommand.h"
#include "command/KnnQueryCommand.h"
#include "command/ObjectIndexCommand.h"
#include "command/DynamicGraphCommand.h"
#include "command/TransformInputCommand.h"
#include "command/ExperimentsCommand.h"
#include "command/RoadNetworkIndexCommand.h"
void showUsage(std::string programName);
Command* getCommand(std::string);
int main(int argc, char* argv[])
{
if (argc < 3) {
// Arguments: -c <command>
if (argc == 2) {
std::cerr << "Too few arguments!\n\n";
}
showUsage(argv[0]);
exit(1);
}
/*
* Determine Command to Execute
*/
Command* command;
int opt = getopt(argc,argv, "c:");
switch (opt) {
case 'c':
command = getCommand(optarg);
break;
default:
std::cerr << "Unknown option provided!\n\n";
showUsage(argv[0]);
exit(1);
}
if (command != NULL) {
if (argc == 3) {
// Commands are expected to have more that 2 options/arguments
command->showCommandUsage(argv[0]);
} else {
command->execute(argc, argv);
}
delete command;
} else {
std::cerr << "Command not found!\n\n";
showUsage(argv[0]);
exit(1);
}
}
void showUsage(std::string programName) {
std::cerr << "Usage: " << programName << " -c <command>\n\n"
<< "Index Commands:\n"
<< utility::getFormattedUsageString(constants::IDX_GRAPH_CMD,"Fast in-memory graph") + "\n"
<< utility::getFormattedUsageString(constants::IDX_DYNAMICGRAPH_CMD,"Slower but updateable graph") + "\n"
<< utility::getFormattedUsageString(constants::NETWORK_IDX_CMD,"Other types of graph indexes") + "\n"
<< utility::getFormattedUsageString(constants::OBJ_IDX_CMD,"Object indexes for various graph indexes") + "\n\n"
<< "Query Commands:\n"
<< utility::getFormattedUsageString(constants::QUERY_KNN_CMD,"kNN query") + "\n"
<< "Other Commands:\n"
<< utility::getFormattedUsageString(constants::SAMPLE_SET_CMD,"Generate different types of object sets") + "\n"
<< utility::getFormattedUsageString(constants::TRANSFORM_INPUT_CMD,"Process graphs from known input data sources") + "\n"
<< utility::getFormattedUsageString(constants::EXPERIMENTS_CMD,"Run knn experiments") + "\n\n"
<< "Note: Execute commands without parameters to view usage and all options\n";
}
Command* getCommand(std::string commandName) {
/*
* Determine Command
*/
Command* command = NULL;
if (commandName == constants::IDX_GRAPH_CMD) {
command = new GraphCommand();
} else if (commandName == constants::IDX_DYNAMICGRAPH_CMD) {
command = new DynamicGraphCommand();
} else if (commandName == constants::QUERY_KNN_CMD) {
command = new KnnQueryCommand();
} else if (commandName == constants::SAMPLE_SET_CMD) {
command = new GenerateSampleSetCommand();
} else if (commandName == constants::OBJ_IDX_CMD) {
command = new ObjectIndexCommand();
} else if (commandName == constants::TRANSFORM_INPUT_CMD) {
command = new TransformInputCommand();
} else if (commandName == constants::EXPERIMENTS_CMD) {
command = new ExperimentsCommand();
} else if (commandName == constants::NETWORK_IDX_CMD) {
command = new RoadNetworkIndexCommand();
}
return command;
}