Michele De Stefano's C++ Utilities
mds_utils::python::List Class Reference

Wraps a Python list. More...

#include <mds_utils/python/list.hpp>

Inheritance diagram for mds_utils::python::List:
mds_utils::python::Sequence_Base< List > mds_utils::python::Obj

Public Member Functions

 List ()
 The default constructor.
 
 List (PyObject *po)
 Constructs a new List from a Python sequence. More...
 
 List (const List &rhs)
 The copy constructor.
 
 List (List &&rhs)
 The move constructor.
 
 List (ProxyAttr &&rhs)
 The move constructor from ProxyAttr objects.
 
Listoperator= (List &&rhs)
 The move assignment.
 
Listoperator= (const List &rhs)
 The standard assignment.
 
template<class T >
Listappend (const T &val)
 Appends an element to the list. More...
 
template<class T >
Listappend (T &&val)
 Appends an element to the list using move semantics. More...
 
template<class T >
Listinsert (long i, const T &val)
 Inserts an element in front of the specified element. More...
 
template<class T >
Listinsert (long i, T &&val)
 Inserts an element in front of the specified element using move semantics. More...
 
Listsort ()
 Sorts the list.
 
Listreverse ()
 Reverses the list.
 
- Public Member Functions inherited from mds_utils::python::Sequence_Base< List >
 Sequence_Base ()
 Default constructor. More...
 
 Sequence_Base (size_t len)
 Creates a sequence of the desired length. More...
 
 Sequence_Base (PyObject *po)
 Constructs a new Sequence_Base from a Python sequence. More...
 
 Sequence_Base (Sequence_Base &&rhs)
 Move constructor.
 
 Sequence_Base (const Sequence_Base &rhs)
 The copy-constructor.
 
 Sequence_Base (ProxyAttr &&rhs)
 Move constructor from ProxyAttr object. More...
 
Sequence_Base< List > & operator= (Sequence_Base< List > &&rhs)
 Move assignment.
 
Sequence_Base< List > & operator= (const Sequence_Base< List > &rhs)
 The standard assignment.
 
void set (const seq_T &seq)
 Sets a Python sequence from a Boost Fusion sequence. More...
 
void set (FwIt b, FwIt e)
 Sets a Python sequence from a range of values. More...
 
void set (const Obj &o)
 Sets a Python sequence from another Python sequence. More...
 
void del (long i)
 Deletes the item in position i.
 
size_t len () const
 Returns the length of the sequence.
 
ProxyElem operator[] (long i)
 Element access. More...
 
- Public Member Functions inherited from mds_utils::python::Obj
 Obj ()
 Default constructor.
 
 Obj (const Obj &rhs)
 The copy-constructor. More...
 
 Obj (Obj &&rhs)
 Move constructor. More...
 
 Obj (ProxyAttr &&rhs)
 Move constructor from ProxyAttr objects. More...
 
 Obj (PyObject *po)
 Construct from a Python object. More...
 
Objoperator= (const Obj &rhs)
 Standard assignment.
 
Objoperator= (Obj &&rhs)
 Move assignment.
 
virtual Objoperator= (PyObject *po)
 Assignment from a Python object. More...
 
template<class T >
Objoperator= (const T &val)
 Assignment from a value. More...
 
virtual ~Obj ()
 Destructor.
 
PyObject * getPyObject () const
 Returns the underlying PyObject. More...
 
 operator PyObject * () const
 Automatic type conversion towards a Python object. More...
 
virtual PyObject * transfer ()
 Returns the Python object with transferred ownership. More...
 
virtual void incref ()
 Increments the reference count using Py_XINCREF. More...
 
virtual void decref ()
 Decrements the reference count using Py_XDECREF.
 
void reset ()
 Resets the object to the state given by the default constructor.
 
void get_ownership ()
 Used in place of incref, when the wrapped PyObject* was increfed already.
 
bool has_attr (const std::string &name) const
 Tests if the object has a particular attribute.
 
ProxyAttr attr (const std::string &name)
 Retrieves an attribute. More...
 
bool is_callable () const
 Checks if the object is callable. More...
 
Obj operator() ()
 Calling operator. More...
 
Obj operator() (const Obj &args)
 Calling operator, with positional arguments. More...
 
Obj operator() (const Obj &args, const Obj &kw)
 Calling operator, with positional and keyword arguments. More...
 

Friends

class Sequence_Base< List >
 

Additional Inherited Members

- Protected Member Functions inherited from mds_utils::python::Sequence_Base< List >
size_t idx (long i) const
 Converts a Python index (that can also be negative) into a C index. More...
 
- Protected Member Functions inherited from mds_utils::python::Obj
void check_callable ()
 Checks if the object is callable. More...
 
void check_call_result (PyObject *result)
 Checks if the result of the object call was successful. More...
 
- Protected Attributes inherited from mds_utils::python::Sequence_Base< List >
size_t m_len
 The length of the sequence.
 
- Protected Attributes inherited from mds_utils::python::Obj
size_t decref_on_destroy
 
PyObject * m_po
 Underlying pointer to the wrapped Python object.
 

Detailed Description

Wraps a Python list.

Warning
  • Be sure to have included proper overloads of the mds_utils::python::to_python function.
  • Remember that the copy/move constructors and the assignment operators do not duplicate the underlying Python object. They only increment its reference count.
Author
Michele De Stefano
Date
05/08/2014

Definition at line 47 of file list.hpp.

Constructor & Destructor Documentation

mds_utils::python::List::List ( PyObject *  po)
inline

Constructs a new List from a Python sequence.

It throws an exception if the parameter is not a sequence.

Parameters
poPointer to a Pyton sequence object.
Remarks
It does not incref the Python object.
Author
Michele De Stefano
Date
19/04/2014

Definition at line 91 of file list.hpp.

Member Function Documentation

template<class T >
List& mds_utils::python::List::append ( const T &  val)
inline

Appends an element to the list.

Parameters
valThe element to be appended.
Author
Michele De Stefano
Date
20/05/2014

Definition at line 127 of file list.hpp.

References mds_utils::python::Sequence_Base< List >::m_len, mds_utils::python::Obj::m_po, and mds_utils::python::to_python().

Referenced by mds_utils::python::support_random_access< Dummy_Container >::py_get_item().

template<class T >
List& mds_utils::python::List::append ( T &&  val)
inline

Appends an element to the list using move semantics.

Parameters
valThe element to be appended.
Author
Michele De Stefano
Date
27/07/2014

Definition at line 145 of file list.hpp.

References mds_utils::python::Sequence_Base< List >::m_len, mds_utils::python::Obj::m_po, and mds_utils::python::to_python().

template<class T >
List& mds_utils::python::List::insert ( long  i,
const T &  val 
)
inline

Inserts an element in front of the specified element.

Parameters
iThe index where the new element will be inserted in front of.
valThe element to be inserted.
Author
Michele De Stefano
Date
19/04/2014

Definition at line 165 of file list.hpp.

References mds_utils::python::Sequence_Base< List >::idx(), and mds_utils::python::to_python().

template<class T >
List& mds_utils::python::List::insert ( long  i,
T &&  val 
)
inline

Inserts an element in front of the specified element using move semantics.

Parameters
iThe index where the new element will be inserted in front of.
valThe element to be inserted.
Author
Michele De Stefano
Date
27/07/2014

Definition at line 184 of file list.hpp.

References mds_utils::python::Sequence_Base< List >::idx(), and mds_utils::python::to_python().


The documentation for this class was generated from the following file: