39 for(
int i=0;i<size;i++){
42 std::vector<std::string> tags;
43 size_t found=opt_tag.find_first_of(
":");
44 if (found==std::string::npos){
45 tags.push_back(opt_tag);
48 while (found!=std::string::npos){
49 tags.push_back(opt_tag.substr(0,found));
50 opt_tag.erase(0,found+1);
51 found=opt_tag.find_first_of(
":");
52 if (found==std::string::npos){
53 tags.push_back(opt_tag);
59 int allowable_defined=0;
61 if (param[i].allowable[j]!=
""){
72 std::cerr <<
"OUT OF MEMORY\nFile" << __FILE__ <<
"Line:\t"<< __LINE__ << std::endl;
80 if (allowable_defined>0){
82 for(
int k=0;k<allowable_defined;k++){
92 if (param[i].preset.compare(
"")!=0){
96 std::istringstream input(param[i].preset);
97 if(!(input>>tempValue)){
98 std::cerr <<
"Couldn't convert preset to numerical integer: " << param[i].
preset << std::endl;
102 tp->
data.
i=tempValue;
110 std::istringstream input(param[i].preset);
111 if(!(input >> tempValue)){
112 std::cerr <<
"Couldn't convert preset to numerical double: " << param[i].
preset << std::endl;
116 tp->
data.
d=tempValue;
128 for(
size_t k=0;k<param[i].
preset.size();k++){
129 if (k>=MAX_ALLOWABLE){
130 std::cerr <<
"More presets than allowed OPT_FLAG" <<std::endl;
133 char c=param[i].
preset[k];
146 for(
size_t j=0; j<tags.size();j++){
163 for(
int i=1;i<argc;i++){
164 std::string tag=argv[i];
166 std::cout <<
"Unpaired/Unknown commandline argument:\t" << tag <<std::endl;
167 std::cout <<
usage << std::endl;
170 else if (
opts.count(tag)){
171 std::string secondary;
173 switch (
opts[tag]->type) {
178 if (!
opts[tag]->default_value){
179 std::cerr <<
"Command:\t" << tag <<
" is missing a secondary command line argument\n";
180 std::cout <<
usage << std::endl;
184 else if (argv[i+1][0]==
'-'){
185 if (!
opts[tag]->default_value){
186 std::cerr <<
"Command:\t" << tag <<
" is missing a secondary command line argument\n";
191 opts[tag]->data.i=atoi(argv[++i]);
196 if (!
opts[tag]->default_value){
197 std::cerr <<
"Command:\t" << tag <<
" is missing a argument\n";
198 std::cout <<
usage << std::endl;
202 else if (argv[i+1][0]==
'-'){
203 if (!
opts[tag]->default_value){
204 std::cerr <<
"Command:\t" << tag <<
" is missing a secondary command line argument\n";
208 opts[tag]->data.d=atof(argv[++i]);
221 if (secondary[0]==
'-'){
222 if (!
opts[tag]->default_value){
228 if (
opts[tag]->restricted){
229 if (
opts[tag]->flags.count(secondary)){
230 opts[tag]->str=secondary;
233 std::cerr <<
"Secondary option for:\t" << tag <<
" ->" << secondary <<
" is not allowed.\n";
234 std::cout <<
usage << std::endl;
239 if (secondary.compare(
"")==0){
240 if (!
opts[tag]->default_value){
241 opts[tag]->str=secondary;
245 opts[tag]->str=secondary;
252 std::cerr <<
"Command:\t" << tag <<
" is missing a secondary command line argument\n";
253 std::cout <<
usage << std::endl;
258 if (
opts[tag]->flags.count(secondary)){
259 opts[tag]->flags[secondary]=
true;
262 std::cerr <<
"Secondary option for:\t" << tag <<
" ->" << secondary <<
" is not allowed.\n";
263 std::cout <<
usage << std::endl;
275 std::map<std::string,bool> RequiredNotSet;
276 std::map<std::string,opt_data*>::iterator it;
278 for(it=
opts.begin();it!=
opts.end();it++){
279 if ((*it).second->required && !(*it).second->set){
286 std::map<std::string,bool>::iterator it;
287 for(it=RequiredNotSet.begin();it!=RequiredNotSet.end();it++){
288 std::cout <<
"Required option:\t" << (*it).first <<
" not set on command-line\n";
290 std::cout <<
usage <<std::endl;
304 if (
opts.count(param)){
306 value=
opts[param]->data.i;
310 std::cerr <<
"Option: " << param <<
" not set or not of type OPT_INT\n";
315 std::cerr <<
"Option: " << param <<
" type doesn't exist\n";
327 if (
opts.count(param)){
329 value=
opts[param]->data.d;
333 std::cerr <<
"Option: " << param <<
" not set or not of type OPT_DOUBLE\n";
338 std::cerr <<
"Option: " << param <<
" type doesn't exist\n";
350 if (
opts.count(param)){
352 value=
opts[param]->str;
356 std::cerr <<
"Option: " << param <<
" not set or not of type OPT_STRING\n";
361 std::cerr <<
"Option: " << param <<
" type doesn't exist\n";
373 std::string secondary=sec;
374 if (
opts.count(param)){
376 if (
opts[param]->flags.count(secondary)){
377 return opts[param]->flags[secondary];
380 std::cerr <<
"Secondary command: " << secondary <<
" doesn't exist.\n";
390 std::cerr <<
"Option: " << param <<
" type doesn't exist\n";
403 if (
opts.count(param)){
404 return opts[param]->set;
407 std::cerr <<
"Option: " << param <<
" type doesn't exist\n";
417 if (
opts.count(param)){
419 return opts[param]->str;
422 std::cerr <<
"Option: " << param <<
" not set or not of type OPT_STRING\n";
427 std::cerr <<
"Option: " << param <<
" type doesn't exist\n";
438 if (
opts.count(param)){
440 return opts[param]->data.i;
443 std::cerr <<
"Option: " << param <<
" not set or not of type OPT_INT\n";
448 std::cerr <<
"Option: " << param <<
" type doesn't exist\n";
458 if (
opts.count(param)){
460 return opts[param]->data.d;
463 std::cerr <<
"Option: " << param <<
" not set or not of type OPT_DOUBLE\n";
468 std::cerr <<
"Option: " << param <<
" type doesn't exist\n";