// Return a relation of tuples that satisfy the conditions. The new relation // is stored in the result data member. Relation Database::selection( vector<Condition> conditions, Relation* targetRelation ) { result.clear( ); // Set up the list of conditions. ConditionList cl = ConditionList( conditions, targetRelation ); // Find the tuples in the relation that satisfy the conditions and add // them to the new relation. for ( int i = 0; i < targetRelation->getNumTuples( ); i++ ){ if ( cl.evalOnTuple( i ) ){ vector<Entry*> newRow; // Find the columns that satify the conditions and create // a tuple out of them for ( int j = 0; j < targetRelation->attributeSize( ); j++ ){ newRow.push_back( new Entry( *targetRelation->getRow( i ).at( j ) ) ); } // Add the newly created tuple to the new relation. result.addRow( newRow ); } } result.setAttributes( targetRelation->getAttributes( ) ); result.setKeys( targetRelation->getKeys() ); return result; }
void Creature::removeCondition(const Creature* attacker, ConditionType_t type) { ConditionList tmpList = conditions; for(ConditionList::iterator it = tmpList.begin(); it != tmpList.end(); ++it) { if((*it)->getType() == type) onCombatRemoveCondition(attacker, *it); } }
void Creature::removeCondition(const std::string& name, const CombatSource& combatSource) { ConditionList tmpList = conditions; for(ConditionList::iterator it = tmpList.begin(); it != tmpList.end(); ++it){ if((*it)->getName() == name){ onCombatRemoveCondition(combatSource, *it); } } }
bool PhaseMgr::NeedsPhaseUpdateWithData(PhaseUpdateData const updateData) const { PhaseDefinitionStore::const_iterator itr = _PhaseDefinitionStore->find(player->GetZoneId()); if (itr != _PhaseDefinitionStore->end()) { for (PhaseDefinitionContainer::const_iterator phase = itr->second.begin(); phase != itr->second.end(); ++phase) { ConditionList conditionList = sConditionMgr->GetConditionsForPhaseDefinition(phase->zoneId, phase->entry); for (ConditionList::const_iterator condition = conditionList.begin(); condition != conditionList.end(); ++condition) if (updateData.IsConditionRelated(*condition)) return true; } } return false; }
bool Item::IsTargetValidForItemUse(Unit* pUnitTarget) { ConditionList conditions = sConditionMgr->GetConditionsForNotGroupedEntry(CONDITION_SOURCE_TYPE_ITEM_REQUIRED_TARGET, GetProto()->ItemId); if (conditions.empty()) return true; if (!pUnitTarget) return false; for (ConditionList::const_iterator itr = conditions.begin(); itr != conditions.end(); ++itr) { ACE_Auto_Ptr<ItemRequiredTarget> irt(new ItemRequiredTarget((ItemRequiredTargetType)(*itr)->mConditionValue1, (*itr)->mConditionValue2)); if (irt->IsFitToRequirements(pUnitTarget)) return true; } return false; }
bool Item::IsTargetValidForItemUse(Unit* pUnitTarget) { ConditionList conditions = sConditionMgr->GetConditionsForNotGroupedEntry(CONDITION_SOURCE_TYPE_ITEM_REQUIRED_TARGET, GetTemplate()->ItemId); if (conditions.empty()) return true; if (!pUnitTarget) return false; for (ConditionList::const_iterator itr = conditions.begin(); itr != conditions.end(); ++itr) { ItemRequiredTarget irt(ItemRequiredTargetType((*itr)->ConditionValue1), (*itr)->ConditionValue2); if (irt.IsFitToRequirements(pUnitTarget)) return true; } return false; }
// Updates all of the entries in a relation that meet the specified condition Relation* Database::update( string relationName, vector<string> attributeNames, vector<Entry> newVals, vector<Condition> conditions ) { Relation* targetRelation = findRelation( relationName ); vector<string> targetAttNames = targetRelation->getAttributeNames( ); vector<int> targetIndeces; for ( unsigned i = 0; i < attributeNames.size( ); i++ ){ for ( unsigned j = 0; j < targetAttNames.size( ); j++ ){ if ( attributeNames.at( i ) == targetAttNames.at( j ) ){ targetIndeces.push_back( j ); } } } ConditionList cl = ConditionList( conditions, targetRelation ); for ( int i = 0; i < targetRelation->getNumTuples( ); i++ ){ if ( cl.evalOnTuple( i ) ){ vector<Entry*> targetRow = targetRelation->getRow( i ); for ( unsigned j = 0; j < targetIndeces.size( ); j++ ){ delete targetRow.at( targetIndeces.at( j ) ); targetRow.at( targetIndeces.at( j ) ) = new Entry( newVals.at( j ) ); } targetRelation->updateRow( targetRow, i ); } } return targetRelation; }
BinaryLogicalCondition::BinaryLogicalCondition(ConditionList& conditions): Condition(Condition::BinLogicCon), conditions(conditions) { if(conditions.size() ==0){ throw InvalidConditionException("Sorry bud, but you gotta at least give me one condition " "when you're constructing a BinaryLogicalCondition. Looks like you didn't. I'm just gonna " "chalk it up a silly little mistake though. Take a look over your conditions again and make sure " "you don't ever give any of your BinaryLogicConditions and empty condition list.\n\n" "Error: Empty condition list given to a BinaryLogicalCondition constructor."); } }
// Delete from a relation based on the specified conditions Relation Database::deleteFromRelation( Relation* targetRelation, vector<Condition> conditions ){ ConditionList cl = ConditionList( conditions, targetRelation ); //WE CANT DELETE THESE RIGHT AWAY OR ELSE WE MESS UP OUR DATA STRUCTURES vector<int> toBeDeleted; for ( int i = 0; i < targetRelation->getNumTuples( ); ++i ){ if ( cl.evalOnTuple( i ) ){ toBeDeleted.push_back( i ); } } for ( unsigned i = 0; i < toBeDeleted.size( ); i++ ){ //the index decreases as we delete rows targetRelation->deleteRow( toBeDeleted.at( i ) - i ); } return targetRelation; }