Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Instrument Control
Ploty2
Commits
28f310f1
Commit
28f310f1
authored
Nov 26, 2019
by
Locatelli
Browse files
Commit custom Python Object
parent
94da3c44
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/view/mpl/PythonObject.h
0 → 100644
View file @
28f310f1
/*
* 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 <common/base/BaseTypes.h>
#include <boost/python.hpp>
#include "MplLock.h"
#include <utility>
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
<
typename
Type
>
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment