From 138e7233bce5ff5a9d20f54af80f6104303d6ca0 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sun, 18 Oct 2009 14:28:26 +0000 Subject: (svn r17800) -Codechange: first steps into making CargoList a template --- src/cargopacket.cpp | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'src/cargopacket.cpp') diff --git a/src/cargopacket.cpp b/src/cargopacket.cpp index ec42fe6b3..f37df719a 100644 --- a/src/cargopacket.cpp +++ b/src/cargopacket.cpp @@ -68,7 +68,8 @@ CargoPacket::CargoPacket(uint16 count, byte days_in_transit, Money feeder_share, * */ -CargoList::~CargoList() +template +CargoList::~CargoList() { while (!this->packets.empty()) { delete this->packets.front(); @@ -76,14 +77,16 @@ CargoList::~CargoList() } } -void CargoList::RemoveFromCache(const CargoPacket *cp) +template +void CargoList::RemoveFromCache(const CargoPacket *cp) { this->count -= cp->count; this->feeder_share -= cp->feeder_share; this->cargo_days_in_transit -= cp->days_in_transit * cp->count; } -void CargoList::AddToCache(const CargoPacket *cp) +template +void CargoList::AddToCache(const CargoPacket *cp) { this->count += cp->count; this->feeder_share += cp->feeder_share; @@ -101,7 +104,8 @@ void VehicleCargoList::AgeCargo() } } -void CargoList::Append(CargoPacket *cp) +template +void CargoList::Append(CargoPacket *cp) { assert(cp != NULL); @@ -123,7 +127,8 @@ void CargoList::Append(CargoPacket *cp) } -void CargoList::Truncate(uint max_remaining) +template +void CargoList::Truncate(uint max_remaining) { for (List::iterator it = packets.begin(); it != packets.end(); /* done during loop*/) { CargoPacket *cp = *it; @@ -149,7 +154,9 @@ void CargoList::Truncate(uint max_remaining) } } -bool CargoList::MoveTo(CargoList *dest, uint max_move, CargoList::MoveToAction mta, CargoPayment *payment, uint data) +template +template +bool CargoList::MoveTo(Tother_inst *dest, uint max_move, CargoList::MoveToAction mta, CargoPayment *payment, uint data) { assert(mta == MTA_FINAL_DELIVERY || dest != NULL); assert(mta == MTA_UNLOAD || mta == MTA_CARGO_LOAD || payment != NULL); @@ -228,7 +235,8 @@ bool CargoList::MoveTo(CargoList *dest, uint max_move, CargoList::MoveToAction m return it != packets.end(); } -void CargoList::InvalidateCache() +template +void CargoList::InvalidateCache() { this->count = 0; this->feeder_share = 0; @@ -238,3 +246,16 @@ void CargoList::InvalidateCache() this->AddToCache(*it); } } + +/* + * We have to instantiate everything we want to be usable. + */ +template class CargoList; +template class CargoList; + +/** Autoreplace Vehicle -> Vehicle 'transfer' */ +template bool CargoList::MoveTo(VehicleCargoList *, uint max_move, MoveToAction mta, CargoPayment *payment, uint data); +/** Cargo unloading at a station */ +template bool CargoList::MoveTo(StationCargoList *, uint max_move, MoveToAction mta, CargoPayment *payment, uint data); +/** Cargo loading at a station */ +template bool CargoList::MoveTo(VehicleCargoList *, uint max_move, MoveToAction mta, CargoPayment *payment, uint data); -- cgit v1.2.3-70-g09d2