OpenWalnut
1.4.0
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #include <string> 00026 00027 #include "python/WScriptInterpreterPython.h" 00028 00029 #include "WScriptEngine.h" 00030 00031 WScriptEngine::WScriptEngine( boost::shared_ptr<WModuleContainer> const& rootContainer ) 00032 { 00033 #ifdef PYTHON_FOUND // this is defined in the CMake scripts 00034 m_interpreters.push_back( boost::shared_ptr< WScriptInterpreter >( new WScriptInterpreterPython( rootContainer ) ) ); 00035 #else 00036 ( void ) rootContainer; // avoid compiler warning: unused parameter ‘rootContainer’ 00037 #endif 00038 for( std::size_t k = 0; k < m_interpreters.size(); ++k ) 00039 { 00040 m_interpreters[ k ]->initBindings(); 00041 } 00042 } 00043 00044 WScriptEngine::~WScriptEngine() 00045 { 00046 } 00047 00048 boost::shared_ptr< WScriptInterpreter > WScriptEngine::getInterpreterByFileExtension( std::string const& ext ) 00049 { 00050 for( std::size_t k = 0; k < m_interpreters.size(); ++k ) 00051 { 00052 if( ext == m_interpreters[ k ]->getExtension() ) 00053 { 00054 return m_interpreters[ k ]; 00055 } 00056 } 00057 return boost::shared_ptr< WScriptInterpreter >(); 00058 } 00059 00060 boost::shared_ptr< WScriptInterpreter > WScriptEngine::getInterpreter( std::string const& name ) 00061 { 00062 for( std::size_t k = 0; k < m_interpreters.size(); ++k ) 00063 { 00064 if( name == m_interpreters[ k ]->getName() ) 00065 { 00066 return m_interpreters[ k ]; 00067 } 00068 } 00069 return boost::shared_ptr< WScriptInterpreter >(); 00070 } 00071 00072 std::size_t WScriptEngine::getNumInterpreters() const 00073 { 00074 return m_interpreters.size(); 00075 } 00076 00077 boost::shared_ptr< WScriptInterpreter > WScriptEngine::getInterpreter( std::size_t index ) 00078 { 00079 if( index < m_interpreters.size() ) 00080 { 00081 return m_interpreters[ index ]; 00082 } 00083 return boost::shared_ptr< WScriptInterpreter >(); 00084 }