29 #ifndef GRAPHCHI_CMDOPTS_DEF
30 #define GRAPHCHI_CMDOPTS_DEF
44 #define VARIABLE_IS_NOT_USED __attribute__ ((unused))
46 #define VARIABLE_IS_NOT_USED
49 static bool _cmd_configured =
false;
53 static std::map<std::string, std::string> conf;
58 if (conf.find(option_name) != conf.end()) {
59 return conf[option_name];
61 std::cout <<
"ERROR: could not find option " << option_name <<
" from config.";
67 std::string default_value) {
68 if (conf.find(option_name) != conf.end()) {
69 return conf[option_name];
75 static int VARIABLE_IS_NOT_USED get_config_option_int(
const char *option_name,
int default_value) {
76 if (conf.find(option_name) != conf.end()) {
77 return atoi(conf[option_name].c_str());
83 static uint64_t
VARIABLE_IS_NOT_USED get_config_option_long(
const char *option_name, uint64_t default_value) {
84 if (conf.find(option_name) != conf.end()) {
85 return atol(conf[option_name].c_str());
90 static double VARIABLE_IS_NOT_USED get_config_option_double(
const char *option_name,
double default_value) {
91 if (conf.find(option_name) != conf.end()) {
92 return atof(conf[option_name].c_str());
98 static void set_argc(
int argc,
const char ** argv);
99 static void set_argc(
int argc,
const char ** argv) {
101 _argv = (
char**)argv;
102 _cmd_configured =
true;
103 conf = loadconfig(filename_config());
106 static void graphchi_init(
int argc,
const char ** argv);
107 static void graphchi_init(
int argc,
const char ** argv) {
108 set_argc(argc, argv);
111 static void check_cmd_init() {
112 if (!_cmd_configured) {
113 std::cout <<
"ERROR: command line options not initialized." << std::endl;
114 std::cout <<
" You need to call set_argc() in the beginning of the program." << std::endl;
119 std::string default_value)
124 for (i = _argc - 2; i >= 0; i -= 2)
125 if (strcmp(_argv[i], option_name) == 0)
126 return std::string(_argv[i + 1]);
127 return get_config_option_string(option_name, default_value);
135 for (i = _argc - 2; i >= 0; i -= 2)
136 if (strcmp(_argv[i], option_name) == 0)
137 return std::string(_argv[i + 1]);
139 std::cout <<
"Error: command line argument [" << std::string(option_name) <<
"] is required!" << std::endl;
143 static std::string
VARIABLE_IS_NOT_USED get_option_string_interactive(
const char *option_name, std::string options)
148 for (i = _argc - 2; i >= 0; i -= 2)
149 if (strcmp(_argv[i], option_name) == 0)
150 return std::string(_argv[i + 1]);
152 std::cout <<
"Please enter value for command-line argument [" << std::string(option_name) <<
"]"<< std::endl;
153 std::cout <<
" (Options are: " << options <<
")" << std::endl;
170 for (i = _argc - 2; i >= 0; i -= 2)
171 if (strcmp(_argv[i], option_name) == 0)
172 return atoi(_argv[i + 1]);
174 return get_config_option_int(option_name, default_value);
182 for (i = _argc - 2; i >= 0; i -= 2)
183 if (strcmp(_argv[i], option_name) == 0)
184 return atoi(_argv[i + 1]);
186 std::cout <<
"Error: command line argument [" << std::string(option_name) <<
"] is required!" << std::endl;
192 static uint64_t
VARIABLE_IS_NOT_USED get_option_long(
const char *option_name, uint64_t default_value)
197 for (i = _argc - 2; i >= 0; i -= 2)
198 if (strcmp(_argv[i], option_name) == 0)
199 return atol(_argv[i + 1]);
200 return get_config_option_long(option_name, default_value);
203 static float VARIABLE_IS_NOT_USED get_option_float(
const char *option_name,
float default_value)
208 for (i = _argc - 2; i >= 0; i -= 2)
209 if (strcmp(_argv[i], option_name) == 0)
210 return (
float)atof(_argv[i + 1]);
211 return (
float) get_config_option_double(option_name, default_value);