Core/Misc: Use boost::in_place() to initialize optionals.

* Improves commit 800d5d8939
* Thanks @Shauren for this great suggestion.
This commit is contained in:
Naios
2015-04-27 17:01:30 +02:00
parent 5acc4b14aa
commit d37ecf796e
15 changed files with 28 additions and 27 deletions
@@ -1325,7 +1325,7 @@ void Battleground::BuildPvPLogDataPacket(WorldPackets::Battleground::PVPLogData&
playerData.Faction = score.second->TeamId;
if (score.second->HonorableKills || score.second->Deaths || score.second->BonusHonor)
{
playerData.Honor = WorldPackets::Battleground::PVPLogData::HonorData();
playerData.Honor = boost::in_place();
playerData.Honor->HonorKills = score.second->HonorableKills;
playerData.Honor->Deaths = score.second->Deaths;
playerData.Honor->ContributionPoints = score.second->BonusHonor;
@@ -1354,7 +1354,7 @@ void Battleground::BuildPvPLogDataPacket(WorldPackets::Battleground::PVPLogData&
if (isRated())
{
pvpLogData.Ratings = WorldPackets::Battleground::PVPLogData::RatingData();
pvpLogData.Ratings = boost::in_place();
for (uint8 i = 0; i < BG_TEAMS_COUNT; ++i)
{
+1 -1
View File
@@ -2155,7 +2155,7 @@ bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientati
transferPending.MapID = mapid;
if (Transport* transport = GetTransport())
{
transferPending.Ship = WorldPackets::Movement::TransferPending::ShipTransferPending();
transferPending.Ship = boost::in_place();
transferPending.Ship->ID = transport->GetEntry();
transferPending.Ship->OriginMapID = GetMapId();
}
+1 -1
View File
@@ -1313,7 +1313,7 @@ void Guild::SendQueryResponse(WorldSession* session)
{
WorldPackets::Guild::QueryGuildInfoResponse response;
response.GuildGuid = GetGUID();
response.Info = WorldPackets::Guild::QueryGuildInfoResponse::GuildInfo();
response.Info = boost::in_place();
response.Info->GuildGUID = GetGUID();
response.Info->VirtualRealmAddress = GetVirtualRealmAddress();
+3 -3
View File
@@ -28,13 +28,13 @@ void WorldSession::SendAuthResponse(uint8 code, bool queued, uint32 queuePos)
if (queued)
{
response.WaitInfo = WorldPackets::Auth::AuthResponse::AuthWaitInfo();
response.WaitInfo = boost::in_place();
response.WaitInfo->WaitCount = queuePos;
}
if (code == AUTH_OK)
{
response.SuccessInfo = WorldPackets::Auth::AuthResponse::AuthSuccessInfo();
response.SuccessInfo = boost::in_place();
response.SuccessInfo->AccountExpansionLevel = GetExpansion();
response.SuccessInfo->ActiveExpansionLevel = GetExpansion();
@@ -64,7 +64,7 @@ void WorldSession::SendAuthWaitQue(uint32 position)
response.Result = AUTH_OK;
else
{
response.WaitInfo = WorldPackets::Auth::AuthResponse::AuthWaitInfo();
response.WaitInfo = boost::in_place();
response.WaitInfo->WaitCount = position;
response.Result = AUTH_WAIT_QUEUE;
}
@@ -1135,7 +1135,7 @@ void WorldSession::SendFeatureSystemStatus()
features.VoiceEnabled = false;
features.BrowserEnabled = false; // Has to be false, otherwise client will crash if "Customer Support" is opened
features.EuropaTicketSystemStatus = WorldPackets::System::FeatureSystemStatus::EuropaTicketConfig();
features.EuropaTicketSystemStatus = boost::in_place();
features.EuropaTicketSystemStatus->ThrottleState.MaxTries = 10;
features.EuropaTicketSystemStatus->ThrottleState.PerMilliseconds = 60000;
features.EuropaTicketSystemStatus->ThrottleState.TryCount = 1;
@@ -2583,7 +2583,7 @@ void WorldSession::SendCharFactionChange(ResponseCodes result, WorldPackets::Cha
if (result == RESPONSE_SUCCESS)
{
packet.Display = WorldPackets::Character::CharFactionChangeResult::CharFactionChangeDisplayInfo();
packet.Display = boost::in_place();
packet.Display->Name = factionChangeInfo->Name;
packet.Display->SexID = factionChangeInfo->SexID;
packet.Display->SkinID = *factionChangeInfo->SkinID;
+1 -1
View File
@@ -65,7 +65,7 @@ void WorldSession::HandleInspectOpcode(WorldPackets::Inspect::Inspect& inspect)
if (Guild* guild = sGuildMgr->GetGuildById(player->GetGuildId()))
{
inspectResult.GuildData = WorldPackets::Inspect::InspectGuildData();
inspectResult.GuildData = boost::in_place();
inspectResult.GuildData->GuildGUID = guild->GetGUID();
inspectResult.GuildData->NumGuildMembers = guild->GetMembersCount();
inspectResult.GuildData->AchievementPoints = guild->GetAchievementMgr().GetAchievementPoints();
+1 -1
View File
@@ -69,7 +69,7 @@ void WorldSession::SendUpdateTrade(bool trader_data /*= true*/)
tradeItem.GiftCreator = item->GetGuidValue(ITEM_FIELD_GIFTCREATOR);
if (!item->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_WRAPPED))
{
tradeItem.Unwrapped = WorldPackets::Trade::TradeUpdated::UnwrappedTradeItem();
tradeItem.Unwrapped = boost::in_place();
tradeItem.Unwrapped->Item.Initialize(item);
tradeItem.Unwrapped->EnchantID = item->GetEnchantmentId(PERM_ENCHANTMENT_SLOT);
@@ -104,7 +104,7 @@ ByteBuffer& operator>>(ByteBuffer& data, Optional<WorldPackets::Item::ItemBonusI
{
uint32 bonusListIdSize;
itemBonusInstanceData = WorldPackets::Item::ItemBonusInstanceData();
itemBonusInstanceData = boost::in_place();
data >> itemBonusInstanceData->Context;
data >> bonusListIdSize;
@@ -180,7 +180,7 @@ void WorldPackets::Item::ItemInstance::Initialize(::Item const* item)
std::vector<uint32> const& bonusListIds = item->GetDynamicValues(ITEM_DYNAMIC_FIELD_BONUSLIST_IDS);
if (!bonusListIds.empty())
{
ItemBonus = WorldPackets::Item::ItemBonusInstanceData();
ItemBonus = boost::in_place();
ItemBonus->BonusListIDs.insert(ItemBonus->BonusListIDs.end(), bonusListIds.begin(), bonusListIds.end());
ItemBonus->Context = item->GetUInt32Value(ITEM_FIELD_CONTEXT);
}
@@ -203,7 +203,7 @@ void WorldPackets::Item::ItemInstance::Initialize(::LootItem const& lootItem)
RandomPropertiesID = lootItem.randomPropertyId;
if (!lootItem.BonusListIDs.empty())
{
ItemBonus = ItemBonusInstanceData();
ItemBonus = boost::in_place();
ItemBonus->BonusListIDs = lootItem.BonusListIDs;
ItemBonus->Context = 0; /// @todo
}
@@ -175,13 +175,13 @@ namespace WorldPackets
class TransferPending final : public ServerPacket
{
public:
struct ShipTransferPending
{
uint32 ID = 0; ///< gameobject_template.entry of the transport the player is teleporting on
int32 OriginMapID = -1; ///< Map id the player is currently on (before teleport)
};
public:
TransferPending() : ServerPacket(SMSG_TRANSFER_PENDING, 16) { }
WorldPacket const* Write() override;
@@ -143,7 +143,7 @@ WorldPacket const* WorldPackets::Spells::AuraUpdate::Write()
ByteBuffer& operator>>(ByteBuffer& buffer, Optional<WorldPackets::Spells::TargetLocation>& location)
{
location = WorldPackets::Spells::TargetLocation();
location = boost::in_place();
buffer >> location->Transport;
buffer >> location->Location.m_positionX;
buffer >> location->Location.m_positionY;
@@ -236,7 +236,7 @@ ByteBuffer& operator>>(ByteBuffer& data, WorldPackets::Ticket::SupportTicketSubm
ByteBuffer& operator>>(ByteBuffer& data, Optional<WorldPackets::Ticket::SupportTicketSubmitComplaint::SupportTicketMailInfo>& mail)
{
mail = WorldPackets::Ticket::SupportTicketSubmitComplaint::SupportTicketMailInfo();
mail = boost::in_place();
data >> mail->MailID;
uint16 bodyLength = data.ReadBits(13);
@@ -250,7 +250,7 @@ ByteBuffer& operator>>(ByteBuffer& data, Optional<WorldPackets::Ticket::SupportT
ByteBuffer& operator>>(ByteBuffer& data, Optional<WorldPackets::Ticket::SupportTicketSubmitComplaint::SupportTicketCalendarEventInfo>& event)
{
event = WorldPackets::Ticket::SupportTicketSubmitComplaint::SupportTicketCalendarEventInfo();
event = boost::in_place();
data >> event->EventID;
data >> event->InviteID;
uint8 titleLength = data.ReadBits(8);
@@ -262,7 +262,7 @@ ByteBuffer& operator>>(ByteBuffer& data, Optional<WorldPackets::Ticket::SupportT
ByteBuffer& operator>>(ByteBuffer& data, Optional<WorldPackets::Ticket::SupportTicketSubmitComplaint::SupportTicketPetInfo>& pet)
{
pet = WorldPackets::Ticket::SupportTicketSubmitComplaint::SupportTicketPetInfo();
pet = boost::in_place();
data >> pet->PetID;
uint8 nameLength = data.ReadBits(8);
@@ -273,7 +273,7 @@ ByteBuffer& operator>>(ByteBuffer& data, Optional<WorldPackets::Ticket::SupportT
ByteBuffer& operator>>(ByteBuffer& data, Optional<WorldPackets::Ticket::SupportTicketSubmitComplaint::SupportTicketGuildInfo>& guild)
{
guild = WorldPackets::Ticket::SupportTicketSubmitComplaint::SupportTicketGuildInfo();
guild = boost::in_place();
data >> guild->GuildID;
uint8 nameLength = data.ReadBits(8);
@@ -284,7 +284,7 @@ ByteBuffer& operator>>(ByteBuffer& data, Optional<WorldPackets::Ticket::SupportT
ByteBuffer& operator>>(ByteBuffer& data, Optional<WorldPackets::Ticket::SupportTicketSubmitComplaint::Struct5E4383>& str)
{
str = WorldPackets::Ticket::SupportTicketSubmitComplaint::Struct5E4383();
str = boost::in_place();
data >> str->RideTicket;
data >> str->_40;
data >> str->_56;
@@ -41,7 +41,7 @@ ByteBuffer& operator>>(ByteBuffer& data, WorldPackets::Who::WhoWord& word)
ByteBuffer& operator>>(ByteBuffer& data, Optional<WorldPackets::Who::WhoRequestServerInfo>& serverInfo)
{
serverInfo = WorldPackets::Who::WhoRequestServerInfo();
serverInfo = boost::in_place();
data >> serverInfo->FactionGroup;
data >> serverInfo->Locale;
+4 -4
View File
@@ -222,7 +222,7 @@ void SpellCastTargets::Write(WorldPackets::Spells::SpellTargetData& data)
if (m_targetMask & TARGET_FLAG_SOURCE_LOCATION)
{
data.SrcLocation = WorldPackets::Spells::TargetLocation();
data.SrcLocation = boost::in_place();
data.SrcLocation->Transport = m_src._transportGUID; // relative position guid here - transport for example
if (!m_src._transportGUID.IsEmpty())
data.SrcLocation->Location = m_src._transportOffset;
@@ -232,7 +232,7 @@ void SpellCastTargets::Write(WorldPackets::Spells::SpellTargetData& data)
if (m_targetMask & TARGET_FLAG_DEST_LOCATION)
{
data.DstLocation = WorldPackets::Spells::TargetLocation();
data.DstLocation = boost::in_place();
data.DstLocation->Transport = m_dst._transportGUID; // relative position guid here - transport for example
if (!m_dst._transportGUID.IsEmpty())
data.DstLocation->Location = m_dst._transportOffset;
@@ -3888,7 +3888,7 @@ void Spell::SendSpellStart()
if (castFlags & CAST_FLAG_RUNE_LIST) // rune cooldowns list
{
castData.RemainingRunes = WorldPackets::Spells::RuneData();
castData.RemainingRunes = boost::in_place();
//TODO: There is a crash caused by a spell with CAST_FLAG_RUNE_LIST casted by a creature
//The creature is the mover of a player, so HandleCastSpellOpcode uses it as the caster
@@ -4006,7 +4006,7 @@ void Spell::SendSpellGo()
if (castFlags & CAST_FLAG_RUNE_LIST) // rune cooldowns list
{
castData.RemainingRunes = WorldPackets::Spells::RuneData();
castData.RemainingRunes = boost::in_place();
//TODO: There is a crash caused by a spell with CAST_FLAG_RUNE_LIST casted by a creature
//The creature is the mover of a player, so HandleCastSpellOpcode uses it as the caster
+1 -1
View File
@@ -1056,7 +1056,7 @@ void SupportMgr::SendGmTicket(WorldSession* session, GmTicket* ticket) const
if (ticket)
{
response.Result = GMTICKET_STATUS_HASTEXT;
response.Info = WorldPackets::Ticket::GMTicketGetTicketResponse::GMTicketInfo();
response.Info = boost::in_place();
response.Info->TicketID = ticket->GetId();
response.Info->TicketDescription = ticket->GetDescription();
+1
View File
@@ -40,6 +40,7 @@
#include <algorithm>
#include <boost/optional.hpp>
#include <boost/utility/in_place_factory.hpp>
#include "Debugging/Errors.h"