Michele De Stefano's C++ Utilities
tuple.hpp
Go to the documentation of this file.
1 // tuple.hpp
2 //
3 // Copyright (c) 2014 - Michele De Stefano (micdestefano@users.sourceforge.net)
4 //
5 // Distributed under the MIT License (See accompanying file LICENSE)
6 
7 #ifndef MDS_UTILS_PYTHON_TUPLE_HPP_INCLUDED
8 #define MDS_UTILS_PYTHON_TUPLE_HPP_INCLUDED
9 
11 
31 namespace mds_utils {
32  namespace python {
33 
49 class Tuple : public Sequence_Base<Tuple> {
50 
51  static PyObject* new_seq(size_t len) {
52  return PyTuple_New(len);
53  }
54 
55  static bool self_type_check(const Obj& o) {
56  return PyTuple_Check(o);
57  }
58 
59  template<class T>
60  bool set_item(size_t pos,T const& x) {
61  return PyTuple_SetItem(m_po,pos,to_python(x)) == 0;
62  }
63 
64  friend class Sequence_Base<Tuple>;
65 
66 
67 public:
68 
70  Tuple() {}
71 
84  Tuple(size_t len) : Sequence_Base<Tuple>(len) {}
85 
86 
99  Tuple(PyObject *po) : Sequence_Base<Tuple>(po) {}
100 
101 
103  Tuple(const Tuple& rhs) : Sequence_Base<Tuple>(rhs) {}
104 
105 
107  Tuple(Tuple&& rhs) : Sequence_Base<Tuple>(std::move(rhs)) {}
108 
110  Tuple(ProxyAttr&& rhs) : Sequence_Base<Tuple>(std::move(rhs)) {}
111 
113  Tuple& operator =(Tuple&& rhs) {
114  Sequence_Base<Tuple>::operator =(std::move(rhs));
115  return *this;
116  }
117 
119  Tuple& operator =(const Tuple& rhs) {
121  return *this;
122  }
123 };
124 
125  }
126 }
127 #endif
Proxy class for managing attribute access.
Definition: obj.hpp:93
Tuple(Tuple &&rhs)
The move constructor.
Definition: tuple.hpp:107
Tuple(const Tuple &rhs)
The copy constructor.
Definition: tuple.hpp:103
PyObject * to_python(void)
Converts a value into a Python object.
Main namespace of all Michele De Stefano&#39;s C++ utilities.
Definition: endian.hpp:30
Contains a wrapper class for a generic Python sequence datatype.
PyObject * m_po
Underlying pointer to the wrapped Python object.
Definition: obj.hpp:165
size_t len() const
Returns the length of the sequence.
Definition: sequence.hpp:434
Tuple(size_t len)
Builds a tuple of specified length but with uninitialized elements.
Definition: tuple.hpp:84
Tuple & operator=(Tuple &&rhs)
The move assignment.
Definition: tuple.hpp:113
Tuple(PyObject *po)
Constructs a new Tuple from a Python sequence.
Definition: tuple.hpp:99
Tuple()
The default constructor.
Definition: tuple.hpp:70
Sequence_Base< Derived > & operator=(Sequence_Base< Derived > &&rhs)
Move assignment.
Definition: sequence.hpp:264
Tuple(ProxyAttr &&rhs)
The move constructor from ProxyAttr objects.
Definition: tuple.hpp:110
Wraps a Python tuple.
Definition: tuple.hpp:49
Base class for all generic sequence types.
Definition: sequence.hpp:94
This is a simple wrapper around the PyObject* datatype.
Definition: obj.hpp:68