OpenWalnut  1.5.0dev
WScriptEngine.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut 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 the
18 // 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 OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WSCRIPTENGINE_H
26 #define WSCRIPTENGINE_H
27 
28 #include <memory>
29 #include <string>
30 #include <vector>
31 
32 
33 #include "../kernel/WModuleContainer.h"
34 #include "WScriptInterpreter.h"
35 
36 /**
37  * The script engine. Provides all script interpreters available for the OpenWalnut installation. Which
38  * interpreters are available depends on the libs available at OpenWalnut build time.
39  */
41 {
42 public:
43  /**
44  * Constructs a new script engine.
45  *
46  * \param rootContainer The root module container to use for modules inserted via scripts.
47  */
48  explicit WScriptEngine( std::shared_ptr< WModuleContainer > const& rootContainer );
49 
50  /**
51  * Destructor.
52  */
53  virtual ~WScriptEngine();
54 
55  /**
56  * This finds an interpreter suitable for executing script files ending with the given extension.
57  *
58  * \param ext The extension of the script file to execute.
59  *
60  * \return The matching script interpreter or a NULL-pointer, if no such interpreter was available.
61  */
62  std::shared_ptr< WScriptInterpreter > getInterpreterByFileExtension( std::string const& ext );
63 
64  /**
65  * This finds an interpreter by script language name.
66  *
67  * \param name The name of the script language.
68  *
69  * \return The matching script interpreter or a NULL-pointer, if no such interpreter was available.
70  */
71  std::shared_ptr< WScriptInterpreter > getInterpreter( std::string const& name );
72 
73  /**
74  * Get the number of script interpreters available.
75  *
76  * \return The number of available script interpreters.
77  */
78  std::size_t getNumInterpreters() const;
79 
80  /**
81  * Get the i'th script interpreter.
82  *
83  * \param index The index of the script interpreter to retrieve, must be in [0,getNumInterpreters()-1].
84  *
85  * \return The script interpreter or a NULL-pointer if the index was invalid.
86  */
87  std::shared_ptr< WScriptInterpreter > getInterpreter( std::size_t index );
88 
89 private:
90  //! The list of available script interpreters.
91  std::vector< std::shared_ptr< WScriptInterpreter > > m_interpreters;
92 };
93 
94 #endif // WSCRIPTENGINE_H
The script engine.
Definition: WScriptEngine.h:41
std::shared_ptr< WScriptInterpreter > getInterpreter(std::string const &name)
This finds an interpreter by script language name.
virtual ~WScriptEngine()
Destructor.
std::shared_ptr< WScriptInterpreter > getInterpreterByFileExtension(std::string const &ext)
This finds an interpreter suitable for executing script files ending with the given extension.
std::size_t getNumInterpreters() const
Get the number of script interpreters available.
std::vector< std::shared_ptr< WScriptInterpreter > > m_interpreters
The list of available script interpreters.
Definition: WScriptEngine.h:91
WScriptEngine(std::shared_ptr< WModuleContainer > const &rootContainer)
Constructs a new script engine.