本文整理汇总了C++中boost::python::list::attr方法的典型用法代码示例。如果您正苦于以下问题:C++ list::attr方法的具体用法?C++ list::attr怎么用?C++ list::attr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::python::list
的用法示例。
在下文中一共展示了list::attr方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: periodise_wrap
int periodise_wrap(boost::python::list args ) {
int iSize = extract<int> (args.attr("__len__")()),
iIb ;
char ** argv = new char*[iSize+1] ;
#define NOM "periodise"
argv[0] = new char[strlen(NOM)+1] ;
strcpy (argv[0], NOM);
for (iIb=0; iIb < iSize ; iIb ++) {
const char * pcArg ;
extract <const char*> earg(args[iIb]);
if (earg.check()) {
pcArg= earg() ;
argv[iIb+1] = new char[strlen(pcArg)+1] ;
strcpy (argv[iIb+1], pcArg);
}
}
int result = periodise (iSize+1, argv ) ;
for (iIb = 0 ; iIb < iSize ;iIb ++) {
delete [] argv[iIb] ;
}
delete [](argv) ;
return result ;
}
示例2: insert
inline void json::insert(const json::key_type& k, const boost::python::list& li) {
unsigned n = boost::python::extract<unsigned>(li.attr("__len__")());
if(!n) return;
jsonvec jv;
for(unsigned i=0;i<n;++i) {
try {
qm_real v = boost::python::extract<qm_real>(li[i]);
jv.add(v);
}
catch(...) {
try {
qm_string s = boost::python::extract<qm_string>(li[i]);
jv.add(s);
}
catch(...) {
try {
json js(*boost::python::extract<json*>(li[i]));
jv.add(js);
}
catch(...) {
QM_FAIL("Could not add list");
}
}
}
}
this->insert(k,jv);
}
示例3: ObjToVector
Array<double,1>* ObjToVector (const list& list)
{
int len = boost::python::extract<int>(list.attr("__len__")());/**< Get the list length */
Array<double,1>* vector = new Array<double,1>(len);
for (int i = 0; i < len; i++)
{
(*vector)(i) = (boost::python::extract<int>(list[i]));
}
return vector;
}
示例4: open
bool PythonSignal::open(boost::python::list macAddress) {
BOOST_VERIFY(mpSignal != 0);
uint8_t mac[6] = {0,0,0,0,0,0};
if(boost::python::extract<size_t>(macAddress.attr("__len__")()) >= 6) {
for (int i = 5; i >= 0; i--) {
mac[i] = boost::python::extract<uint8_t>(macAddress.pop());
}
}
return mpSignal->open(mac);
}
示例5: mpi_init
bool mpi_init(boost::python::list python_argv)
{
using boost::python::extract;
using boost::python::object;
// If already initialized, do nothing but note that initialization
// is done.
int flag = 0;
int result = MPI_Initialized(&flag);
assert(result == MPI_SUCCESS);
if (flag) return false;
// Convert Python argv into C-style argc/argv. Ewwwww!
int my_argc = extract<int>(python_argv.attr("__len__")());
char** my_argv = new char*[my_argc];
for (int arg = 0; arg < my_argc; ++arg)
my_argv[arg] = strdup(extract<const char*>(python_argv[arg]));
// Initialize MPI
int mpi_argc = my_argc;
char** mpi_argv = my_argv;
result = MPI_Init(&mpi_argc, &mpi_argv);
assert(result == MPI_SUCCESS);
// If anything changed, convert C-style argc/argv into Python argv
if (mpi_argv != my_argv) {
// Tear down Python argv
while (int(extract<int>(python_argv.attr("__len__")())) > 0)
python_argv.pop();
// Build up new Python argv
for (int arg = 0; arg < mpi_argc; ++arg)
python_argv.append(object(mpi_argv[arg]));
}
for (int arg = 0; arg < my_argc; ++arg)
free(my_argv[arg]);
delete [] my_argv;
return true;
}
示例6: ObjToArray
Array<double,2>* ObjToArray(const list& list)
{
int row = boost::python::extract<int>(list.attr("__len__")());/**< Get the row length */
int col = boost::python::extract<int>(list[1].attr("__len__")());/**< Get the column length, all columns have the same size * */
Array<double,2>* tab = new Array<double,2>(row,col);
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j ++)
{
(*tab)(i,j) = (boost::python::extract<int>(list[i][j]));
}
}
return tab;
}
示例7: lenExtract
ConvexHull2::ConvexHull2(boost::python::list points)
{
boost::python::object lenObj = points.attr( "__len__" )();
boost::python::extract<int> lenExtract( lenObj );
if ( lenExtract.check() )
{
int numPoints = lenExtract;
for (int pointI = 0; pointI < numPoints; pointI++)
{
boost::python::object pointObj = points[pointI];
boost::python::extract<Point2&> pointExtract( pointObj );
if ( pointExtract.check() )
{
addPoint( pointExtract );
}
}
}
}
示例8: lenExtract
Polygon2::Polygon2(boost::python::list verts)
{
boost::python::object lenObj = verts.attr( "__len__" )();
boost::python::extract<int> lenExtract( lenObj );
if ( lenExtract.check() )
{
int numVerts = lenExtract;
vertices.reserve( numVerts );
for (int i = 0; i < numVerts; i++)
{
boost::python::object pointObj = verts[i];
boost::python::extract<Point2&> pointExtract( pointObj );
if ( pointExtract.check() )
{
vertices.push_back( pointExtract );
}
}
}
}