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