~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/module/option_context.cc

  • Committer: Mark Atwood
  • Date: 2011-07-13 22:28:29 UTC
  • mfrom: (2318.7.25 refactor1)
  • Revision ID: me@mark.atwood.name-20110713222829-sswp061b5ts7tc1k
mergeĀ lp:~olafvdspek/drizzle/refactor1

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 */
19
19
 
20
20
#include <config.h>
21
 
 
 
21
#include <boost/algorithm/string.hpp>
22
22
#include "option_context.h"
23
23
 
24
 
namespace drizzled
25
 
{
26
 
namespace module
27
 
{
28
 
 
29
 
 
 
24
namespace drizzled {
 
25
namespace module {
 
26
  
30
27
option_context::option_context(const std::string &module_name_in,
31
28
                               po::options_description_easy_init po_options_in) :
32
29
  module_name(module_name_in),
33
30
  po_options(po_options_in)
34
31
{ }
35
32
 
36
 
option_context& option_context::operator()(const char* name,
37
 
                                           const char* description)
38
 
{
39
 
  const std::string new_name(prepend_name(module_name, name));
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
 
{
48
 
  const std::string new_name(prepend_name(module_name, name));
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
 
{
58
 
  const std::string new_name(prepend_name(module_name, name));
59
 
  po_options(new_name.c_str(), s, description);
60
 
  return *this;
61
 
}
62
 
 
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
 
 */
82
 
std::string option_context::prepend_name(std::string in_module_name,
83
 
                                         const char *name_in)
 
33
option_context& option_context::operator()(const char* name, const char* description)
 
34
{
 
35
  po_options(prepend_name(module_name, name).c_str(), description);
 
36
  return *this;
 
37
}
 
38
 
 
39
option_context& option_context::operator()(const char* name, const po::value_semantic* s)
 
40
{
 
41
  po_options(prepend_name(module_name, name).c_str(), s);
 
42
  return *this;
 
43
}
 
44
 
 
45
option_context& option_context::operator()(const char* name, const po::value_semantic* s, const char* description)
 
46
{
 
47
  po_options(prepend_name(module_name, name).c_str(), s, description);
 
48
  return *this;
 
49
}
 
50
 
 
51
std::string option_context::prepend_name(std::string in_module_name, const char *name_in)
84
52
{
85
53
  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);
 
54
  std::replace(in_module_name.begin(), in_module_name.end(), '_', '-');
 
55
  boost::to_lower(in_module_name);
90
56
  in_module_name.append(name_in);
91
57
  return in_module_name;
92
58
}
93
59
 
94
 
 
95
60
} /* namespace module */
96
61
} /* namespace drizzled */
97
62