00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <config.h>
00021
00022 #include "option_context.h"
00023
00024 namespace drizzled
00025 {
00026 namespace module
00027 {
00028
00029
00030 option_context::option_context(const std::string &module_name_in,
00031 po::options_description_easy_init po_options_in) :
00032 module_name(module_name_in),
00033 po_options(po_options_in)
00034 { }
00035
00036 option_context& option_context::operator()(const char* name,
00037 const char* description)
00038 {
00039 const std::string new_name(prepend_name(module_name, name));
00040 po_options(new_name.c_str(), description);
00041 return *this;
00042 }
00043
00044
00045 option_context& option_context::operator()(const char* name,
00046 const po::value_semantic* s)
00047 {
00048 const std::string new_name(prepend_name(module_name, name));
00049 po_options(new_name.c_str(), s);
00050 return *this;
00051 }
00052
00053
00054 option_context& option_context::operator()(const char* name,
00055 const po::value_semantic* s,
00056 const char* description)
00057 {
00058 const std::string new_name(prepend_name(module_name, name));
00059 po_options(new_name.c_str(), s, description);
00060 return *this;
00061 }
00062
00063 namespace
00064 {
00065
00066 class SwapUnderscores
00067 {
00068 public:
00069 char operator()(char a) const
00070 {
00071 if (a == '_')
00072 return '-';
00073 return a;
00074 }
00075 };
00076
00077 }
00078
00079
00080
00081
00082 std::string option_context::prepend_name(std::string in_module_name,
00083 const char *name_in)
00084 {
00085 in_module_name.push_back('.');
00086 std::transform(in_module_name.begin(), in_module_name.end(),
00087 in_module_name.begin(), SwapUnderscores());
00088 std::transform(in_module_name.begin(), in_module_name.end(),
00089 in_module_name.begin(), ::tolower);
00090 in_module_name.append(name_in);
00091 return in_module_name;
00092 }
00093
00094
00095 }
00096 }
00097