本文整理汇总了C++中py::Tuple::size方法的典型用法代码示例。如果您正苦于以下问题:C++ Tuple::size方法的具体用法?C++ Tuple::size怎么用?C++ Tuple::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类py::Tuple
的用法示例。
在下文中一共展示了Tuple::size方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createWidget
Py::Object UiLoaderPy::createWidget(const Py::Tuple& args)
{
Py::Module sipmod(PyImport_AddModule((char*)"sip"));
Py::Module qtmod(PyImport_ImportModule((char*)"PyQt4.Qt"));
// 1st argument
std::string className = (std::string)Py::String(args[0]);
// 2nd argument
QWidget* parent = 0;
if (args.size() > 1) {
Py::Callable func = sipmod.getDict().getItem("unwrapinstance");
Py::Tuple arguments(1);
arguments[0] = args[1]; //PyQt pointer
Py::Object result = func.apply(arguments);
void* ptr = PyLong_AsVoidPtr(result.ptr());
QObject* object = reinterpret_cast<QObject*>(ptr);
if (object)
parent = qobject_cast<QWidget*>(object);
}
// 3rd argument
std::string objectName;
if (args.size() > 2) {
objectName = (std::string)Py::String(args[2]);
}
QWidget* widget = loader.createWidget(QString::fromAscii(className.c_str()), parent,
QString::fromAscii(objectName.c_str()));
Py::Callable func = sipmod.getDict().getItem("wrapinstance");
Py::Tuple arguments(2);
arguments[0] = Py::asObject(PyLong_FromVoidPtr(widget));
arguments[1] = qtmod.getDict().getItem("QWidget");
return func.apply(arguments);
}
示例2: Int
Py::Object
_path_module::path_intersects_path(const Py::Tuple& args)
{
args.verify_length(2, 3);
PathIterator p1(args[0]);
PathIterator p2(args[1]);
bool filled = false;
if (args.size() == 3)
{
filled = args[2].isTrue();
}
if (!filled)
{
return Py::Int(::path_intersects_path(p1, p2));
}
else
{
return Py::Int(::path_intersects_path(p1, p2)
|| ::path_in_path(p1, agg::trans_affine(), p2, agg::trans_affine())
|| ::path_in_path(p2, agg::trans_affine(), p1, agg::trans_affine()));
}
}
示例3: read
py::Object read ( py::Object self, py::Tuple args )
try
{
std::istream& stream = *static_cast<std::istream*>
(py::TypeBuilder::get_baton(self));
std::ostringstream payload;
if ( args.size() == 1 )
{
char data[1024];
long size = py::Int(args[0]);
for (; (size > 0); size -= stream.gcount()) {
stream.read(data, std::min(size, long(sizeof(data))));
payload.write(data, stream.gcount());
}
}
else {
payload << stream.rdbuf();
}
return (py::Bytes(payload.str()));
}
catch ( const std::bad_cast& )
{
std::cerr << "Bad cast!" << std::endl;
return (py::None());
}
示例4: write
py::Object write ( py::Object self, py::Tuple args )
{
std::ostream& stream = *static_cast<std::ostream*>
(py::TypeBuilder::get_baton(self));
if (args.size() == 1)
{
stream << (std::string)py::Bytes(args[0]);
}
return (py::None());
}
示例5: writelines
py::Object writelines ( py::Object self, py::Tuple args )
{
std::ostream& stream = *static_cast<std::ostream*>
(py::TypeBuilder::get_baton(self));
if (args.size() == 1)
{
py::Iterator iterator(args[0]);
while (iterator.next()) {
stream << (std::string)py::Bytes(iterator.item());
}
}
return (py::None());
}
示例6: irrelevant
Py::Object CyPy_Task::irrelevant(const Py::Tuple& args)
{
m_value->irrelevant();
if (args.size() > 0) {
args.verify_length(1);
Atlas::Objects::Operation::Error e;
Atlas::Objects::Entity::Anonymous arg;
arg->setAttr("message", verifyString(args.front()));
e->modifyArgs().push_back(arg);
e->setTo(m_value->m_usageInstance.actor->getId());
return CyPy_Operation::wrap(e);
}
return Py::None();
}
示例7: write_png
// this code is heavily adapted from the paint license, which is in
// the file paint.license (BSD compatible) included in this
// distribution. TODO, add license file to MANIFEST.in and CVS
Py::Object _png_module::write_png(const Py::Tuple& args)
{
args.verify_length(4, 5);
FILE *fp = NULL;
bool close_file = false;
bool close_dup_file = false;
Py::Object buffer_obj = Py::Object(args[0]);
PyObject* buffer = buffer_obj.ptr();
if (!PyObject_CheckReadBuffer(buffer))
{
throw Py::TypeError("First argument must be an rgba buffer.");
}
const void* pixBufferPtr = NULL;
Py_ssize_t pixBufferLength = 0;
if (PyObject_AsReadBuffer(buffer, &pixBufferPtr, &pixBufferLength))
{
throw Py::ValueError("Couldn't get data from read buffer.");
}
png_byte* pixBuffer = (png_byte*)pixBufferPtr;
int width = (int)Py::Int(args[1]);
int height = (int)Py::Int(args[2]);
if (pixBufferLength < width * height * 4)
{
throw Py::ValueError("Buffer and width, height don't seem to match.");
}
Py::Object py_fileobj = Py::Object(args[3]);
PyObject* py_file = NULL;
if (py_fileobj.isString())
{
if ((py_file = npy_PyFile_OpenFile(py_fileobj.ptr(), (char *)"wb")) == NULL) {
throw Py::Exception();
}
close_file = true;
}
else
{
py_file = py_fileobj.ptr();
}
if ((fp = npy_PyFile_Dup(py_file, (char *)"wb")))
{
close_dup_file = true;
}
else
{
PyErr_Clear();
PyObject* write_method = PyObject_GetAttrString(
py_file, "write");
if (!(write_method && PyCallable_Check(write_method)))
{
Py_XDECREF(write_method);
throw Py::TypeError(
"Object does not appear to be a 8-bit string path or "
"a Python file-like object");
}
Py_XDECREF(write_method);
}
png_bytep *row_pointers = NULL;
png_structp png_ptr = NULL;
png_infop info_ptr = NULL;
try
{
struct png_color_8_struct sig_bit;
png_uint_32 row;
row_pointers = new png_bytep[height];
for (row = 0; row < (png_uint_32)height; ++row)
{
row_pointers[row] = pixBuffer + row * width * 4;
}
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png_ptr == NULL)
{
throw Py::RuntimeError("Could not create write struct");
}
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL)
{
throw Py::RuntimeError("Could not create info struct");
}
if (setjmp(png_jmpbuf(png_ptr)))
{
throw Py::RuntimeError("Error building image");
}
if (fp)
{
//.........这里部分代码省略.........