-
Notifications
You must be signed in to change notification settings - Fork 1
/
option.cpp
50 lines (42 loc) · 1.1 KB
/
option.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
#include <iostream>
#include <map>
#include <string>
#include <cstring>
#include "option.h"
#include <stdio.h>
#include <stdlib.h>
using namespace std;
Option::Option(int const argc, char const * const argv[])
{
for(int j=1; j<argc-1; j+=2){
if(argv[j][0] != '-')
cout << "Error: " << argv[j] << " must be an option\n";
else
m_option.insert(pair<string,string>(argv[j], argv[j+1]));
}
}
void Option::set_default(const char key[], const char value[])
{
if(m_option.find(key) == m_option.end())
m_option.insert(pair<string,string>(key, value));
}
void Option::set_default(const string key, const string value)
{
if(m_option.find(key) == m_option.end())
m_option.insert(pair<string,string>(key, value));
}
int Option::get_int(const char key[]) const
{
return atoi(m_option.find(key)->second.c_str());
}
float Option::get_float(const char key[]) const
{
return atof(m_option.find(key)->second.c_str());
}
void Option::print()
{
for(map<string,string>::iterator p=m_option.begin(); p != m_option.end();
++p){
cout << p->first << " " << p->second << endl;
}
}