From 06018583d329aa44b6989f841b32538f1c46752b Mon Sep 17 00:00:00 2001 From: Josh Pelkey Date: Thu, 6 May 2010 14:55:16 -0400 Subject: [PATCH] change casts to c++ style --- src/common/buffer.cc | 14 ++++---- src/common/buffer.h | 2 +- src/common/nix-vector.cc | 4 +-- src/common/nix-vector.h | 2 +- src/common/packet-metadata.cc | 50 +++++++++++++-------------- src/common/packet-metadata.h | 18 +++++----- src/common/packet.cc | 20 +++++------ src/mpi/distributed-simulator-impl.cc | 4 +-- src/mpi/distributed-simulator-impl.h | 2 -- src/mpi/mpi-interface.cc | 18 +++++----- 10 files changed, 65 insertions(+), 69 deletions(-) diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 321291631..b764bd827 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -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 (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 (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 (const_cast (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 (const_cast (p)), dataEndLength); + p += (((dataEndLength+3)&(~3))/4); // Advance p, insuring 4 byte boundary sizeCheck -= ((dataEndLength+3)&(~3)); NS_ASSERT (sizeCheck == 0); diff --git a/src/common/buffer.h b/src/common/buffer.h index 56351debd..fe74d8d07 100644 --- a/src/common/buffer.h +++ b/src/common/buffer.h @@ -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; diff --git a/src/common/nix-vector.cc b/src/common/nix-vector.cc index 70be5feac..8d6415171 100644 --- a/src/common/nix-vector.cc +++ b/src/common/nix-vector.cc @@ -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); diff --git a/src/common/nix-vector.h b/src/common/nix-vector.h index 97527bd82..7f275ebfb 100644 --- a/src/common/nix-vector.h +++ b/src/common/nix-vector.h @@ -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 * diff --git a/src/common/packet-metadata.cc b/src/common/packet-metadata.cc index f402d9ab8..914282658 100644 --- a/src/common/packet-metadata.cc +++ b/src/common/packet-metadata.cc @@ -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 (buffer - start) << ", typeUid="<< item.typeUid << ", size="<= TimeStep (m_currentTs)); Scheduler::Event ev; ev.impl = event; - ev.key.m_ts = (uint64_t) tAbsolute.GetTimeStep (); + ev.key.m_ts = static_cast (tAbsolute.GetTimeStep ()); ev.key.m_context = GetContext (); ev.key.m_uid = m_uid; m_uid++; diff --git a/src/mpi/distributed-simulator-impl.h b/src/mpi/distributed-simulator-impl.h index d1d84168c..16b4522d9 100644 --- a/src/mpi/distributed-simulator-impl.h +++ b/src/mpi/distributed-simulator-impl.h @@ -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; diff --git a/src/mpi/mpi-interface.cc b/src/mpi/mpi-interface.cc index 03c9fa5ad..368ee1474 100644 --- a/src/mpi/mpi-interface.cc +++ b/src/mpi/mpi-interface.cc @@ -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 (&m_sid)); + MPI_Comm_size (MPI_COMM_WORLD, reinterpret_cast (&m_size)); m_enabled = true; m_initialized = true; // Post a non-blocking receive for all peers @@ -180,19 +180,19 @@ MpiInterface::SendPacket (Ptr 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 (buffer); *pTime++ = t; - uint32_t* pData = (uint32_t*)pTime; + uint32_t* pData = reinterpret_cast (pTime); *pData++ = node; *pData++ = dev; // Serialize the packet - p->Serialize ((uint8_t*)pData, serializedSize); + p->Serialize (reinterpret_cast (pData), serializedSize); // Find the system id for the destination node Ptr destNode = NodeList::GetNode (node); uint32_t nodeSysId = destNode->GetSystemId (); - MPI_Isend ((void*)i->GetBuffer (), serializedSize + 16, MPI_CHAR, nodeSysId, + MPI_Isend (reinterpret_cast (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 (m_pRxBuffers[index]); uint64_t nanoSeconds = *pTime++; - uint32_t* pData = (uint32_t*)pTime; + uint32_t* pData = reinterpret_cast (pTime); uint32_t node = *pData++; uint32_t dev = *pData++; @@ -230,7 +230,7 @@ MpiInterface::ReceiveMessages () count -= sizeof (nanoSeconds) + sizeof (node) + sizeof (dev); - Ptr p = Create ((uint8_t*)pData, count, true); + Ptr p = Create (reinterpret_cast (pData), count, true); // Find the correct node/device to schedule receive event Ptr pNode = NodeList::GetNode (node);