LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
boost::python::detail::slice_helper< Container, DerivedPolicies, ProxyHandler, Data, Index > Struct Template Reference

#include "indexing_suite_detail.hpp"

Static Public Member Functions

static object base_get_slice (Container &container, PySliceObject *slice)
 
static void base_get_slice_data (Container &container, PySliceObject *slice, Index &from_, Index &to_)
 
static void base_set_slice (Container &container, PySliceObject *slice, PyObject *v)
 
static void base_delete_slice (Container &container, PySliceObject *slice)
 

Detailed Description

template<class Container, class DerivedPolicies, class ProxyHandler, class Data, class Index>
struct boost::python::detail::slice_helper< Container, DerivedPolicies, ProxyHandler, Data, Index >

Definition at line 577 of file indexing_suite_detail.hpp.

Member Function Documentation

template<class Container , class DerivedPolicies , class ProxyHandler , class Data , class Index >
static void boost::python::detail::slice_helper< Container, DerivedPolicies, ProxyHandler, Data, Index >::base_delete_slice ( Container &  container,
PySliceObject *  slice 
)
inlinestatic

Definition at line 692 of file indexing_suite_detail.hpp.

693  {
694  Index from, to;
695  base_get_slice_data(container, slice, from, to);
696  ProxyHandler::base_erase_indexes(container, from, to);
697  DerivedPolicies::delete_slice(container, from, to);
698  }
static void base_get_slice_data(Container &container, PySliceObject *slice, Index &from_, Index &to_)
template<class Container , class DerivedPolicies , class ProxyHandler , class Data , class Index >
static object boost::python::detail::slice_helper< Container, DerivedPolicies, ProxyHandler, Data, Index >::base_get_slice ( Container &  container,
PySliceObject *  slice 
)
inlinestatic

Definition at line 580 of file indexing_suite_detail.hpp.

581  {
582  Index from, to;
583  base_get_slice_data(container, slice, from, to);
584  return DerivedPolicies::get_slice(container, from, to);
585  }
static void base_get_slice_data(Container &container, PySliceObject *slice, Index &from_, Index &to_)
template<class Container , class DerivedPolicies , class ProxyHandler , class Data , class Index >
static void boost::python::detail::slice_helper< Container, DerivedPolicies, ProxyHandler, Data, Index >::base_get_slice_data ( Container &  container,
PySliceObject *  slice,
Index &  from_,
Index &  to_ 
)
inlinestatic

Definition at line 588 of file indexing_suite_detail.hpp.

590  {
591  if (Py_None != slice->step) {
592  PyErr_SetString( PyExc_IndexError, "slice step size not supported.");
593  throw_error_already_set();
594  }
595 
596  Index min_index = DerivedPolicies::get_min_index(container);
597  Index max_index = DerivedPolicies::get_max_index(container);
598 
599  if (Py_None == slice->start) {
600  from_ = min_index;
601  }
602  else {
603  long from = extract<long>( slice->start);
604  if (from < 0) // Negative slice index
605  from += max_index;
606  if (from < 0) // Clip lower bounds to zero
607  from = 0;
608  from_ = boost::numeric_cast<Index>(from);
609  if (from_ > max_index) // Clip upper bounds to max_index.
610  from_ = max_index;
611  }
612 
613  if (Py_None == slice->stop) {
614  to_ = max_index;
615  }
616  else {
617  long to = extract<long>( slice->stop);
618  if (to < 0)
619  to += max_index;
620  if (to < 0)
621  to = 0;
622  to_ = boost::numeric_cast<Index>(to);
623  if (to_ > max_index)
624  to_ = max_index;
625  }
626  }
template<class Container , class DerivedPolicies , class ProxyHandler , class Data , class Index >
static void boost::python::detail::slice_helper< Container, DerivedPolicies, ProxyHandler, Data, Index >::base_set_slice ( Container &  container,
PySliceObject *  slice,
PyObject *  v 
)
inlinestatic

Definition at line 629 of file indexing_suite_detail.hpp.

References x.

630  {
631  Index from, to;
632  base_get_slice_data(container, slice, from, to);
633 
634  extract<Data&> elem(v);
635  // try if elem is an exact Data
636  if (elem.check())
637  {
638  ProxyHandler::base_replace_indexes(container, from, to, 1);
639  DerivedPolicies::set_slice(container, from, to, elem());
640  }
641  else
642  {
643  // try to convert elem to Data
644  extract<Data> elem(v);
645  if (elem.check())
646  {
647  ProxyHandler::base_replace_indexes(container, from, to, 1);
648  DerivedPolicies::set_slice(container, from, to, elem());
649  }
650  else
651  {
652  // Otherwise, it must be a list or some container
653  handle<> l_(python::borrowed(v));
654  object l(l_);
655 
656  std::vector<Data> temp;
657  for (int i = 0; i < l.attr("__len__")(); i++)
658  {
659  object elem(l[i]);
660  extract<Data const&> x(elem);
661  // try if elem is an exact Data type
662  if (x.check())
663  {
664  temp.push_back(x());
665  }
666  else
667  {
668  // try to convert elem to Data type
669  extract<Data> x(elem);
670  if (x.check())
671  {
672  temp.push_back(x());
673  }
674  else
675  {
676  PyErr_SetString(PyExc_TypeError,
677  "Invalid sequence element");
678  throw_error_already_set();
679  }
680  }
681  }
682 
683  ProxyHandler::base_replace_indexes(container, from, to,
684  temp.end()-temp.begin());
685  DerivedPolicies::set_slice(container, from, to,
686  temp.begin(), temp.end());
687  }
688  }
689  }
Float_t x
Definition: compare.C:6
static void base_get_slice_data(Container &container, PySliceObject *slice, Index &from_, Index &to_)

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