Use unique_ptr and initialiser init for OrderExtraInfo.
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
#include "vehicle_type.h"
|
#include "vehicle_type.h"
|
||||||
#include "date_type.h"
|
#include "date_type.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
typedef Pool<Order, OrderID, 256, 64000> OrderPool;
|
typedef Pool<Order, OrderID, 256, 64000> OrderPool;
|
||||||
@@ -29,9 +30,7 @@ extern OrderPool _order_pool;
|
|||||||
extern OrderListPool _orderlist_pool;
|
extern OrderListPool _orderlist_pool;
|
||||||
|
|
||||||
struct OrderExtraInfo {
|
struct OrderExtraInfo {
|
||||||
uint8 cargo_type_flags[NUM_CARGO]; ///< Load/unload types for each cargo type.
|
uint8 cargo_type_flags[NUM_CARGO] = {}; ///< Load/unload types for each cargo type.
|
||||||
|
|
||||||
OrderExtraInfo();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* If you change this, keep in mind that it is saved on 3 places:
|
/* If you change this, keep in mind that it is saved on 3 places:
|
||||||
@@ -53,7 +52,7 @@ private:
|
|||||||
|
|
||||||
CargoID refit_cargo; ///< Refit CargoID
|
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 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.
|
uint16 travel_time; ///< How long in ticks the journey to this destination should take.
|
||||||
@@ -70,16 +69,18 @@ private:
|
|||||||
public:
|
public:
|
||||||
Order *next; ///< Pointer to next order. If NULL, end of list
|
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();
|
||||||
|
|
||||||
Order(uint32 packed);
|
Order(uint32 packed);
|
||||||
|
|
||||||
Order(const Order& other) : extra(NULL)
|
Order(const Order& other)
|
||||||
{
|
{
|
||||||
*this = other;
|
*this = other;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Order(Order&& other) = default;
|
||||||
|
|
||||||
inline Order& operator=(Order const& other)
|
inline Order& operator=(Order const& other)
|
||||||
{
|
{
|
||||||
AssignOrder(other);
|
AssignOrder(other);
|
||||||
|
@@ -48,7 +48,6 @@ INSTANTIATE_POOL_METHODS(OrderList)
|
|||||||
/** Clean everything up. */
|
/** Clean everything up. */
|
||||||
Order::~Order()
|
Order::~Order()
|
||||||
{
|
{
|
||||||
DeAllocExtraInfo();
|
|
||||||
if (CleaningPool()) return;
|
if (CleaningPool()) return;
|
||||||
|
|
||||||
/* We can visit oil rigs and buoys that are not our own. They will be shown in
|
/* 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()
|
void Order::AllocExtraInfo()
|
||||||
{
|
{
|
||||||
if (this->extra == NULL) {
|
if (!this->extra) {
|
||||||
this->extra = new OrderExtraInfo();
|
this->extra.reset(new OrderExtraInfo());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Order::DeAllocExtraInfo()
|
void Order::DeAllocExtraInfo()
|
||||||
{
|
{
|
||||||
if (this->extra != NULL) {
|
this->extra.reset();
|
||||||
delete this->extra;
|
|
||||||
this->extra = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
OrderExtraInfo::OrderExtraInfo()
|
|
||||||
{
|
|
||||||
memset(cargo_type_flags, 0, sizeof(cargo_type_flags));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CargoStationIDStackSet::FillNextStoppingStation(const Vehicle *v, const OrderList *o, const Order *first, uint hops)
|
void CargoStationIDStackSet::FillNextStoppingStation(const Vehicle *v, const OrderList *o, const Order *first, uint hops)
|
||||||
|
@@ -209,9 +209,9 @@ void Save_ORDX()
|
|||||||
Order *order;
|
Order *order;
|
||||||
|
|
||||||
FOR_ALL_ORDERS(order) {
|
FOR_ALL_ORDERS(order) {
|
||||||
if (order->extra != NULL) {
|
if (order->extra) {
|
||||||
SlSetArrayIndex(order->index);
|
SlSetArrayIndex(order->index);
|
||||||
SlObject(order->extra, GetOrderExtraInfoDescription());
|
SlObject(order->extra.get(), GetOrderExtraInfoDescription());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -223,7 +223,7 @@ void Load_ORDX()
|
|||||||
Order *order = Order::GetIfValid(index);
|
Order *order = Order::GetIfValid(index);
|
||||||
assert(order != NULL);
|
assert(order != NULL);
|
||||||
order->AllocExtraInfo();
|
order->AllocExtraInfo();
|
||||||
SlObject(order->extra, GetOrderExtraInfoDescription());
|
SlObject(order->extra.get(), GetOrderExtraInfoDescription());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user