~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/module/context.cc

  • Committer: Monty Taylor
  • Date: 2010-10-15 17:18:02 UTC
  • mto: (1859.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1860.
  • Revision ID: mordred@inaugust.com-20101015171802-qhk6zyfhrkvprr1n
Added support for registering regular sys_var instances via module::Context.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
20
#include "config.h"
 
21
#include "drizzled/module/context.h"
 
22
#include "drizzled/module/option_map.h"
 
23
#include "drizzled/module/module.h"
 
24
#include "drizzled/drizzled.h"
 
25
 
 
26
namespace drizzled
 
27
{
 
28
 
 
29
namespace module
 
30
{
 
31
 
 
32
module::option_map Context::getOptions()
 
33
{
 
34
  return module::option_map(module->getName(), getVariablesMap());
 
35
}
 
36
 
 
37
void Context::registerVariable(sys_var *var)
 
38
{
 
39
  var->setName(prepend_name(module->getName(), var->getName()));
 
40
  add_sys_var_to_list(var);
 
41
}
 
42
 
 
43
namespace
 
44
{
 
45
 
 
46
class SwapDashes
 
47
{
 
48
public:
 
49
  char operator()(char a) const
 
50
  {
 
51
    if (a == '-')
 
52
      return '_';
 
53
    return a;
 
54
  }
 
55
};
 
56
 
 
57
} /* namespace */
 
58
 
 
59
std::string Context::prepend_name(std::string module_name,
 
60
                                  const std::string &var_name)
 
61
{
 
62
  module_name.push_back('_');
 
63
  module_name.append(var_name);
 
64
  std::transform(module_name.begin(), module_name.end(),
 
65
                 module_name.begin(), SwapDashes());
 
66
  std::transform(module_name.begin(), module_name.end(),
 
67
                 module_name.begin(), ::tolower);
 
68
  return module_name;
 
69
}
 
70
 
 
71
 
 
72
} /* namespace module */
 
73
} /* namespace drizzled */