~ubuntu-branches/ubuntu/precise/fluxbox/precise

« back to all changes in this revision

Viewing changes to src/CommandParser.hh

  • Committer: Bazaar Package Importer
  • Author(s): Dmitry E. Oboukhov
  • Date: 2008-07-01 10:38:14 UTC
  • mfrom: (2.1.12 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080701103814-khx2b6il152x9p93
Tags: 1.0.0+deb1-8
* x-dev has been removed from build-depends (out-of-date package).
* Standards-Version bumped to 3.8.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// CommandParser.hh for Fluxbox - an X11 Window manager
2
 
// Copyright (c) 2003 - 2005 Henrik Kinnunen (fluxgen at fluxbox dot org)
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 3865 2005-01-24 18:34:57Z mathias $
24
 
 
25
 
#ifndef COMMANDPARSER_HH
26
 
#define COMMANDPARSER_HH
27
 
 
28
 
#include <string>
29
 
#include <map>
30
 
 
31
 
#include "RefCount.hh"
32
 
 
33
 
namespace FbTk {
34
 
class Command;
35
 
};
36
 
 
37
 
/// Creates commands from command and argument.
38
 
/// Used for modules to add new commands in compile/run time
39
 
class CommandFactory {
40
 
public:
41
 
    CommandFactory();
42
 
    virtual ~CommandFactory();
43
 
    virtual FbTk::Command *stringToCommand(const std::string &command, 
44
 
                                           const std::string &arguments) = 0;
45
 
protected:
46
 
    void addCommand(const std::string &value);
47
 
};
48
 
 
49
 
/// Parses text into a command
50
 
class CommandParser {
51
 
public:
52
 
    typedef std::map<std::string, CommandFactory *> CommandFactoryMap;
53
 
 
54
 
    /// @return parses and returns a command matching the line
55
 
    FbTk::Command *parseLine(const std::string &line);
56
 
 
57
 
    /// @return instance of command parser
58
 
    static CommandParser &instance();
59
 
    /// @return map of factorys
60
 
    const CommandFactoryMap &factorys() const { return m_commandfactorys; }
61
 
private:
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