Interpreter.h
1 /*
2 
3 Copyright (c) 2018, Johnathan Corkery. (jcorkery@umich.edu)
4 All rights reserved.
5 
6 This file is part of the Dynacoe project (https://github.com/jcorks/Dynacoe)
7 Dynacoe was released under the MIT License, as detailed below.
8 
9 
10 
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is furnished
16 to do so, subject to the following conditions:
17 
18 The above copyright notice and this permission notice shall
19 be included in all copies or substantial portions of the Software.
20 
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 DEALINGS IN THE SOFTWARE.
28 
29 
30 
31 */
32 
33 #ifndef H_DC_INTERPRETER_INCLUDED
34 #define H_DC_INTERPRETER_INCLUDED
35 
36 #include <string>
37 #include <vector>
38 #include <map>
39 
40 namespace Dynacoe {
41 
42 
47 
48 class Interpreter {
49  public:
50 
53  class Command {
54  public:
59  virtual std::string operator()(const std::vector<std::string> & argvec)= 0;
60 
63  virtual std::string Help() const = 0;
64  };
65 
66 
67 
68 
69  Interpreter();
70 
71 
72 
73 
79  std::string RunCommand(const std::string &);
80 
81 
86  void AddCommand(const std::string & cmd, Command * consoleCommand);
87 
88 
89 
90  private:
91 
92  struct CommandResult {
94  std::vector<std::string> args;
95  };
96 
97  std::map<std::string, Command*> commands;
98  std::string ReduceEvaluators(const std::string &);
99  CommandResult RunCommandString(const std::string & in);
100 
101 
102 
103 
104 };
105 }
106 
107 
108 #endif
virtual std::string operator()(const std::vector< std::string > &argvec)=0
The callback for the command invocation.
The interpreter provides a means to execute dynamic runtime behavior through text. This is most conventionally useful via the Console.
Definition: Interpreter.h:48
Definition: AssetID.h:37
Functor that represents a run command.
Definition: Interpreter.h:53
virtual std::string Help() const =0
Function that contains text to be accessed when requesting documentation on the command.
std::string RunCommand(const std::string &)
Runs a console command.
void AddCommand(const std::string &cmd, Command *consoleCommand)
Sets a new console command.