~drizzle-trunk/drizzle/development

1626.2.1 by Monty Taylor
Added wrapper around variables_map to allow us to pull values back out of
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"
1635.1.1 by Monty Taylor
Moved actual parsing of plugin program_options to drizzled.cc so that we do
24
#include "drizzled/drizzled.h"
1878.3.1 by Monty Taylor
Split set_var.* into sys_var.* and set_var.*
25
#include "drizzled/sys_var.h"
1626.2.1 by Monty Taylor
Added wrapper around variables_map to allow us to pull values back out of
26
27
namespace drizzled
28
{
1635.1.1 by Monty Taylor
Moved actual parsing of plugin program_options to drizzled.cc so that we do
29
1626.2.1 by Monty Taylor
Added wrapper around variables_map to allow us to pull values back out of
30
namespace module
31
{
32
33
module::option_map Context::getOptions()
34
{
1635.1.1 by Monty Taylor
Moved actual parsing of plugin program_options to drizzled.cc so that we do
35
  return module::option_map(module->getName(), getVariablesMap());
1626.2.1 by Monty Taylor
Added wrapper around variables_map to allow us to pull values back out of
36
}
37
1857.3.1 by Monty Taylor
Added support for registering regular sys_var instances via module::Context.
38
void Context::registerVariable(sys_var *var)
39
{
40
  var->setName(prepend_name(module->getName(), var->getName()));
1857.3.4 by Monty Taylor
Track lifecycle of sys_var different form plugin_sysvar
41
  module->addMySysVar(var);
1857.3.1 by Monty Taylor
Added support for registering regular sys_var instances via module::Context.
42
  add_sys_var_to_list(var);
43
}
44
45
namespace
46
{
47
48
class SwapDashes
49
{
50
public:
51
  char operator()(char a) const
52
  {
53
    if (a == '-')
54
      return '_';
55
    return a;
56
  }
57
};
58
59
} /* namespace */
60
61
std::string Context::prepend_name(std::string module_name,
62
                                  const std::string &var_name)
63
{
64
  module_name.push_back('_');
65
  module_name.append(var_name);
66
  std::transform(module_name.begin(), module_name.end(),
67
                 module_name.begin(), SwapDashes());
68
  std::transform(module_name.begin(), module_name.end(),
69
                 module_name.begin(), ::tolower);
70
  return module_name;
71
}
72
73
1626.2.1 by Monty Taylor
Added wrapper around variables_map to allow us to pull values back out of
74
} /* namespace module */
75
} /* namespace drizzled */