1
2// vim:sw=2:ai
3
4/*
5 * Copyright (C) 2010 DeNA Co.,Ltd.. All rights reserved.
6 * See COPYRIGHT.txt for details.
7 */
8
9#include <stdlib.h>
10#include <stdio.h>
11#include <string.h>
12
13#include "config.hpp"
14
15namespace dena {
16
17unsigned int verbose_level = 0;
18
19std::string
20config::get_str(const std::string& key, const std::string& def) const
21{
22 const_iterator iter = this->find(key);
23 if (iter == this->end()) {
24 DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%s(default)\n", key.c_str(),
25 def.c_str()));
26 return def;
27 }
28 DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%s\n", key.c_str(),
29 iter->second.c_str()));
30 return iter->second;
31}
32
33long long
34config::get_int(const std::string& key, long long def) const
35{
36 const_iterator iter = this->find(key);
37 if (iter == this->end()) {
38 DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%lld(default)\n", key.c_str(),
39 def));
40 return def;
41 }
42 const long long r = atoll(iter->second.c_str());
43 DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%lld\n", key.c_str(), r));
44 return r;
45}
46
47void
48parse_args(int argc, char **argv, config& conf)
49{
50 for (int i = 1; i < argc; ++i) {
51 const char *const arg = argv[i];
52 const char *const eq = strchr(arg, '=');
53 if (eq == 0) {
54 continue;
55 }
56 const std::string key(arg, eq - arg);
57 const std::string val(eq + 1);
58 conf[key] = val;
59 }
60 config::const_iterator iter = conf.find("verbose");
61 if (iter != conf.end()) {
62 verbose_level = atoi(iter->second.c_str());
63 }
64}
65
66};
67
68