OpenIG  2.0.4
cross-platform open-source OpenSceneGraph Image Generator
Commands.h
1 //#******************************************************************************
2 //#*
3 //#* Copyright (C) 2015 Compro Computer Services
4 //#* http://openig.compro.net
5 //#*
6 //#* Source available at: https://github.com/CCSI-CSSI/MuseOpenIG
7 //#*
8 //#* This software is released under the LGPL.
9 //#*
10 //#* This software is free software; you can redistribute it and/or modify
11 //#* it under the terms of the GNU Lesser General Public License as published
12 //#* by the Free Software Foundation; either version 2.1 of the License, or
13 //#* (at your option) any later version.
14 //#*
15 //#* This software is distributed in the hope that it will be useful,
16 //#* but WITHOUT ANY WARRANTY; without even the implied warranty of
17 //#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
18 //#* the GNU Lesser General Public License for more details.
19 //#*
20 //#* You should have received a copy of the GNU Lesser General Public License
21 //#* along with this library; if not, write to the Free Software
22 //#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 //#*
24 //#* Please direct any questions or comments to the OpenIG Forums
25 //#* Email address: openig@compro.net
26 //#*
27 //#*
28 //#* Please direct any questions or comments to the OpenIG Forums
29 //#* Email address: openig@compro.net
30 //#*
31 //#*
32 //#*****************************************************************************
33 
34 #ifndef COMMANDS_H
35 #define COMMANDS_H
36 
37 #if defined(OPENIG_SDK)
38  #include <OpenIG-Base/StringUtils.h>
39  #include <OpenIG-Base/Export.h>
40 #else
41  #include <Core-Base/StringUtils.h>
42  #include <Core-Base/Export.h>
43 #endif
44 
45 #include <map>
46 #include <string>
47 
48 #include <osg/ref_ptr>
49 #include <osg/Referenced>
50 
51 namespace OpenIG {
52  namespace Base {
53 
60  class IGCORE_EXPORT Commands
61  {
62  protected:
69  Commands();
70 
77  ~Commands();
78 
79  public:
86  class Command : public osg::Referenced
87  {
88  public:
97  virtual int exec(const StringUtils::Tokens& tokens) = 0;
98 
106  virtual const std::string getUsage() const = 0;
107 
115  virtual const std::string getDescription() const = 0;
116 
135  virtual const std::string getArgumentsFormat() const = 0;
136  };
137 
144  struct CommandExecCallback : public osg::Referenced
145  {
146  virtual void operator()(const std::string& command) = 0;
147  };
148 
155  void setCommandExecCallback(CommandExecCallback* callback);
156 
164  static Commands* instance();
165 
174  int exec(const std::string& command);
175 
184  void addCommand(const std::string& command, Command* cmd);
185 
193  void loadScript(const std::string& fileName);
194 
201  void clear();
202 
203  typedef osg::ref_ptr<Command> CommandPtr;
204  typedef std::map<std::string, osg::ref_ptr<Command> > CommandsMap;
205  typedef std::map<std::string, osg::ref_ptr<Command> >::iterator CommandsMapIterator;
206  typedef std::map<std::string, osg::ref_ptr<Command> >::const_iterator CommandsMapConstIterator;
207 
215  const CommandsMap& getCommands() const
216  {
217  return _commands;
218  }
219 
227  void removeCommand(const std::string& command);
228 
229  protected:
231  CommandsMap _commands;
232 
234  osg::ref_ptr<CommandExecCallback> _commandExecCallback;
235 
236  };
237  } // namespace
238 } // namespace
239 
240 #endif // COMMANDS_H
Definition: ImageGenerator.h:62
The Commands singleton class.
Definition: Commands.h:60
osg::ref_ptr< CommandExecCallback > _commandExecCallback
The command exec callback, executed when a command is executed.
Definition: Commands.h:234
const CommandsMap & getCommands() const
Gives the current commands.
Definition: Commands.h:215
The Command class.
Definition: Commands.h:86
Callback when command is executed.
Definition: Commands.h:144
CommandsMap _commands
name based std::map of commands added
Definition: Commands.h:231