Drizzled Public API Documentation

option_context.cc
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2010 Monty Taylor
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
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 } /* namespace */
00078 
00079 /*
00080  * Private methods.
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 } /* namespace module */
00096 } /* namespace drizzled */
00097