/usr/include/rdkit/RDBoost/PySequenceHolder.h is in librdkit-dev 201503-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | //
// Copyright (c) 2003-2006 greg Landrum and Rational Discovery LLC
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
// The contents are covered by the terms of the BSD license
// which is included in the file license.txt, found at the root
// of the RDKit source tree.
//
#ifndef _RD_PYSEQUENCEHOLDER_H_
#define _RD_PYSEQUENCEHOLDER_H_
//
// Defines a class to hold sequences passed in from Python
//
#include "Wrap.h"
#include <RDGeneral/Invariant.h>
namespace python = boost::python;
//! \brief Class to hold sequences (lists, tuples, arrays, etc.)
//! passed from Python -> C++
//!
//! PySequenceHolder is templated on the type of the contained object.
//!
//! The class is \em lazy: elements are not evaluated until requested
//! within the C++ code.
//!
template <typename T>
class PySequenceHolder {
public:
PySequenceHolder(python::object seq) {
d_seq = seq;
};
// --------------------------------------------------
//! \brief Returns the size of the contained sequence.
//!
//! NOTE: the sequence must have a \c __len__ attribute, otherwise
//! a \c ValueError will be raised.
unsigned int size() const {
unsigned int res=0;
try {
res = python::extract<int>(d_seq.attr("__len__")());
} catch (...) {
throw_value_error("sequence does not support length query");
}
return res;
};
// --------------------------------------------------
//! \brief Returns an element of the sequence
//!
//! ARGUMENTS:
//! - which: an integer specifying which element should be returned.
//!
//! NOTES:
//! - if the sequence is not \a which elements long, we raise an
//! \c IndexError
//! - if the element cannot be converted to type \c T, we raise a
//! \c ValueError
T operator[](unsigned int which) const {
if(which > size()){
throw_index_error(which);
}
try{
T res = python::extract<T>(d_seq[which]);
return res;
} catch (...) {
throw_value_error("cannot extract desired type from sequence");
}
POSTCONDITION(0,"cannot reach this point");
return static_cast<T>(0);
};
private:
python::object d_seq;
};
#endif
|