本文整理汇总了C++中basic::PairStream::entries方法的典型用法代码示例。如果您正苦于以下问题:C++ PairStream::entries方法的具体用法?C++ PairStream::entries怎么用?C++ PairStream::entries使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类basic::PairStream
的用法示例。
在下文中一共展示了PairStream::entries方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setSlotStores
//------------------------------------------------------------------------------
// Set slot functions
//------------------------------------------------------------------------------
bool StoresMgr::setSlotStores(const Basic::PairStream* const msg)
{
// First let our base class do everything that it needs to.
BaseClass::setSlotStores(msg);
// ---
// Clear all previous stores and assigned weapons
// ---
weaponsList = 0;
externalList = 0;
fuelList = 0;
gunPtr = 0;
// ---
// Use the stores list that the Stores class just processed.
Basic::PairStream* stores = getStores();
if (stores != 0){
// Create the new weapons list that contains all weapons
{
Basic::PairStream* newWeapons = new Basic::PairStream();
searchAndAdd(stores, typeid(Weapon), newWeapons);
if (newWeapons->entries() > 0) weaponsList = newWeapons;
newWeapons->unref();
}
// Create the new external stores list that contains all
// non-weapon, external stores (e.g., fuel tanks, pods, guns)
{
Basic::PairStream* newExternal = new Basic::PairStream();
searchAndAdd(stores, typeid(ExternalStore), newExternal);
if (newExternal->entries() > 0) externalList = newExternal;
newExternal->unref();
}
// Create the new fuel tank list that contains all fuel tanks
{
Basic::PairStream* newFuel = new Basic::PairStream();
searchAndAdd(stores, typeid(FuelTank), newFuel);
if (newFuel->entries() > 0) fuelList = newFuel;
newFuel->unref();
}
// Find the primary gun; i.e., the first gun found on our stores
Basic::List::Item* item = stores->getFirstItem();
while (item != 0 && gunPtr == 0) {
Basic::Pair* pair = (Basic::Pair*)(item->getValue());
Gun* p = dynamic_cast<Gun*>( pair->object() );
if (p != 0) gunPtr = p;
item = item->getNext();
}
stores->unref();
stores = 0;
}
return true;
}
示例2: setSlotStores
//.........这里部分代码省略.........
}
numWpn = 0;
numEs = 0;
// ---
// Quick out if 'msg' is zero
// ---
if (msg == 0) return true;
bool ok = true;
// ---
// Create the new external stores list
//
// For all items in the 'msg' list ...
// -- Make sure that it's a weapon or other type of external store, and
// that it has a valid station number.
// -- Clone the store and if it's a weapon then assign it to the station.
// ---
Basic::PairStream* newStores = new Basic::PairStream();
const Basic::List::Item* item = msg->getFirstItem();
while (item != 0) {
const Basic::Pair* pair = static_cast<const Basic::Pair*>(item->getValue());
const Basic::Component* p = static_cast<const Basic::Component*>(pair->object());
if (p != 0) {
// get the station number from the stores' slot name
int stationNumber = 0;
const Basic::Identifier* stationName = pair->slot();
if (stationName->isInteger()) {
stationNumber = stationName->getInteger();
}
if (stationNumber > 0 && stationNumber <= static_cast<int>(ns)) {
// check the type of component
bool isWpn = p->isClassType(typeid(Weapon));
bool isEE = p->isClassType(typeid(ExternalStore));
if ( isWpn || isEE ) {
// Clone the weapon pair and set us as its container
Basic::Pair* cpair = pair->clone();
Component* cp = static_cast<Component*>(cpair->object());
cp->container(this);
if ( isWpn ) {
// Weapon types ...
// Assign the weapon to the station
Weapon* cwpn = static_cast<Weapon*>( cpair->object() );
assignWeaponToStation(stationNumber, cwpn);
}
if ( isEE ) {
// External stores types ...
// Assign the external store to the station
ExternalStore* cwpn = static_cast<ExternalStore*>( cpair->object() );
assignExtStoreToStation(stationNumber, cwpn);
}
if (cpair != 0) {
// Add to the new stores list
newStores->put(cpair);
cpair->unref(); // the new list has it.
}
}
else {
std::cerr << "Stores::setSlotStores(): invalid external stores type; use Weapon or Stores classes" << std::endl;
ok = false;
}
}
else {
std::cerr << "Stores::setSlotStores(): invalid station number from the store's slot name." << std::endl;
ok = false;
}
}
item = item->getNext();
}
// Make the new stores list the active list
if (ok && newStores->entries() > 0) {
storesList = newStores;
}
else {
for (unsigned int s = 1; s <= ns; s++) {
assignWeaponToStation(s,0);
}
numWpn = 0;
}
newStores->unref();
return ok;
}