aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/CommandRegistry.cc
diff options
context:
space:
mode:
authorMark Tiefenbruck <mark@fluxbox.org>2007-12-16 03:36:01 (GMT)
committerMark Tiefenbruck <mark@fluxbox.org>2007-12-16 03:36:01 (GMT)
commit8516f1e2a21a374127ccfa3f7b8de2443e67fe33 (patch)
treea66f212f856981584b2b44bfc772096c5ee7bebe /src/FbTk/CommandRegistry.cc
parent90f4f1ecc1635fd5d144f86d64b1674958d0a59f (diff)
downloadfluxbox-8516f1e2a21a374127ccfa3f7b8de2443e67fe33.zip
fluxbox-8516f1e2a21a374127ccfa3f7b8de2443e67fe33.tar.bz2
changed CommandRegistry to a template class, renamed to ObjectRegistry<Type>
Diffstat (limited to 'src/FbTk/CommandRegistry.cc')
-rw-r--r--src/FbTk/CommandRegistry.cc96
1 files changed, 0 insertions, 96 deletions
diff --git a/src/FbTk/CommandRegistry.cc b/src/FbTk/CommandRegistry.cc
deleted file mode 100644
index fc40920..0000000
--- a/src/FbTk/CommandRegistry.cc
+++ /dev/null
@@ -1,96 +0,0 @@
1// CommandRegistry.cc for FbTk
2// Copyright (c) 2007 Fluxbox Team (fluxgen at fluxbox dot org)
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22// $Id: $
23
24#include "CommandRegistry.hh"
25#include "Command.hh"
26#include "StringUtil.hh"
27
28#include <iostream>
29
30namespace FbTk {
31
32CommandRegistry &CommandRegistry::instance() {
33 static CommandRegistry s_instance;
34 return s_instance;
35}
36
37
38bool CommandRegistry::registerCommand(string name,
39 CreateFunction createFunction) {
40 name = StringUtil::toLower(name);
41 m_commandCreators[name] = createFunction;
42 return true;
43}
44
45bool CommandRegistry::registerBoolCommand(string name,
46 BoolCreateFunction createFunction) {
47 name = StringUtil::toLower(name);
48 m_boolcommandCreators[name] = createFunction;
49 return true;
50}
51
52Command *CommandRegistry::parseLine(const string &line, bool trusted) const {
53 // parse args and command
54 string command, args;
55 StringUtil::getFirstWord(line, command, args);
56 StringUtil::removeFirstWhitespace(args);
57 StringUtil::removeTrailingWhitespace(args);
58
59 // now we have parsed command and args
60 command = StringUtil::toLower(command);
61 return getCommand(command, args, trusted);
62}
63
64BoolCommand *CommandRegistry::parseBoolLine(const string &line, bool trusted) const {
65 // parse args and command
66 string command, args;
67 StringUtil::getFirstWord(line, command, args);
68 StringUtil::removeFirstWhitespace(args);
69 StringUtil::removeTrailingWhitespace(args);
70
71 // now we have parsed command and args
72 command = StringUtil::toLower(command);
73 return getBoolCommand(command, args, trusted);
74}
75
76Command *CommandRegistry::getCommand(const string &name, const string &args,
77 bool trusted) const {
78 string lc = StringUtil::toLower(name);
79 CreatorMap::const_iterator it = m_commandCreators.find(lc.c_str());
80 if (it == m_commandCreators.end())
81 return 0;
82 else
83 return it->second(name, args, trusted);
84}
85
86BoolCommand *CommandRegistry::getBoolCommand(const string &name,
87 const string &args, bool trusted) const {
88 string lc = StringUtil::toLower(name);
89 BoolCreatorMap::const_iterator it = m_boolcommandCreators.find(lc.c_str());
90 if (it == m_boolcommandCreators.end())
91 return 0;
92 else
93 return it->second(name, args, trusted);
94}
95
96}; // end namespace FbTk