本文整理汇总了C++中basic::Pair类的典型用法代码示例。如果您正苦于以下问题:C++ Pair类的具体用法?C++ Pair怎么用?C++ Pair使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Pair类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getSpecificMissile
// Get the next free missile of type 'missileType'
Missile* SimpleStoresMgr::getSpecificMissile(const Basic::String* const missileType)
{
Missile* msl = 0;
if (missileType != 0) {
Basic::PairStream* list = getWeapons();
if (list != 0) {
// Find the first free (inactive) missile of type weaponType
Basic::List::Item* item = list->getFirstItem();
while (item != 0 && msl == 0) {
Basic::Pair* pair = (Basic::Pair*)(item->getValue());
Missile* p = dynamic_cast<Missile*>( pair->object() );
if (p != 0 && p->isInactive()) {
// Ok, we have a missile, but is it the type we want?
if (*p->getType() == *missileType) {
p->ref();
msl = p;
}
}
item = item->getNext();
}
list->unref();
}
}
return msl;
}
示例2: builder
//-----------------------------------------------------------------------------
// Eaagles::Swarms::builder() -- builds simulation tree
//-----------------------------------------------------------------------------
static void builder()
{
cout << "Reading file : " << configFile << endl;
// Read the description file
int errors = 0;
Basic::Object* q1 = Basic::lcParser(configFile, Factory::createObj, &errors);
if (errors > 0) {
cerr << "File: " << configFile << ", errors: " << errors << endl;
exit(1);
}
station = 0;
if (q1 != 0) {
// When we were given a Basic::Pair, get the pointer to its object.
Basic::Pair* pp = dynamic_cast<Basic::Pair*>(q1);
if (pp != 0) {
q1 = pp->object();
}
// What we should have here is the Station object
station = dynamic_cast<Simulation::Station*>(q1);
}
// Make sure we did get a valid Station object (we must have one!)
if (station == 0) {
cout << "Invalid description file!" << endl;
exit(EXIT_FAILURE);
}
}
示例3: removeSymbol
//------------------------------------------------------------------------------
// Removes a symbol from the master symbol table
//------------------------------------------------------------------------------
bool SymbolLoader::removeSymbol(const int idx)
{
bool ok = false;
// Find the symbol
if (idx >= 1 && idx <= MAX_SYMBOLS) {
const int i = (idx - 1);
if (symbols[i] != 0) {
// ---
// remove the symbol's graphical component from our subcomponent list
// ---
{
// Get the symbol's graphical component
Basic::Pair* pair = symbols[i]->getSymbolPair();
BasicGL::Graphic* g = (BasicGL::Graphic*) pair->object();
Basic::PairStream* x = getComponents();
Basic::Component::processComponents(x, typeid(BasicGL::Graphic), 0, g);
x->unref();
}
// ---
// and remove it from our master symbol table
// ---
symbols[i]->setSymbolPair(0);
symbols[i]->unref();
symbols[i] = 0;
ok = true;
}
}
return ok;
}
示例4: stepOwnshipPlayer
//------------------------------------------------------------------------------
// stepOwnshipPlayer() -- Step to the next local player
//------------------------------------------------------------------------------
void SimStation::stepOwnshipPlayer()
{
Basic::PairStream* pl = getSimulation()->getPlayers();
if (pl != nullptr) {
Simulation::Player* f = nullptr;
Simulation::Player* n = nullptr;
bool found = false;
// Find the next player
Basic::List::Item* item = pl->getFirstItem();
while (item != nullptr) {
Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue());
if (pair != nullptr) {
Simulation::Player* ip = static_cast<Simulation::Player*>(pair->object());
if ( ip->isMode(Simulation::Player::ACTIVE) &&
ip->isLocalPlayer() &&
ip->isClassType(typeid(Simulation::AirVehicle))
) {
if (f == nullptr) { f = ip; } // Remember the first
if (found) { n = ip; ; break; }
if (ip == getOwnship()) found = true;
}
}
item = item->getNext();
}
if (found && n == nullptr) n = f;
if (n != nullptr) setOwnshipPlayer(n);
pl->unref();
}
}
示例5: onJettisonEvent
// Default external equipment jettison event handler
bool Stores::onJettisonEvent(ExternalStore* const sys)
{
bool ok = false;
if (sys != 0) {
Basic::PairStream* list = getStores();
if (list != 0) {
// First, make sure it's one of ours!
bool found = false;
Basic::List::Item* item = list->getFirstItem();
while (item != 0 && !found) {
Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue());
found = (sys == pair->object()); // is it a match?
item = item->getNext();
}
if (found) {
// Send a jettison event to the system
ok = sys->event(JETTISON_EVENT);
}
list->unref();
list = 0;
}
}
return ok;
}
示例6: createWindow
//-----------------------------------------------------------------------------
// createWindow() -- create the main window
//-----------------------------------------------------------------------------
int GlutDisplay::createWindow()
{
winId = -1;
#ifdef __FREEGLUT_EXT_H__ /* freeglut only */
glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);
#endif
unsigned int wmode = GLUT_DOUBLE | GLUT_RGB | GLUT_ALPHA;
if (getClearDepth() >= 0.0f) { wmode = wmode | GLUT_DEPTH; }
if (accumBuff) { wmode = wmode | GLUT_ACCUM; }
if (stencilBuff) { wmode = wmode | GLUT_STENCIL; }
glutInitDisplayMode( wmode );
GLint vpX(0), vpY(0); // our initial viewport position
GLsizei vpWidth(0), vpHeight(0); // our initial viewport size
getViewport(&vpX, &vpY, &vpWidth, &vpHeight);
glutInitWindowPosition(vpX, vpY);
glutInitWindowSize(vpWidth, vpHeight);
winId = glutCreateWindow(getName());
if (winId > 0) {
if (isMessageEnabled(MSG_INFO)) {
std::cout << "GlutDisplay::createWindow() name = " << getName() << ", winId = " << winId << std::endl;
}
// Configure the new window
if (fullScreenFlg) glutFullScreen();
glutDisplayFunc(drawFuncCB);
glutReshapeFunc(reshapeItCB);
glutIdleFunc(idleCB);
glutPassiveMotionFunc(passiveMotionFuncCB);
glutMotionFunc(motionFuncCB);
glutKeyboardFunc(keyboardFuncCB);
glutSpecialFunc(specialFuncCB);
glutMouseFunc(mouseFuncCB);
glutEntryFunc(entryFuncCB);
registerGlutDisplay(winId, this);
glutSetWindow(winId);
configure();
loadTextures();
// Create sub windows (if any)
if (subDisplays() != nullptr) {
Basic::List::Item* item = subDisplays()->getFirstItem();
while (item != nullptr) {
Basic::Pair* pair = dynamic_cast<Basic::Pair*>(item->getValue());
if (pair != nullptr) {
GlutDisplay* dobj = dynamic_cast<GlutDisplay*>( pair->object() );
if (dobj != nullptr) dobj->createSubWindow(winId);
}
item = item->getNext();
}
}
// Select this window
select();
}
return winId;
}
示例7: searchAndAdd
//------------------------------------------------------------------------------
// Search all of the objects in the main list for objects of 'type' and add
// them to the sublist. Also check all Stores type objects for any 'type' objects.
//------------------------------------------------------------------------------
void StoresMgr::searchAndAdd(Basic::PairStream* const mainList, const std::type_info& type, Basic::PairStream* sublist)
{
if (mainList != 0 && sublist != 0) {
const Basic::List::Item* item = mainList->getFirstItem();
while (item != 0) {
Basic::Pair* pair = (Basic::Pair*)(item->getValue());
Basic::Component* p = (Basic::Component*)( pair->object() );
// Check the type and add to the list
bool isType = p->isClassType(type);
if (isType) sublist->put(pair);
// If this is a Stores object then check its stores for 'type' objects as well
Stores* sp = dynamic_cast<Stores*>(p);
if ( sp != 0 ) {
Basic::PairStream* pstores = sp->getStores();
searchAndAdd(pstores, type, sublist);
pstores->unref();
}
item = item->getNext();
}
}
}
示例8: getSpecificBomb
// Get the next free bomb of type 'bombType'
Bomb* SimpleStoresMgr::getSpecificBomb(const Basic::String* const bombType)
{
Bomb* bomb = 0;
if (bombType != 0) {
Basic::PairStream* list = getWeapons();
if (list != 0) {
// Find the first free (inactive) bomb
Basic::List::Item* item = list->getFirstItem();
while (item != 0 && bomb == 0) {
Basic::Pair* pair = (Basic::Pair*)(item->getValue());
Bomb* p = dynamic_cast<Bomb*>( pair->object() );
if (p != 0 && p->isInactive()) {
// Ok, we have a bomb, but is it the type we want?
if (*p->getType() == *bombType) {
p->ref();
bomb = p;
}
}
item = item->getNext();
}
list->unref();
}
}
return bomb;
}
示例9: 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;
}
示例10: determineColor
//------------------------------------------------------------------------------
// determineColors() - take our value, and look for a corresponding color
// and breakpoint
//------------------------------------------------------------------------------
bool ColorRotary::determineColor(const LCreal value)
{
bool ok = false;
int breakPoint = 0;
// find out where we are in the break table
unsigned int i = 0;
// do an endpoint check while we are at it
if (value >= myValues[numVals-1]) breakPoint = numVals;
while (!ok && i < numVals) {
if (value >= myValues[i] && value < myValues[i+1]) {
breakPoint = (i + 1);
ok = true;
}
else i++;
}
// now set the proper color (using the breakpoint index)
if (myColors != 0) {
Basic::Pair* pair = myColors->getPosition(breakPoint);
if (pair != 0) {
Basic::Color* listcolor = dynamic_cast<Basic::Color*>(pair->object());
if (listcolor != 0) {
osg::Vec4* vec = (osg::Vec4*) listcolor->getRGBA();
color = *vec;
ok = true;
}
}
}
return ok;
}
示例11: onJettisonEvent
// Default weapon jettison event handler
bool Stores::onJettisonEvent(Weapon* const wpn)
{
bool ok = false;
if (wpn != nullptr) {
Basic::PairStream* list = getStores();
if (list != nullptr) {
// First, make sure it's one of ours!
bool found = false;
Basic::List::Item* item = list->getFirstItem();
while (item != nullptr && !found) {
Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue());
found = (wpn == pair->object()); // is it a match?
item = item->getNext();
}
if (found) {
// Send a jettison event to the weapon
ok = wpn->event(JETTISON_EVENT);
}
list->unref();
list = nullptr;
}
}
return ok;
}
示例12: reshapeIt
//-----------------------------------------------------------------------------
// reshape it function, for reshaping our subdisplays
//-----------------------------------------------------------------------------
void GlutDisplay::reshapeIt(int w, int h)
{
//std::cout << "reshapeIt() winID = " << winId;
//std::cout << "; size(" << w << ", " << h << ")";
//std::cout << std::endl;
// make sure we have a min height and width or our displays will get destroyed
if (w > 10 && h > 10) {
BaseClass::reshapeIt(w, h);
if (subDisplays() != nullptr && okToResize) {
// go through and put our new numbers in
Basic::List::Item* item = subDisplays()->getFirstItem();
while (item != nullptr) {
Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue());
if (pair != nullptr) {
GlutDisplay* gd = dynamic_cast<GlutDisplay*>(pair->object());
if (gd != nullptr) gd->reshapeSubWindow();
}
item = item->getNext();
}
// Restore our window ID
glutSetWindow(this->getWindowId());
}
}
}
示例13: builder
// MyObj builder
static MyObj* builder(const char* const filename)
{
// read configuration file
int errors = 0;
Basic::Object* obj = Basic::lcParser(filename, factory, &errors);
if (errors > 0) {
std::cerr << "File: " << filename << ", errors: " << errors << std::endl;
std::exit(EXIT_FAILURE);
}
// test to see if an object was created
if (obj == 0) {
std::cerr << "Invalid configuration file, no objects defined!" << std::endl;
std::exit(EXIT_FAILURE);
}
// do we have a Basic::Pair, if so, point to object in Pair, not Pair itself
Basic::Pair* pair = dynamic_cast<Basic::Pair*>(obj);
if (pair != 0) {
obj = pair->object();
obj->ref();
pair->unref();
}
// try to cast to proper object, and check
MyObj* myObj = dynamic_cast<MyObj*>(obj);
if (myObj == 0) {
std::cerr << "Invalid configuration file!" << std::endl;
std::exit(EXIT_FAILURE);
}
return myObj;
}
示例14: getSpecificWeapon
// Get the next free weapon of this 'type'
Weapon* SimpleStoresMgr::getSpecificWeapon(const std::type_info& type)
{
Weapon* wpn = 0;
if (&type != 0) {
Basic::PairStream* list = getWeapons();
if (list != 0) {
// Find the first free (inactive) bomb
Basic::List::Item* item = list->getFirstItem();
while (item != 0 && wpn == 0) {
Basic::Pair* pair = (Basic::Pair*)(item->getValue());
Weapon* p = dynamic_cast<Weapon*>( pair->object() );
if (p != 0 && p->isInactive() && p->isClassType(type)) {
p->ref();
wpn = p;
}
item = item->getNext();
}
list->unref();
}
}
return wpn;
}
示例15: getTrackManagerByType
//------------------------------------------------------------------------------
// getTrackManagerByType() -- return the first track manager of type
//------------------------------------------------------------------------------
TrackManager* OnboardComputer::getTrackManagerByType(const std::type_info& type)
{
TrackManager* p = 0;
Basic::Pair* pair = findByType(type);
if (pair != 0) {
p = dynamic_cast<TrackManager*>( pair->object() );
}
return p;
}