schmoozerd
29.08.2012, 01:41
Can somebody explain why we use return-by-reference to access object-fields?
const int32& GetInt32Value(uint16 index) const
{
MANGOS_ASSERT(index < m_valuesCount || PrintIndexError(index , false));
return m_int32Values[ index ];
}
const uint32& GetUInt32Value(uint16 index) const
{
MANGOS_ASSERT(index < m_valuesCount || PrintIndexError(index , false));
return m_uint32Values[ index ];
}
const uint64& GetUInt64Value(uint16 index) const
{
MANGOS_ASSERT(index + 1 < m_valuesCount || PrintIndexError(index , false));
return *((uint64*) & (m_uint32Values[ index ]));
}
const float& GetFloatValue(uint16 index) const
{
MANGOS_ASSERT(index < m_valuesCount || PrintIndexError(index , false));
return m_floatValues[ index ];
}
uint8 GetByteValue(uint16 index, uint8 offset) const
{
MANGOS_ASSERT(index < m_valuesCount || PrintIndexError(index , false));
MANGOS_ASSERT(offset < 4);
return *(((uint8*)&m_uint32Values[ index ]) + offset);
}
uint16 GetUInt16Value(uint16 index, uint8 offset) const
{
MANGOS_ASSERT(index < m_valuesCount || PrintIndexError(index , false));
MANGOS_ASSERT(offset < 2);
return *(((uint16*)&m_uint32Values[ index ]) + offset);
}
ObjectGuid const& GetGuidValue(uint16 index) const { return *reinterpret_cast<ObjectGuid const*>(&GetUInt64Value(index)); }
instead of normal return by value?
(Historical note: we do this since long forgotten times)
const int32& GetInt32Value(uint16 index) const
{
MANGOS_ASSERT(index < m_valuesCount || PrintIndexError(index , false));
return m_int32Values[ index ];
}
const uint32& GetUInt32Value(uint16 index) const
{
MANGOS_ASSERT(index < m_valuesCount || PrintIndexError(index , false));
return m_uint32Values[ index ];
}
const uint64& GetUInt64Value(uint16 index) const
{
MANGOS_ASSERT(index + 1 < m_valuesCount || PrintIndexError(index , false));
return *((uint64*) & (m_uint32Values[ index ]));
}
const float& GetFloatValue(uint16 index) const
{
MANGOS_ASSERT(index < m_valuesCount || PrintIndexError(index , false));
return m_floatValues[ index ];
}
uint8 GetByteValue(uint16 index, uint8 offset) const
{
MANGOS_ASSERT(index < m_valuesCount || PrintIndexError(index , false));
MANGOS_ASSERT(offset < 4);
return *(((uint8*)&m_uint32Values[ index ]) + offset);
}
uint16 GetUInt16Value(uint16 index, uint8 offset) const
{
MANGOS_ASSERT(index < m_valuesCount || PrintIndexError(index , false));
MANGOS_ASSERT(offset < 2);
return *(((uint16*)&m_uint32Values[ index ]) + offset);
}
ObjectGuid const& GetGuidValue(uint16 index) const { return *reinterpret_cast<ObjectGuid const*>(&GetUInt64Value(index)); }
instead of normal return by value?
(Historical note: we do this since long forgotten times)