/* * Nomad Instrument Control Software * * Copyright 2011 Institut Laue-Langevin * * Licensed under the EUPL, Version 1.1 only (the "License"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * * http://joinup.ec.europa.eu/software/page/eupl * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. */ #ifndef PYTHONOBJECT_H #define PYTHONOBJECT_H #include #include #include "MplLock.h" #include namespace view { namespace mpl { /*! * \brief Lock system for managing thread safe operation on Python interpreter */ class PythonObject { public: /*! * \brief constructor, lock the GIL */ PythonObject() { } PythonObject(const boost::python::object& obj) : m_Object(std::move(obj)) { } PythonObject(const PythonObject& obj) { m_Object = obj(); } /*! * \brief destructor, release the GIL */ ~PythonObject() { reset(); } // const boost::python::object& get() const { // return m_Object; // } void reset() { m_Object = boost::python::object(); } const boost::python::object& operator() () const { return m_Object; } PythonObject& operator= (const PythonObject& obj) { m_Object = boost::python::object(); m_Object = obj(); return *this; } PythonObject& operator= (const boost::python::object& obj) { m_Object = boost::python::object(); m_Object = obj; return *this; } boost::python::object operator[](int32 index) const { return m_Object[index]; } boost::python::object operator[](const char* attr) const { return m_Object[attr]; } boost::python::object attr(const char* attrstr) const { return m_Object.attr(attrstr); } template void setattr(const char* attrstr, Type set) { m_Object.attr(attrstr) = set; } private: boost::python::object m_Object; //! State of interpreter to get back }; } } #endif // PYTHONOBJECT_H