Use unique_ptr and initialiser init for OrderExtraInfo.

pull/155/head
Jonathan G Rennison 8 years ago
parent e90b266af1
commit f8f8e642dc

@ -21,6 +21,7 @@
#include "vehicle_type.h"
#include "date_type.h"
#include <memory>
#include <vector>
typedef Pool<Order, OrderID, 256, 64000> OrderPool;
@ -29,9 +30,7 @@ extern OrderPool _order_pool;
extern OrderListPool _orderlist_pool;
struct OrderExtraInfo {
uint8 cargo_type_flags[NUM_CARGO]; ///< Load/unload types for each cargo type.
OrderExtraInfo();
uint8 cargo_type_flags[NUM_CARGO] = {}; ///< Load/unload types for each cargo type.
};
/* If you change this, keep in mind that it is saved on 3 places:
@ -53,7 +52,7 @@ private:
CargoID refit_cargo; ///< Refit CargoID
OrderExtraInfo *extra;///< Extra order info
std::unique_ptr<OrderExtraInfo> extra; ///< Extra order info
uint16 wait_time; ///< How long in ticks to wait at the destination.
uint16 travel_time; ///< How long in ticks the journey to this destination should take.
@ -70,16 +69,18 @@ private:
public:
Order *next; ///< Pointer to next order. If NULL, end of list
Order() : refit_cargo(CT_NO_REFIT), extra(NULL), max_speed(UINT16_MAX) {}
Order() : refit_cargo(CT_NO_REFIT), max_speed(UINT16_MAX) {}
~Order();
Order(uint32 packed);
Order(const Order& other) : extra(NULL)
Order(const Order& other)
{
*this = other;
}
Order(Order&& other) = default;
inline Order& operator=(Order const& other)
{
AssignOrder(other);

@ -48,7 +48,6 @@ INSTANTIATE_POOL_METHODS(OrderList)
/** Clean everything up. */
Order::~Order()
{
DeAllocExtraInfo();
if (CleaningPool()) return;
/* We can visit oil rigs and buoys that are not our own. They will be shown in
@ -297,22 +296,14 @@ void Order::AssignOrder(const Order &other)
void Order::AllocExtraInfo()
{
if (this->extra == NULL) {
this->extra = new OrderExtraInfo();
if (!this->extra) {
this->extra.reset(new OrderExtraInfo());
}
}
void Order::DeAllocExtraInfo()
{
if (this->extra != NULL) {
delete this->extra;
this->extra = NULL;
}
}
OrderExtraInfo::OrderExtraInfo()
{
memset(cargo_type_flags, 0, sizeof(cargo_type_flags));
this->extra.reset();
}
void CargoStationIDStackSet::FillNextStoppingStation(const Vehicle *v, const OrderList *o, const Order *first, uint hops)

@ -209,9 +209,9 @@ void Save_ORDX()
Order *order;
FOR_ALL_ORDERS(order) {
if (order->extra != NULL) {
if (order->extra) {
SlSetArrayIndex(order->index);
SlObject(order->extra, GetOrderExtraInfoDescription());
SlObject(order->extra.get(), GetOrderExtraInfoDescription());
}
}
}
@ -223,7 +223,7 @@ void Load_ORDX()
Order *order = Order::GetIfValid(index);
assert(order != NULL);
order->AllocExtraInfo();
SlObject(order->extra, GetOrderExtraInfoDescription());
SlObject(order->extra.get(), GetOrderExtraInfoDescription());
}
}

Loading…
Cancel
Save