OpenWalnut  1.4.0
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 <string>
29 #include <vector>
30 
31 #include <boost/shared_ptr.hpp>
32 
33 #include "../kernel/WModuleContainer.h"
34 
35 #include "WScriptInterpreter.h"
36 
37 /**
38  * The script engine. Provides all script interpreters available for the OpenWalnut installation. Which
39  * interpreters are available depends on the libs available at OpenWalnut build time.
40  */
42 {
43 public:
44  /**
45  * Constructs a new script engine.
46  *
47  * \param rootContainer The root module container to use for modules inserted via scripts.
48  */
49  explicit WScriptEngine( boost::shared_ptr< WModuleContainer > const& rootContainer );
50 
51  /**
52  * Destructor.
53  */
54  virtual ~WScriptEngine();
55 
56  /**
57  * This finds an interpreter suitable for executing script files ending with the given extension.
58  *
59  * \param ext The extension of the script file to execute.
60  *
61  * \return The matching script interpreter or a NULL-pointer, if no such interpreter was available.
62  */
63  boost::shared_ptr< WScriptInterpreter > getInterpreterByFileExtension( std::string const& ext );
64 
65  /**
66  * This finds an interpreter by script language name.
67  *
68  * \param name The name of the script language.
69  *
70  * \return The matching script interpreter or a NULL-pointer, if no such interpreter was available.
71  */
72  boost::shared_ptr< WScriptInterpreter > getInterpreter( std::string const& name );
73 
74  /**
75  * Get the number of script interpreters available.
76  *
77  * \return The number of available script interpreters.
78  */
79  std::size_t getNumInterpreters() const;
80 
81  /**
82  * Get the i'th script interpreter.
83  *
84  * \param index The index of the script interpreter to retrieve, must be in [0,getNumInterpreters()-1].
85  *
86  * \return The script interpreter or a NULL-pointer if the index was invalid.
87  */
88  boost::shared_ptr< WScriptInterpreter > getInterpreter( std::size_t index );
89 
90 private:
91  //! The list of available script interpreters.
92  std::vector< boost::shared_ptr< WScriptInterpreter > > m_interpreters;
93 };
94 
95 #endif // WSCRIPTENGINE_H
boost::shared_ptr< WScriptInterpreter > getInterpreterByFileExtension(std::string const &ext)
This finds an interpreter suitable for executing script files ending with the given extension...
The script engine.
Definition: WScriptEngine.h:41
std::vector< boost::shared_ptr< WScriptInterpreter > > m_interpreters
The list of available script interpreters.
Definition: WScriptEngine.h:92
boost::shared_ptr< WScriptInterpreter > getInterpreter(std::string const &name)
This finds an interpreter by script language name.
std::size_t getNumInterpreters() const
Get the number of script interpreters available.
virtual ~WScriptEngine()
Destructor.
WScriptEngine(boost::shared_ptr< WModuleContainer > const &rootContainer)
Constructs a new script engine.