3.2 Wrappers for std::vector<T>

PyQwt3D has a partial interface to the following C++ std::vector templates:

  1. AxisVector for std::vector<Axis>
  2. Cell for std::vector<unsigned>
  3. CellField for std::vector<Cell>
  4. ColorVector for std::vector<RGBA>
  5. DoubleVector for std::vector<double>
  6. FreeVectorField for std::vector<FreeVectorField>
  7. TripleField for std::vector<Triple>

The interface implements four constructors for each template instantianation - taking Cell as example:

  1. Cell()
  2. Cell(size)
  3. Cell(size, item)
  4. Cell(otherCell)

and 13 member functions - taking Cell as example:

  1. result = cell.capacity()
  2. cell.clear()
  3. result = cell.empty()
  4. result = cell.back()
  5. result = cell.front()
  6. result = cell.max_size()
  7. cell.pop_back()
  8. cell.push_back(item)
  9. cell.reserve(size)
  10. cell.reserve(size, item = 0)
  11. cell.resize(size, item = 0)
  12. result = cell.size()
  13. cell.swap(otherCell)

Iterators are not yet implemented. However, the implementation of the Python slots __getitem__, __len__ and __setitem__ let you use those classes almost as a sequence. For instance:

>>> from Qwt3D import *
>>> tf = TripleField()
>>> tf.push_back(Triple(0.0, 1.0, 2.0))
>>> tf.push_back(Triple(1.0, 2.0, 3.0))
>>> for t in tf:                                 # thanks to __getitem__
...  print t.x, t.y, t.z
...
0.0 1.0 2.0
1.0 2.0 3.0
>>> for i in range(len(tf)):                     # thanks to __len__
...  print tf[i].x, tf[i].y, tf[i].z
...
0.0 1.0 2.0
1.0 2.0 3.0
>>> for i in range(len(tf)):                     # thanks to __len__
...  tf[i] = Triple(i, 2*i, 3*i)		 # thanks to __setitem__
...
>>> for t in tf:                                 # thanks to __getitem__
...  print t.x, t.y, t.z
...
0.0 0.0 0.0
1.0 2.0 3.0
>>>