aboutsummaryrefslogtreecommitdiff
path: root/src/CommandParser.hh
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2003-06-30 14:44:43 (GMT)
committerfluxgen <fluxgen>2003-06-30 14:44:43 (GMT)
commitbbe279233a210fe8ef23b0d265421b8f18d2b358 (patch)
tree7a9458ebb3cc7582c008cf43bbdb2ed1b502b1ac /src/CommandParser.hh
parent0dc31b93a8538aac2a538737df52a92bf8e8c21a (diff)
downloadfluxbox-bbe279233a210fe8ef23b0d265421b8f18d2b358.zip
fluxbox-bbe279233a210fe8ef23b0d265421b8f18d2b358.tar.bz2
new command parser
Diffstat (limited to 'src/CommandParser.hh')
-rw-r--r--src/CommandParser.hh77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/CommandParser.hh b/src/CommandParser.hh
new file mode 100644
index 0000000..1a58c35
--- /dev/null
+++ b/src/CommandParser.hh
@@ -0,0 +1,77 @@
1// CommandParser.hh for Fluxbox - an X11 Window manager
2// Copyright (c) 2003 Henrik Kinnunen (fluxgen{<a*t>}users.sourceforge.net)
3// and Simon Bowden (rathnor at users.sourceforge.net)
4//
5// Permission is hereby granted, free of charge, to any person obtaining a
6// copy of this software and associated documentation files (the "Software"),
7// to deal in the Software without restriction, including without limitation
8// the rights to use, copy, modify, merge, publish, distribute, sublicense,
9// and/or sell copies of the Software, and to permit persons to whom the
10// Software is furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21// DEALINGS IN THE SOFTWARE.
22
23// $Id: CommandParser.hh,v 1.1 2003/06/30 14:44:43 fluxgen Exp $
24
25#ifndef COMMANDPARSER_HH
26#define COMMANDPARSER_HH
27
28#include <string>
29#include <map>
30#include <ostream>
31
32#include "RefCount.hh"
33
34namespace FbTk {
35class Command;
36};
37
38/// Creates commands from command and argument.
39/// Used for modules to add new commands in compile/run time
40class CommandFactory {
41public:
42 CommandFactory();
43 virtual ~CommandFactory();
44 virtual FbTk::Command *stringToCommand(const std::string &command,
45 const std::string &arguments) = 0;
46protected:
47 void addCommand(const std::string &value);
48};
49
50/// Parses text into a command
51class CommandParser {
52public:
53 typedef std::map<std::string, CommandFactory *> CommandFactoryMap;
54
55 /// @return parses and returns a command matching the line
56 FbTk::Command *parseLine(const std::string &line);
57 /// lists all commands to an ostream
58 void showCommands(std::ostream &the_stream) const;
59 /// @return instance of command parser
60 static CommandParser &instance();
61private:
62 // so CommandFactory can associate it's commands
63 friend class CommandFactory;
64 /// associate a command with a factory
65 void associateCommand(const std::string &name, CommandFactory &factory);
66 /// remove all associations with the factory
67 void removeAssociation(CommandFactory &factory);
68
69 /// search for a command in our command factory map
70 FbTk::Command *toCommand(const std::string &command,
71 const std::string &arguments);
72
73 CommandFactoryMap m_commandfactorys; ///< a string to factory map
74
75};
76
77#endif // COMMANDPARSER_HH