Code:
RouteData<A> *old_winner = NULL, *old_winner_clone = NULL; //neki korisnicki (templatizovani) tip RouteData
list<RouteData<A> > alternatives; //lista istog tipa
old_winner = find_alternative_routes(caller, rtmsg.net(), alternatives); //funkcija koja vraca pokazivac na element liste "alternatives"
RouteData<A> *old_winner = NULL, *old_winner_clone = NULL; //neki korisnicki (templatizovani) tip RouteData
list<RouteData<A> > alternatives; //lista istog tipa
old_winner = find_alternative_routes(caller, rtmsg.net(), alternatives); //funkcija koja vraca pokazivac na element liste "alternatives"
Implementacija funkcije find_alternative_routes izgleda ovako:
Code:
template<class A>
RouteData<A>*
DecisionTable<A>::find_alternative_routes(
const BGPRouteTable<A> *caller,
const IPNet<A>& net,
list <RouteData<A> >& alternatives) const
{
RouteData<A>* previous_winner = NULL;
typename map<BGPRouteTable<A>*, PeerTableInfo<A>* >::const_iterator i;
const SubnetRoute<A>* found_route;
for (i = _parents.begin(); i != _parents.end(); i++) {
//We don't need to lookup the route in the parent that the new
//route came from - if this route replaced an earlier route
//from the same parent we'd see it as a replace, not an add
if (i->first != caller) {
uint32_t found_genid;
FPAListRef found_attributes;
found_route = i->first->lookup_route(net, found_genid,
found_attributes);
if (found_route != NULL) {
PeerTableInfo<A> *pti = i->second;
alternatives.push_back(RouteData<A>(found_route,
found_attributes,
pti->route_table(),
pti->peer_handler(),
found_genid));
if (found_route->is_winner()) {
XLOG_ASSERT(previous_winner == NULL);
previous_winner = &(alternatives.back());
}
}
}
}
return previous_winner;
}
template<class A>
RouteData<A>*
DecisionTable<A>::find_alternative_routes(
const BGPRouteTable<A> *caller,
const IPNet<A>& net,
list <RouteData<A> >& alternatives) const
{
RouteData<A>* previous_winner = NULL;
typename map<BGPRouteTable<A>*, PeerTableInfo<A>* >::const_iterator i;
const SubnetRoute<A>* found_route;
for (i = _parents.begin(); i != _parents.end(); i++) {
//We don't need to lookup the route in the parent that the new
//route came from - if this route replaced an earlier route
//from the same parent we'd see it as a replace, not an add
if (i->first != caller) {
uint32_t found_genid;
FPAListRef found_attributes;
found_route = i->first->lookup_route(net, found_genid,
found_attributes);
if (found_route != NULL) {
PeerTableInfo<A> *pti = i->second;
alternatives.push_back(RouteData<A>(found_route,
found_attributes,
pti->route_table(),
pti->peer_handler(),
found_genid));
if (found_route->is_winner()) {
XLOG_ASSERT(previous_winner == NULL);
previous_winner = &(alternatives.back());
}
}
}
}
return previous_winner;
}
Dakle, funkcija find_alternative routes vraca pokazivac (previous_winner) na element liste "alternatives" koji zadovoljava uslov if (found_route->is_winner()), i povratna vrednost se dodeljuje promenjivoj (pokazivacu) old_winner sa pocetka code-a. Sada treba prosiriti ovaj model tako da old_winner sa pocetka moze da prihvati vise vrednosti tj. vise pokazivaca na listu "alternatives" koje bi funkcija find_alternative_routes trebala da vrati pod istim if uslovom. Moje razumevanje je da old_winner sada treba deklarisati kao listu pokazivaca na elemente liste "alternatives" (koji su takodje tipa RouteData) i da funkcija find_alternative_routes sada treba da vrati tu listu pokazivaca. Kako bi se ovo realizovalo na konkretnom primeru? Hvala
[Ovu poruku je menjao X Files dana 06.03.2010. u 19:50 GMT+1]