shared_ptr -> std::shared_ptr
This is one of the first commits in a plan to remove all `using namespace std;` lines in the entire codebase as it is considered anti-pattern today.
This commit is contained in:
@@ -19,7 +19,7 @@ void SynchedEntityData::define(int id, int value)
|
||||
MemSect(17);
|
||||
checkId(id);
|
||||
int type = TYPE_INT;
|
||||
shared_ptr<DataItem> dataItem = shared_ptr<DataItem>( new DataItem(type, id, value) );
|
||||
std::shared_ptr<DataItem> dataItem = std::shared_ptr<DataItem>( new DataItem(type, id, value) );
|
||||
itemsById[id] = dataItem;
|
||||
MemSect(0);
|
||||
m_isEmpty = false;
|
||||
@@ -30,7 +30,7 @@ void SynchedEntityData::define(int id, byte value)
|
||||
MemSect(17);
|
||||
checkId(id);
|
||||
int type = TYPE_BYTE;
|
||||
shared_ptr<DataItem> dataItem = shared_ptr<DataItem>( new DataItem(type, id, value) );
|
||||
std::shared_ptr<DataItem> dataItem = std::shared_ptr<DataItem>( new DataItem(type, id, value) );
|
||||
itemsById[id] = dataItem;
|
||||
MemSect(0);
|
||||
m_isEmpty = false;
|
||||
@@ -41,7 +41,7 @@ void SynchedEntityData::define(int id, short value)
|
||||
MemSect(17);
|
||||
checkId(id);
|
||||
int type = TYPE_SHORT;
|
||||
shared_ptr<DataItem> dataItem = shared_ptr<DataItem>( new DataItem(type, id, value) );
|
||||
std::shared_ptr<DataItem> dataItem = std::shared_ptr<DataItem>( new DataItem(type, id, value) );
|
||||
itemsById[id] = dataItem;
|
||||
MemSect(0);
|
||||
m_isEmpty = false;
|
||||
@@ -52,7 +52,7 @@ void SynchedEntityData::define(int id, const wstring& value)
|
||||
MemSect(17);
|
||||
checkId(id);
|
||||
int type = TYPE_STRING;
|
||||
shared_ptr<DataItem> dataItem = shared_ptr<DataItem>( new DataItem(type, id, value) );
|
||||
std::shared_ptr<DataItem> dataItem = std::shared_ptr<DataItem>( new DataItem(type, id, value) );
|
||||
itemsById[id] = dataItem;
|
||||
MemSect(0);
|
||||
m_isEmpty = false;
|
||||
@@ -63,7 +63,7 @@ void SynchedEntityData::defineNULL(int id, void *pVal)
|
||||
MemSect(17);
|
||||
checkId(id);
|
||||
int type = TYPE_ITEMINSTANCE;
|
||||
shared_ptr<DataItem> dataItem = shared_ptr<DataItem>( new DataItem(type, id, shared_ptr<ItemInstance>()) );
|
||||
std::shared_ptr<DataItem> dataItem = std::shared_ptr<DataItem>( new DataItem(type, id, std::shared_ptr<ItemInstance>()) );
|
||||
itemsById[id] = dataItem;
|
||||
MemSect(0);
|
||||
m_isEmpty = false;
|
||||
@@ -109,7 +109,7 @@ wstring SynchedEntityData::getString(int id)
|
||||
return itemsById[id]->getValue_wstring();
|
||||
}
|
||||
|
||||
shared_ptr<ItemInstance> SynchedEntityData::getItemInstance(int id)
|
||||
std::shared_ptr<ItemInstance> SynchedEntityData::getItemInstance(int id)
|
||||
{
|
||||
//assert(false); // 4J - not currently implemented
|
||||
return itemsById[id]->getValue_itemInstance();
|
||||
@@ -123,7 +123,7 @@ Pos *SynchedEntityData::getPos(int id)
|
||||
|
||||
void SynchedEntityData::set(int id, int value)
|
||||
{
|
||||
shared_ptr<DataItem> dataItem = itemsById[id];
|
||||
std::shared_ptr<DataItem> dataItem = itemsById[id];
|
||||
|
||||
// update the value if it has changed
|
||||
if (value != dataItem->getValue_int())
|
||||
@@ -136,7 +136,7 @@ void SynchedEntityData::set(int id, int value)
|
||||
|
||||
void SynchedEntityData::set(int id, byte value)
|
||||
{
|
||||
shared_ptr<DataItem> dataItem = itemsById[id];
|
||||
std::shared_ptr<DataItem> dataItem = itemsById[id];
|
||||
|
||||
// update the value if it has changed
|
||||
if (value != dataItem->getValue_byte())
|
||||
@@ -149,7 +149,7 @@ void SynchedEntityData::set(int id, byte value)
|
||||
|
||||
void SynchedEntityData::set(int id, short value)
|
||||
{
|
||||
shared_ptr<DataItem> dataItem = itemsById[id];
|
||||
std::shared_ptr<DataItem> dataItem = itemsById[id];
|
||||
|
||||
// update the value if it has changed
|
||||
if (value != dataItem->getValue_short())
|
||||
@@ -162,7 +162,7 @@ void SynchedEntityData::set(int id, short value)
|
||||
|
||||
void SynchedEntityData::set(int id, const wstring& value)
|
||||
{
|
||||
shared_ptr<DataItem> dataItem = itemsById[id];
|
||||
std::shared_ptr<DataItem> dataItem = itemsById[id];
|
||||
|
||||
// update the value if it has changed
|
||||
if (value != dataItem->getValue_wstring())
|
||||
@@ -173,9 +173,9 @@ void SynchedEntityData::set(int id, const wstring& value)
|
||||
}
|
||||
}
|
||||
|
||||
void SynchedEntityData::set(int id, shared_ptr<ItemInstance> value)
|
||||
void SynchedEntityData::set(int id, std::shared_ptr<ItemInstance> value)
|
||||
{
|
||||
shared_ptr<DataItem> dataItem = itemsById[id];
|
||||
std::shared_ptr<DataItem> dataItem = itemsById[id];
|
||||
|
||||
// update the value if it has changed
|
||||
if (value != dataItem->getValue_itemInstance())
|
||||
@@ -197,7 +197,7 @@ bool SynchedEntityData::isDirty()
|
||||
return m_isDirty;
|
||||
}
|
||||
|
||||
void SynchedEntityData::pack(vector<shared_ptr<DataItem> > *items, DataOutputStream *output) // TODO throws IOException
|
||||
void SynchedEntityData::pack(vector<std::shared_ptr<DataItem> > *items, DataOutputStream *output) // TODO throws IOException
|
||||
{
|
||||
|
||||
if (items != NULL)
|
||||
@@ -205,7 +205,7 @@ void SynchedEntityData::pack(vector<shared_ptr<DataItem> > *items, DataOutputStr
|
||||
AUTO_VAR(itEnd, items->end());
|
||||
for (AUTO_VAR(it, items->begin()); it != itEnd; it++)
|
||||
{
|
||||
shared_ptr<DataItem> dataItem = *it;
|
||||
std::shared_ptr<DataItem> dataItem = *it;
|
||||
writeDataItem(output, dataItem);
|
||||
}
|
||||
}
|
||||
@@ -214,24 +214,24 @@ void SynchedEntityData::pack(vector<shared_ptr<DataItem> > *items, DataOutputStr
|
||||
output->writeByte(EOF_MARKER);
|
||||
}
|
||||
|
||||
vector<shared_ptr<SynchedEntityData::DataItem> > *SynchedEntityData::packDirty()
|
||||
vector<std::shared_ptr<SynchedEntityData::DataItem> > *SynchedEntityData::packDirty()
|
||||
{
|
||||
|
||||
vector<shared_ptr<DataItem> > *result = NULL;
|
||||
vector<std::shared_ptr<DataItem> > *result = NULL;
|
||||
|
||||
if (m_isDirty)
|
||||
{
|
||||
AUTO_VAR(itEnd, itemsById.end());
|
||||
for ( AUTO_VAR(it, itemsById.begin()); it != itEnd; it++ )
|
||||
{
|
||||
shared_ptr<DataItem> dataItem = (*it).second;
|
||||
std::shared_ptr<DataItem> dataItem = (*it).second;
|
||||
if (dataItem->isDirty())
|
||||
{
|
||||
dataItem->setDirty(false);
|
||||
|
||||
if (result == NULL)
|
||||
{
|
||||
result = new vector<shared_ptr<DataItem> >();
|
||||
result = new vector<std::shared_ptr<DataItem> >();
|
||||
}
|
||||
result->push_back(dataItem);
|
||||
}
|
||||
@@ -247,7 +247,7 @@ void SynchedEntityData::packAll(DataOutputStream *output) // throws IOException
|
||||
AUTO_VAR(itEnd, itemsById.end());
|
||||
for (AUTO_VAR(it, itemsById.begin()); it != itEnd; it++ )
|
||||
{
|
||||
shared_ptr<DataItem> dataItem = (*it).second;
|
||||
std::shared_ptr<DataItem> dataItem = (*it).second;
|
||||
writeDataItem(output, dataItem);
|
||||
}
|
||||
|
||||
@@ -255,18 +255,18 @@ void SynchedEntityData::packAll(DataOutputStream *output) // throws IOException
|
||||
output->writeByte(EOF_MARKER);
|
||||
}
|
||||
|
||||
vector<shared_ptr<SynchedEntityData::DataItem> > *SynchedEntityData::getAll()
|
||||
vector<std::shared_ptr<SynchedEntityData::DataItem> > *SynchedEntityData::getAll()
|
||||
{
|
||||
vector<shared_ptr<DataItem> > *result = NULL;
|
||||
vector<std::shared_ptr<DataItem> > *result = NULL;
|
||||
|
||||
AUTO_VAR(itEnd, itemsById.end());
|
||||
for (AUTO_VAR(it, itemsById.begin()); it != itEnd; it++ )
|
||||
{
|
||||
if (result == NULL)
|
||||
{
|
||||
result = new vector<shared_ptr<DataItem> >();
|
||||
result = new vector<std::shared_ptr<DataItem> >();
|
||||
}
|
||||
shared_ptr<DataItem> dataItem = (*it).second;
|
||||
std::shared_ptr<DataItem> dataItem = (*it).second;
|
||||
result->push_back(dataItem);
|
||||
}
|
||||
|
||||
@@ -274,7 +274,7 @@ vector<shared_ptr<SynchedEntityData::DataItem> > *SynchedEntityData::getAll()
|
||||
}
|
||||
|
||||
|
||||
void SynchedEntityData::writeDataItem(DataOutputStream *output, shared_ptr<DataItem> dataItem) //throws IOException
|
||||
void SynchedEntityData::writeDataItem(DataOutputStream *output, std::shared_ptr<DataItem> dataItem) //throws IOException
|
||||
{
|
||||
// pack type and id
|
||||
int header = ((dataItem->getType() << TYPE_SHIFT) | (dataItem->getId() & MAX_ID_VALUE)) & 0xff;
|
||||
@@ -285,7 +285,7 @@ void SynchedEntityData::writeDataItem(DataOutputStream *output, shared_ptr<DataI
|
||||
{
|
||||
case TYPE_BYTE:
|
||||
output->writeByte( dataItem->getValue_byte());
|
||||
break;
|
||||
break;
|
||||
case TYPE_INT:
|
||||
output->writeInt( dataItem->getValue_int());
|
||||
break;
|
||||
@@ -295,23 +295,23 @@ void SynchedEntityData::writeDataItem(DataOutputStream *output, shared_ptr<DataI
|
||||
case TYPE_STRING:
|
||||
Packet::writeUtf(dataItem->getValue_wstring(), output);
|
||||
break;
|
||||
case TYPE_ITEMINSTANCE:
|
||||
case TYPE_ITEMINSTANCE:
|
||||
{
|
||||
shared_ptr<ItemInstance> instance = (shared_ptr<ItemInstance> )dataItem->getValue_itemInstance();
|
||||
std::shared_ptr<ItemInstance> instance = (std::shared_ptr<ItemInstance> )dataItem->getValue_itemInstance();
|
||||
Packet::writeItem(instance, output);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
assert(false); // 4J - not implemented
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
vector<shared_ptr<SynchedEntityData::DataItem> > *SynchedEntityData::unpack(DataInputStream *input) //throws IOException
|
||||
vector<std::shared_ptr<SynchedEntityData::DataItem> > *SynchedEntityData::unpack(DataInputStream *input) //throws IOException
|
||||
{
|
||||
|
||||
vector<shared_ptr<DataItem> > *result = NULL;
|
||||
vector<std::shared_ptr<DataItem> > *result = NULL;
|
||||
|
||||
int currentHeader = input->readByte();
|
||||
|
||||
@@ -320,40 +320,40 @@ vector<shared_ptr<SynchedEntityData::DataItem> > *SynchedEntityData::unpack(Data
|
||||
|
||||
if (result == NULL)
|
||||
{
|
||||
result = new vector<shared_ptr<DataItem> >();
|
||||
result = new vector<std::shared_ptr<DataItem> >();
|
||||
}
|
||||
|
||||
// split type and id
|
||||
int itemType = (currentHeader & TYPE_MASK) >> TYPE_SHIFT;
|
||||
int itemId = (currentHeader & MAX_ID_VALUE);
|
||||
|
||||
shared_ptr<DataItem> item = shared_ptr<DataItem>();
|
||||
std::shared_ptr<DataItem> item = std::shared_ptr<DataItem>();
|
||||
switch (itemType)
|
||||
{
|
||||
case TYPE_BYTE:
|
||||
{
|
||||
byte dataRead = input->readByte();
|
||||
item = shared_ptr<DataItem>( new DataItem(itemType, itemId, dataRead) );
|
||||
item = std::shared_ptr<DataItem>( new DataItem(itemType, itemId, dataRead) );
|
||||
}
|
||||
break;
|
||||
case TYPE_SHORT:
|
||||
{
|
||||
short dataRead = input->readShort();
|
||||
item = shared_ptr<DataItem>( new DataItem(itemType, itemId, dataRead) );
|
||||
item = std::shared_ptr<DataItem>( new DataItem(itemType, itemId, dataRead) );
|
||||
}
|
||||
break;
|
||||
case TYPE_INT:
|
||||
{
|
||||
int dataRead = input->readInt();
|
||||
item = shared_ptr<DataItem>( new DataItem(itemType, itemId, dataRead) );
|
||||
item = std::shared_ptr<DataItem>( new DataItem(itemType, itemId, dataRead) );
|
||||
}
|
||||
break;
|
||||
case TYPE_STRING:
|
||||
item = shared_ptr<DataItem>( new DataItem(itemType, itemId, Packet::readUtf(input, MAX_STRING_DATA_LENGTH)) );
|
||||
item = std::shared_ptr<DataItem>( new DataItem(itemType, itemId, Packet::readUtf(input, MAX_STRING_DATA_LENGTH)) );
|
||||
break;
|
||||
case TYPE_ITEMINSTANCE:
|
||||
case TYPE_ITEMINSTANCE:
|
||||
{
|
||||
item = shared_ptr<DataItem>(new DataItem(itemType, itemId, Packet::readItem(input)));
|
||||
item = std::shared_ptr<DataItem>(new DataItem(itemType, itemId, Packet::readItem(input)));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -372,16 +372,16 @@ vector<shared_ptr<SynchedEntityData::DataItem> > *SynchedEntityData::unpack(Data
|
||||
|
||||
/**
|
||||
* Assigns values from a list of data items.
|
||||
*
|
||||
*
|
||||
* @param items
|
||||
*/
|
||||
|
||||
void SynchedEntityData::assignValues(vector<shared_ptr<DataItem> > *items)
|
||||
void SynchedEntityData::assignValues(vector<std::shared_ptr<DataItem> > *items)
|
||||
{
|
||||
AUTO_VAR(itEnd, items->end());
|
||||
for (AUTO_VAR(it, items->begin()); it != itEnd; it++)
|
||||
{
|
||||
shared_ptr<DataItem> item = *it;
|
||||
std::shared_ptr<DataItem> item = *it;
|
||||
AUTO_VAR(itemFromId, itemsById.find(item->getId()));
|
||||
if (itemFromId != itemsById.end() )
|
||||
{
|
||||
@@ -418,11 +418,11 @@ bool SynchedEntityData::isEmpty()
|
||||
int SynchedEntityData::getSizeInBytes()
|
||||
{
|
||||
int size = 1;
|
||||
|
||||
|
||||
AUTO_VAR(itEnd, itemsById.end());
|
||||
for (AUTO_VAR(it, itemsById.begin()); it != itEnd; it++ )
|
||||
{
|
||||
shared_ptr<DataItem> dataItem = (*it).second;
|
||||
std::shared_ptr<DataItem> dataItem = (*it).second;
|
||||
|
||||
size += 1;
|
||||
|
||||
@@ -431,7 +431,7 @@ int SynchedEntityData::getSizeInBytes()
|
||||
{
|
||||
case TYPE_BYTE:
|
||||
size += 1;
|
||||
break;
|
||||
break;
|
||||
case TYPE_SHORT:
|
||||
size += 2;
|
||||
break;
|
||||
@@ -481,7 +481,7 @@ SynchedEntityData::DataItem::DataItem(int type, int id, const wstring& value) :
|
||||
this->dirty = true;
|
||||
}
|
||||
|
||||
SynchedEntityData::DataItem::DataItem(int type, int id, shared_ptr<ItemInstance> itemInstance) : type( type ), id( id )
|
||||
SynchedEntityData::DataItem::DataItem(int type, int id, std::shared_ptr<ItemInstance> itemInstance) : type( type ), id( id )
|
||||
{
|
||||
this->value_itemInstance = itemInstance;
|
||||
this->dirty = true;
|
||||
@@ -512,7 +512,7 @@ void SynchedEntityData::DataItem::setValue(const wstring& value)
|
||||
this->value_wstring = value;
|
||||
}
|
||||
|
||||
void SynchedEntityData::DataItem::setValue(shared_ptr<ItemInstance> itemInstance)
|
||||
void SynchedEntityData::DataItem::setValue(std::shared_ptr<ItemInstance> itemInstance)
|
||||
{
|
||||
this->value_itemInstance = itemInstance;
|
||||
}
|
||||
@@ -537,7 +537,7 @@ wstring SynchedEntityData::DataItem::getValue_wstring()
|
||||
return value_wstring;
|
||||
}
|
||||
|
||||
shared_ptr<ItemInstance> SynchedEntityData::DataItem::getValue_itemInstance()
|
||||
std::shared_ptr<ItemInstance> SynchedEntityData::DataItem::getValue_itemInstance()
|
||||
{
|
||||
return value_itemInstance;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user