本文整理汇总了C++中PyDict::GetItem方法的典型用法代码示例。如果您正苦于以下问题:C++ PyDict::GetItem方法的具体用法?C++ PyDict::GetItem怎么用?C++ PyDict::GetItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyDict
的用法示例。
在下文中一共展示了PyDict::GetItem方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PyObject
//.........这里部分代码省略.........
DBResultRow row;
while(res.GetRow(row))
types[row.GetUInt(0)].insert(row.GetUInt(1));
if(!sDatabase.RunQuery(res,
"SELECT"
" marketGroupID, parentGroupID"
" FROM invMarketGroups"))
{
codelog(MARKET__ERROR, "Error in query: %s", res.error.c_str());
return NULL;
}
std::map<int, int> parentChild; //maps child -> parent
std::map<int, std::set<int> > childParent; //maps parent -> all children.
while(res.GetRow(row)) {
//figure out the parent ID, mapping NULL to -1 for our map.
int marketGroupID = row.GetUInt(0);
int parentGroupID = row.IsNull(1) ? -1 : row.GetUInt(1);
parentChild[marketGroupID] = parentGroupID;
childParent[parentGroupID].insert(marketGroupID);
}
//now we need to propigate all of the items up the tree (a parent group's items list contains ALL items of its children.)
_PropigateItems(types, parentChild, childParent, -1);
//now we get to do the other query.
if(!sDatabase.RunQuery(res,
"SELECT"
" marketGroupID, parentGroupID, marketGroupName, description, graphicID, hasTypes"
" FROM invMarketGroups"))
{
codelog(MARKET__ERROR, "Error in query: %s", res.error.c_str());
return NULL;
}
//doing this the long (non XML) way to avoid the extra copies due to the huge volume of data here.
PyDict *args = new PyDict();
PyDict *parentSets = new PyDict();
PyList *header = new PyList();
header->AddItemString("marketGroupID");
header->AddItemString("parentGroupID");
header->AddItemString("marketGroupName");
header->AddItemString("description");
header->AddItemString("graphicID");
header->AddItemString("hasTypes");
header->AddItemString("types"); //this column really contains an entire list.
header->AddItemString("dataID");
args->SetItemString("header", header);
args->SetItemString("idName", new PyString("parentGroupID"));
args->SetItemString("RowClass", new PyToken("util.Row"));
args->SetItemString("idName2", new PyNone);
args->SetItemString("items", parentSets);
//now fill in items.
// we have to satisfy this structure... which uses parentGroupID as the
// main dict key, each dict entry is then a list of MarketGroup_Entrys
// which have that parentGroupID
//marketGroupID, parentGroupID, marketGroupName, description, graphicID, hasTypes, types
std::map< int, std::set<uint32> >::const_iterator tt;
MarketGroup_Entry entry;
PyList* list;
PyList* parents = new PyList();
while( res.GetRow(row) )
{
entry.marketGroupID = row.GetUInt( 0 );
//figure out the parent ID, mapping NULL to -1 for our map.
entry.parentGroupID = ( row.IsNull( 1 ) ? -1 : row.GetUInt( 1 ) );
entry.marketGroupName = row.GetText( 2 );
entry.description = row.GetText( 3 );
entry.graphicID = ( row.IsNull( 4 ) ? -1 : row.GetUInt( 4 ) );
entry.hasTypes = row.GetUInt( 5 );
// Insert all types
entry.types.clear();
tt = types.find( entry.marketGroupID );
if( tt != types.end() )
entry.types.insert( entry.types.begin(), tt->second.begin(), tt->second.end() );
if(entry.parentGroupID == -1)
list = parents;
else
list = static_cast<PyList*> (parentSets->GetItem(new PyInt( entry.parentGroupID )));
if(list == NULL)
list = new PyList();
list->AddItem(entry.Encode());
PySafeIncRef(list);
if(entry.parentGroupID != -1)
parentSets->SetItem(new PyInt(entry.parentGroupID), list);
}
parentSets->SetItem(new PyNone, parents);
return new PyObject( "util.FilterRowset", args );
}