10 #include <QSharedPointer>
19 #include <pybind11/pybind11.h>
20 #include <pybind11/native_enum.h>
31 template <>
struct type_caster<QString>
35 bool load(handle src,
bool)
37 PyObject *source = src.ptr();
39 const char *str = PyUnicode_AsUTF8(source);
49 static handle
cast(
const QString &src, return_value_policy policy, handle parent)
51 const QByteArray byteArray = src.toUtf8();
53 const char *errors =
nullptr;
54 PyObject *obj = PyUnicode_DecodeUTF8(byteArray.constData(), byteArray.size(), errors);
59 template <>
struct type_caster<QByteArray>
63 bool load(handle src,
bool)
65 if (!src || !isinstance<pybind11::bytes>(src))
72 if (PyBytes_AsStringAndSize(src.ptr(), &buffer, &
length) == -1)
74 std::runtime_error(
"Unable to extract bytes contents!");
76 value = QByteArray(buffer,
length);
80 static handle
cast(
const QByteArray &src, return_value_policy , handle )
82 return PyBytes_FromStringAndSize(src.constData(), src.size());
86 template <>
struct type_caster<QVariant>
90 bool load(handle src,
bool)
101 if (isinstance<pybind11::int_>(src))
103 value = src.cast<
int>();
105 else if (isinstance<pybind11::str>(src))
107 value = QString::fromStdString(src.cast<std::string>());
109 else if (isinstance<pybind11::float_>(src))
111 value = src.cast<
double>();
120 static handle
cast(
const QVariant &src, return_value_policy policy, handle handle)
122 pybind11::object h = none();
125 case QVariant::Invalid:
128 h = pybind11::cast(src.toBool(), policy, handle);
131 h = pybind11::cast(src.toInt(), policy, handle);
134 h = pybind11::cast(src.toUInt(), policy, handle);
136 case QVariant::LongLong:
137 h = pybind11::cast(src.toLongLong(), policy, handle);
139 case QVariant::ULongLong:
140 h = pybind11::cast(src.toULongLong(), policy, handle);
142 case QVariant::Double:
143 h = pybind11::cast(src.toDouble(), policy, handle);
146 h = pybind11::cast(src.toChar(), policy, handle);
148 case QVariant::String:
149 h = pybind11::cast(src.toString(), policy, handle);
157 case QVariant::ByteArray:
158 h = pybind11::cast(src.toByteArray(), policy, handle);
160 case QVariant::BitArray:
170 case QVariant::Locale:
174 case QVariant::RectF:
178 case QVariant::SizeF:
182 case QVariant::LineF:
184 case QVariant::Point:
186 case QVariant::PointF:
188 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
189 case QVariant::RegularExpression:
192 case QVariant::RegExp:
197 case QVariant::EasingCurve:
201 case QVariant::ModelIndex:
203 case QVariant::PersistentModelIndex:
205 case QVariant::LastCoreType:
209 case QVariant::Pixmap:
211 case QVariant::Brush:
213 case QVariant::Color:
215 case QVariant::Palette:
217 case QVariant::Image:
219 case QVariant::Polygon:
221 case QVariant::Region:
223 case QVariant::Bitmap:
225 case QVariant::Cursor:
227 case QVariant::KeySequence:
231 case QVariant::TextLength:
233 case QVariant::TextFormat:
234 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
236 case QVariant::Matrix:
241 case QVariant::Matrix4x4:
243 case QVariant::Vector2D:
245 case QVariant::Vector3D:
247 case QVariant::Vector4D:
249 case QVariant::Quaternion:
253 case QVariant::LastGuiType:
255 case QVariant::SizePolicy:
257 case QVariant::UserType:
259 #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
260 case QVariant::PolygonF:
263 case QVariant::LastType:
264 throw std::runtime_error(
"Cannot convert this QVariant to python object");
PYBIND11_MAKE_OPAQUE(QSharedPointer< ccColorScale >)
PYBIND11_DECLARE_HOLDER_TYPE(T, QSharedPointer< T >)
__host__ __device__ float length(float2 v)
void Transform(benchmark::State &state, const core::Device &device)
std::vector< std::string > StringList
PYBIND11_TYPE_CASTER(QByteArray, _("QByteArray"))
bool load(handle src, bool)
static handle cast(const QByteArray &src, return_value_policy, handle)
bool load(handle src, bool)
PYBIND11_TYPE_CASTER(QString, _("QString"))
static handle cast(const QString &src, return_value_policy policy, handle parent)
static handle cast(const QVariant &src, return_value_policy policy, handle handle)
PYBIND11_TYPE_CASTER(QVariant, _("QVariant"))
bool load(handle src, bool)