change casts to c++ style

This commit is contained in:
Josh Pelkey
2010-05-06 14:55:16 -04:00
parent ce0dabd900
commit 06018583d3
10 changed files with 65 additions and 69 deletions

View File

@@ -699,7 +699,7 @@ Buffer::GetSerializedSize (void) const
uint32_t
Buffer::Serialize (uint8_t* buffer, uint32_t maxSize) const
{
uint32_t* p = (uint32_t*)buffer;
uint32_t* p = reinterpret_cast<uint32_t *> (buffer);
uint32_t size = 0;
NS_LOG_FUNCTION (this);
@@ -768,9 +768,9 @@ Buffer::Serialize (uint8_t* buffer, uint32_t maxSize) const
}
uint32_t
Buffer::Deserialize (uint8_t *buffer, uint32_t size)
Buffer::Deserialize (const uint8_t *buffer, uint32_t size)
{
uint32_t* p = (uint32_t*)buffer;
const uint32_t* p = reinterpret_cast<const uint32_t *> (buffer);
uint32_t sizeCheck = size-4;
NS_ASSERT (sizeCheck >= 4);
@@ -787,8 +787,8 @@ Buffer::Deserialize (uint8_t *buffer, uint32_t size)
AddAtStart (dataStartLength);
NS_ASSERT (sizeCheck >= dataStartLength);
Begin ().Write ((uint8_t*)p, dataStartLength);
p += (((dataStartLength+3)&(~3))/4);
Begin ().Write (reinterpret_cast<uint8_t *> (const_cast<uint32_t *> (p)), dataStartLength);
p += (((dataStartLength+3)&(~3))/4); // Advance p, insuring 4 byte boundary
sizeCheck -= ((dataStartLength+3)&(~3));
// Add end data
@@ -800,8 +800,8 @@ Buffer::Deserialize (uint8_t *buffer, uint32_t size)
NS_ASSERT (sizeCheck >= dataEndLength);
Buffer::Iterator tmp = End ();
tmp.Prev (dataEndLength);
tmp.Write ((uint8_t*)p, dataEndLength);
p += (((dataEndLength+3)&(~3))/4);
tmp.Write (reinterpret_cast<uint8_t *> (const_cast<uint32_t *> (p)), dataEndLength);
p += (((dataEndLength+3)&(~3))/4); // Advance p, insuring 4 byte boundary
sizeCheck -= ((dataEndLength+3)&(~3));
NS_ASSERT (sizeCheck == 0);

View File

@@ -503,7 +503,7 @@ public:
* The raw character buffer is deserialized and all the
* data is placed into this buffer.
*/
uint32_t Deserialize (uint8_t* buffer, uint32_t size);
uint32_t Deserialize (const uint8_t* buffer, uint32_t size);
int32_t GetCurrentStartOffset (void) const;
int32_t GetCurrentEndOffset (void) const;

View File

@@ -287,10 +287,10 @@ NixVector::Serialize (uint32_t* buffer, uint32_t maxSize) const
}
uint32_t
NixVector::Deserialize (uint32_t* buffer, uint32_t size)
NixVector::Deserialize (const uint32_t* buffer, uint32_t size)
{
NS_LOG_FUNCTION (this);
uint32_t* p = buffer;
const uint32_t* p = buffer;
uint32_t sizeCheck = size - 4;
NS_ASSERT (sizeCheck >= 4);

View File

@@ -125,7 +125,7 @@ class NixVector : public Object
* The raw character buffer containing all the nix-vector
* information is deserialized into this nix-vector.
*/
uint32_t Deserialize (uint32_t* buffer, uint32_t size);
uint32_t Deserialize (const uint32_t* buffer, uint32_t size);
/**
* \return number of bits of numberOfNeighbors
*

View File

@@ -1113,7 +1113,7 @@ PacketMetadata::Serialize (uint8_t* buffer, uint32_t maxSize) const
while (current != 0xffff)
{
ReadItems (current, &item, &extraItem);
NS_LOG_LOGIC ("bytesWritten=" << (uint32_t)(buffer - start) << ", typeUid="<<
NS_LOG_LOGIC ("bytesWritten=" << static_cast<uint32_t> (buffer - start) << ", typeUid="<<
item.typeUid << ", size="<<item.size<<", chunkUid="<<item.chunkUid<<
", fragmentStart="<<extraItem.fragmentStart<<", fragmentEnd="<<
extraItem.fragmentEnd<< ", packetUid="<<extraItem.packetUid);
@@ -1130,7 +1130,7 @@ PacketMetadata::Serialize (uint8_t* buffer, uint32_t maxSize) const
{
return 0;
}
buffer = AddToRaw ((uint8_t *)uidString.c_str (),
buffer = AddToRaw (reinterpret_cast<const uint8_t *> (uidString.c_str ()),
uidStringSize, start, buffer, maxSize);
if (buffer == 0)
{
@@ -1192,15 +1192,15 @@ PacketMetadata::Serialize (uint8_t* buffer, uint32_t maxSize) const
current = item.next;
}
NS_ASSERT ((uint32_t)(buffer - start) == maxSize);
NS_ASSERT (static_cast<uint32_t> (buffer - start) == maxSize);
return 1;
}
uint32_t
PacketMetadata::Deserialize (uint8_t* buffer, uint32_t size)
PacketMetadata::Deserialize (const uint8_t* buffer, uint32_t size)
{
NS_LOG_FUNCTION (this);
uint8_t* start = buffer;
const uint8_t* start = buffer;
uint32_t desSize = size - 4;
buffer = ReadFromRawU64 (m_packetUid, start, buffer, size);
@@ -1264,7 +1264,7 @@ PacketMetadata::AddToRawU8 (const uint8_t& data,
uint32_t maxSize)
{
// First check buffer overflow
if ((uint32_t)((current + sizeof (uint8_t) - start)) > maxSize)
if (static_cast<uint32_t> ((current + sizeof (uint8_t) - start)) > maxSize)
{
return 0;
}
@@ -1279,7 +1279,7 @@ PacketMetadata::AddToRawU16 (const uint16_t& data,
uint32_t maxSize)
{
// First check buffer overflow
if ((uint32_t)((current + sizeof (uint16_t) - start)) > maxSize)
if (static_cast<uint32_t> ((current + sizeof (uint16_t) - start)) > maxSize)
{
return 0;
}
@@ -1294,7 +1294,7 @@ PacketMetadata::AddToRawU32 (const uint32_t& data,
uint32_t maxSize)
{
// First check buffer overflow
if ((uint32_t)((current + sizeof (uint32_t) - start)) > maxSize)
if (static_cast<uint32_t> ((current + sizeof (uint32_t) - start)) > maxSize)
{
return 0;
}
@@ -1309,7 +1309,7 @@ PacketMetadata::AddToRawU64 (const uint64_t& data,
uint32_t maxSize)
{
// First check buffer overflow
if ((uint32_t)((current + sizeof (uint64_t) - start)) > maxSize)
if (static_cast<uint32_t> ((current + sizeof (uint64_t) - start)) > maxSize)
{
return 0;
}
@@ -1325,7 +1325,7 @@ PacketMetadata::AddToRaw (const uint8_t* data,
uint32_t maxSize)
{
// First check buffer overflow
if ((uint32_t)((current + dataSize - start)) > maxSize)
if (static_cast<uint32_t> ((current + dataSize - start)) > maxSize)
{
return 0;
}
@@ -1335,53 +1335,53 @@ PacketMetadata::AddToRaw (const uint8_t* data,
uint8_t*
PacketMetadata::ReadFromRawU8 (uint8_t& data,
uint8_t* start,
uint8_t* current,
const uint8_t* start,
const uint8_t* current,
uint32_t maxSize)
{
// First check buffer underflow
if ((uint32_t)((current + sizeof (uint8_t) - start)) > maxSize)
if (static_cast<uint32_t> ((current + sizeof (uint8_t) - start)) > maxSize)
{
return 0;
}
memcpy(&data, current, sizeof (uint8_t));
return current + sizeof (uint8_t);
return const_cast<uint8_t *> (current) + sizeof (uint8_t);
}
uint8_t*
PacketMetadata::ReadFromRawU16 (uint16_t& data,
uint8_t* start,
uint8_t* current,
const uint8_t* start,
const uint8_t* current,
uint32_t maxSize)
{
// First check buffer underflow
if ((uint32_t)((current + sizeof (uint16_t) - start)) > maxSize)
if (static_cast<uint32_t> ((current + sizeof (uint16_t) - start)) > maxSize)
{
return 0;
}
memcpy(&data, current, sizeof (uint16_t));
return current + sizeof (uint16_t);
return const_cast<uint8_t *> (current) + sizeof (uint16_t);
}
uint8_t*
PacketMetadata::ReadFromRawU32 (uint32_t& data,
uint8_t* start,
uint8_t* current,
const uint8_t* start,
const uint8_t* current,
uint32_t maxSize)
{
// First check buffer underflow
if ((uint32_t)((current + sizeof (uint32_t) - start)) > maxSize)
if (static_cast<uint32_t> ((current + sizeof (uint32_t) - start)) > maxSize)
{
return 0;
}
memcpy(&data, current, sizeof (uint32_t));
return current + sizeof (uint32_t);
return const_cast<uint8_t *> (current) + sizeof (uint32_t);
}
uint8_t*
PacketMetadata::ReadFromRawU64 (uint64_t& data,
uint8_t* start,
uint8_t* current,
const uint8_t* start,
const uint8_t* current,
uint32_t maxSize)
{
// First check buffer underflow
@@ -1390,7 +1390,7 @@ PacketMetadata::ReadFromRawU64 (uint64_t& data,
return 0;
}
memcpy(&data, current, sizeof (uint64_t));
return current + sizeof (uint64_t);
return const_cast<uint8_t *> (current) + sizeof (uint64_t);
}

View File

@@ -159,7 +159,7 @@ public:
// Serialization to/from raw uint8_t*
uint32_t Serialize (uint8_t* buffer, uint32_t maxSize) const;
uint32_t Deserialize (uint8_t* buffer, uint32_t size);
uint32_t Deserialize (const uint8_t* buffer, uint32_t size);
private:
// Helper for the raw serilization/deserialization
@@ -190,23 +190,23 @@ private:
uint32_t maxSize);
static uint8_t* ReadFromRawU8 (uint8_t& data,
uint8_t* start,
uint8_t* current,
const uint8_t* start,
const uint8_t* current,
uint32_t maxSize);
static uint8_t* ReadFromRawU16 (uint16_t& data,
uint8_t* start,
uint8_t* current,
const uint8_t* start,
const uint8_t* current,
uint32_t maxSize);
static uint8_t* ReadFromRawU32 (uint32_t& data,
uint8_t* start,
uint8_t* current,
const uint8_t* start,
const uint8_t* current,
uint32_t maxSize);
static uint8_t* ReadFromRawU64 (uint64_t& data,
uint8_t* start,
uint8_t* current,
const uint8_t* start,
const uint8_t* current,
uint32_t maxSize);
struct Data {
/* number of references to this struct Data instance. */

View File

@@ -132,7 +132,7 @@ Packet::Packet ()
* zero. The lower 32 bits are for the
* global UID
*/
m_metadata ((uint64_t)Simulator::GetSystemId () << 32 | m_globalUid, 0),
m_metadata (static_cast<uint64_t> (Simulator::GetSystemId ()) << 32 | m_globalUid, 0),
m_nixVector (0)
{
m_globalUid++;
@@ -174,7 +174,7 @@ Packet::Packet (uint32_t size)
* zero. The lower 32 bits are for the
* global UID
*/
m_metadata ((uint64_t)Simulator::GetSystemId () << 32 | m_globalUid, size),
m_metadata (static_cast<uint64_t> (Simulator::GetSystemId ()) << 32 | m_globalUid, size),
m_nixVector (0)
{
m_globalUid++;
@@ -200,7 +200,7 @@ Packet::Packet (uint8_t const*buffer, uint32_t size)
* zero. The lower 32 bits are for the
* global UID
*/
m_metadata ((uint64_t)Simulator::GetSystemId () << 32 | m_globalUid, size),
m_metadata (static_cast<uint64_t> (Simulator::GetSystemId ()) << 32 | m_globalUid, size),
m_nixVector (0)
{
m_globalUid++;
@@ -601,7 +601,7 @@ uint32_t Packet::GetSerializedSize (void) const
uint32_t
Packet::Serialize (uint8_t* buffer, uint32_t maxSize) const
{
uint32_t* p = (uint32_t*)buffer;
uint32_t* p = reinterpret_cast<uint32_t *> (buffer);
uint32_t size = 0;
// if nix-vector exists, serialize it
@@ -666,7 +666,7 @@ Packet::Serialize (uint8_t* buffer, uint32_t maxSize) const
// serialize the metadata
uint32_t serialized =
m_metadata.Serialize ((uint8_t*)p, metaSize);
m_metadata.Serialize (reinterpret_cast<uint8_t *> (p), metaSize);
if (serialized)
{
// increment p by metaSize bytes
@@ -695,7 +695,7 @@ Packet::Serialize (uint8_t* buffer, uint32_t maxSize) const
// serialize the buffer
uint32_t serialized =
m_buffer.Serialize ((uint8_t*)p, bufSize);
m_buffer.Serialize (reinterpret_cast<uint8_t *> (p), bufSize);
if (serialized)
{
// increment p by bufSize bytes
@@ -717,11 +717,11 @@ Packet::Serialize (uint8_t* buffer, uint32_t maxSize) const
}
uint32_t
Packet::Deserialize (uint8_t const*buffer, uint32_t size)
Packet::Deserialize (const uint8_t* buffer, uint32_t size)
{
NS_LOG_FUNCTION (this);
uint32_t* p = (uint32_t*)buffer;
const uint32_t* p = reinterpret_cast<const uint32_t *> (buffer);
// read nix-vector
NS_ASSERT (!m_nixVector);
@@ -762,7 +762,7 @@ Packet::Deserialize (uint8_t const*buffer, uint32_t size)
NS_ASSERT (size >= 0);
uint32_t metadataDeserialized =
m_metadata.Deserialize ((uint8_t*)p, metaSize);
m_metadata.Deserialize (reinterpret_cast<const uint8_t *> (p), metaSize);
if (!metadataDeserialized)
{
// meta-data not deserialized
@@ -782,7 +782,7 @@ Packet::Deserialize (uint8_t const*buffer, uint32_t size)
NS_ASSERT (size >= 0);
uint32_t bufferDeserialized =
m_buffer.Deserialize ((uint8_t*)p, bufSize);
m_buffer.Deserialize (reinterpret_cast<const uint8_t *> (p), bufSize);
if (!bufferDeserialized)
{
// buffer not deserialized

View File

@@ -1,7 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005,2006 INRIA
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
@@ -362,7 +360,7 @@ DistributedSimulatorImpl::Schedule (Time const &time, EventImpl *event)
NS_ASSERT (tAbsolute >= TimeStep (m_currentTs));
Scheduler::Event ev;
ev.impl = event;
ev.key.m_ts = (uint64_t) tAbsolute.GetTimeStep ();
ev.key.m_ts = static_cast<uint64_t> (tAbsolute.GetTimeStep ());
ev.key.m_context = GetContext ();
ev.key.m_uid = m_uid;
m_uid++;

View File

@@ -1,7 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005,2006 INRIA
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;

View File

@@ -149,8 +149,8 @@ MpiInterface::Enable (int* pargc, char*** pargv)
// Initialize the MPI interface
MPI_Init (pargc, pargv);
MPI_Barrier (MPI_COMM_WORLD);
MPI_Comm_rank (MPI_COMM_WORLD, (int*)&m_sid);
MPI_Comm_size (MPI_COMM_WORLD, (int*)&m_size);
MPI_Comm_rank (MPI_COMM_WORLD, reinterpret_cast <int *> (&m_sid));
MPI_Comm_size (MPI_COMM_WORLD, reinterpret_cast <int *> (&m_size));
m_enabled = true;
m_initialized = true;
// Post a non-blocking receive for all peers
@@ -180,19 +180,19 @@ MpiInterface::SendPacket (Ptr<Packet> p, const Time& rxTime, uint32_t node, uint
i->SetBuffer (buffer);
// Add the time, dest node and dest device
uint64_t t = rxTime.GetNanoSeconds ();
uint64_t* pTime = (uint64_t*)buffer;
uint64_t* pTime = reinterpret_cast <uint64_t *> (buffer);
*pTime++ = t;
uint32_t* pData = (uint32_t*)pTime;
uint32_t* pData = reinterpret_cast<uint32_t *> (pTime);
*pData++ = node;
*pData++ = dev;
// Serialize the packet
p->Serialize ((uint8_t*)pData, serializedSize);
p->Serialize (reinterpret_cast<uint8_t *> (pData), serializedSize);
// Find the system id for the destination node
Ptr<Node> destNode = NodeList::GetNode (node);
uint32_t nodeSysId = destNode->GetSystemId ();
MPI_Isend ((void*)i->GetBuffer (), serializedSize + 16, MPI_CHAR, nodeSysId,
MPI_Isend (reinterpret_cast<void *> (i->GetBuffer ()), serializedSize + 16, MPI_CHAR, nodeSysId,
0, MPI_COMM_WORLD, (i->GetRequest ()));
m_txCount++;
#else
@@ -220,9 +220,9 @@ MpiInterface::ReceiveMessages ()
m_rxCount++; // Count this receive
// Get the meta data first
uint64_t* pTime = (uint64_t*)m_pRxBuffers[index];
uint64_t* pTime = reinterpret_cast<uint64_t *> (m_pRxBuffers[index]);
uint64_t nanoSeconds = *pTime++;
uint32_t* pData = (uint32_t*)pTime;
uint32_t* pData = reinterpret_cast<uint32_t *> (pTime);
uint32_t node = *pData++;
uint32_t dev = *pData++;
@@ -230,7 +230,7 @@ MpiInterface::ReceiveMessages ()
count -= sizeof (nanoSeconds) + sizeof (node) + sizeof (dev);
Ptr<Packet> p = Create<Packet> ((uint8_t*)pData, count, true);
Ptr<Packet> p = Create<Packet> (reinterpret_cast<uint8_t *> (pData), count, true);
// Find the correct node/device to schedule receive event
Ptr<Node> pNode = NodeList::GetNode (node);