1625.1.2
by Monty Taylor
Added option_context class, along with unittests, for adding a module |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright (C) 2010 Monty Taylor
|
|
5 |
*
|
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
8 |
* the Free Software Foundation; version 2 of the License.
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
18 |
*/
|
|
19 |
||
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
20 |
#include <config.h> |
1625.1.2
by Monty Taylor
Added option_context class, along with unittests, for adding a module |
21 |
|
22 |
#include "option_context.h" |
|
23 |
||
24 |
namespace drizzled |
|
25 |
{
|
|
26 |
namespace module |
|
27 |
{
|
|
28 |
||
29 |
||
30 |
option_context::option_context(const std::string &module_name_in, |
|
31 |
po::options_description_easy_init po_options_in) : |
|
32 |
module_name(module_name_in), |
|
33 |
po_options(po_options_in) |
|
34 |
{ } |
|
35 |
||
36 |
option_context& option_context::operator()(const char* name, |
|
37 |
const char* description) |
|
38 |
{
|
|
1633.6.2
by Vijay Samuel
Reverted changes. |
39 |
const std::string new_name(prepend_name(module_name, name)); |
1625.1.2
by Monty Taylor
Added option_context class, along with unittests, for adding a module |
40 |
po_options(new_name.c_str(), description); |
41 |
return *this; |
|
42 |
}
|
|
43 |
||
44 |
||
45 |
option_context& option_context::operator()(const char* name, |
|
46 |
const po::value_semantic* s) |
|
47 |
{
|
|
1633.6.2
by Vijay Samuel
Reverted changes. |
48 |
const std::string new_name(prepend_name(module_name, name)); |
1625.1.2
by Monty Taylor
Added option_context class, along with unittests, for adding a module |
49 |
po_options(new_name.c_str(), s); |
50 |
return *this; |
|
51 |
}
|
|
52 |
||
53 |
||
54 |
option_context& option_context::operator()(const char* name, |
|
55 |
const po::value_semantic* s, |
|
56 |
const char* description) |
|
57 |
{
|
|
1633.6.2
by Vijay Samuel
Reverted changes. |
58 |
const std::string new_name(prepend_name(module_name, name)); |
1625.1.2
by Monty Taylor
Added option_context class, along with unittests, for adding a module |
59 |
po_options(new_name.c_str(), s, description); |
60 |
return *this; |
|
61 |
}
|
|
62 |
||
1633.6.2
by Vijay Samuel
Reverted changes. |
63 |
namespace
|
64 |
{
|
|
65 |
||
66 |
class SwapUnderscores |
|
67 |
{
|
|
68 |
public: |
|
69 |
char operator()(char a) const |
|
70 |
{
|
|
71 |
if (a == '_') |
|
72 |
return '-'; |
|
73 |
return a; |
|
74 |
}
|
|
75 |
};
|
|
76 |
||
77 |
} /* namespace */ |
|
78 |
||
79 |
/*
|
|
80 |
* Private methods.
|
|
81 |
*/
|
|
1891.2.1
by Monty Taylor
Fixed things to make things compile with clang |
82 |
std::string option_context::prepend_name(std::string in_module_name, |
1633.6.2
by Vijay Samuel
Reverted changes. |
83 |
const char *name_in) |
84 |
{
|
|
1891.2.1
by Monty Taylor
Fixed things to make things compile with clang |
85 |
in_module_name.push_back('.'); |
86 |
std::transform(in_module_name.begin(), in_module_name.end(), |
|
87 |
in_module_name.begin(), SwapUnderscores()); |
|
88 |
std::transform(in_module_name.begin(), in_module_name.end(), |
|
89 |
in_module_name.begin(), ::tolower); |
|
90 |
in_module_name.append(name_in); |
|
91 |
return in_module_name; |
|
1633.6.2
by Vijay Samuel
Reverted changes. |
92 |
}
|
93 |
||
1625.1.2
by Monty Taylor
Added option_context class, along with unittests, for adding a module |
94 |
|
95 |
} /* namespace module */ |
|
96 |
} /* namespace drizzled */ |
|
97 |