17#ifndef PyOpal_PyLine_h
77 void append(boost::python::object element);
102 boost::python::class_<PyLine>
make_class(
const char* className);
108 std::vector<boost::python::object>
line;
115 std::shared_ptr<TBeamline<FlaggedElmPtr>> objectPtr = getOpalShared();
116 return objectPtr->getName();
121 std::shared_ptr<TBeamline<FlaggedElmPtr>> objectPtr = getOpalShared();
122 objectPtr->setName(
name);
130 index = line.size()+index;
144 if (objectPtr ==
nullptr) {
145 throw OpalException(
"PyLine_<TBeamline<FlaggedElmPtr> >::register",
146 "Trying to register something that was not a Opal Object");
153 boost::python::docstring_options docop(
true,
true,
false);
154 auto pyclass = boost::python::class_<PyLine>(className);
163 }
catch (std::exception& exc) {
174 line.at(i) = pyelement;
175 }
catch (std::exception& exc) {
176 throw OpalException(
"PyLine::setElement",
"Failed to set element");
178 boost::python::object pyopalelement = pyelement.attr(
"get_opal_element")();
180 boost::python::extract<PyOpal::PyOpalObjectNS::PyOpalObject<OpalElement>& >(pyopalelement);
182 for (
BL::iterator it = object_m->begin(); it != object_m->end(); ++it) {
185 std::shared_ptr<OpalElement> opalElementShared = cpyelement.
getOpalShared();
186 OpalElement* opalElement = opalElementShared.get();
188 throw OpalException(
"PyLine::setElement",
"Failed to extract element");
193 throw OpalException(
"PyLine::setElement",
"Failed to cast element");
198 object_m->insert(new_it, felmptr);
210 line.push_back(boost::python::object());
212 object_m->push_back(felmptr);
214 setElement(i, pyelement);
std::string::iterator iterator
PyLine_< TBeamline< FlaggedElmPtr > > PyLine
ElementBase * getElement() const
Return the embedded CLASSIC element.
void setElement(ElementBase *)
Assign new CLASSIC element.
The base class for all OPAL objects.
static OpalData * getInstance()
void define(Object *newObject)
Define a new object.
virtual const std::string & getName() const
Get element name.
A section of a beam line.
A section of a beam line.
virtual void update()
Update the embedded CLASSIC element.
virtual Line * clone(const std::string &name)
Make clone.
PyOpalObject<C> is the basic wrapper class for Opal Objects.
std::shared_ptr< C > getOpalShared()
Returns the Opal Object from the PyOpalObject.
PyLine_ is a list of elements in a beamline.
int getLength() const
Returns the number of elements in the line.
void setName(std::string name)
Set the name of the underlying object.
std::vector< boost::python::object > line
The python objects stored in the line.
int wrangleIndex(int index)
Handle negative indices in pythonic way.
void append(boost::python::object element)
Extend the length of the vector and TBeamline.
void setElement(int i, boost::python::object element)
Set a python object in the line vector and update the TBeamline.
std::string getName() const
Set the name of the underlying object.
boost::python::class_< PyLine > make_class(const char *className)
Make a python::class_ object for a PyLine.
boost::python::object getElement(int i)
Get a python object from the vector of stored objects.
The base class for all OPAL exceptions.