change casts to c++ style
authorJosh Pelkey <jpelkey@gatech.edu>
Thu, 06 May 2010 14:55:16 -0400
changeset 6291 8b3cd8b4d560
parent 6290 e01b68222e60
child 6292 4e538cf92937
change casts to c++ style
src/common/buffer.cc
src/common/buffer.h
src/common/nix-vector.cc
src/common/nix-vector.h
src/common/packet-metadata.cc
src/common/packet-metadata.h
src/common/packet.cc
src/mpi/distributed-simulator-impl.cc
src/mpi/distributed-simulator-impl.h
src/mpi/mpi-interface.cc
--- a/src/common/buffer.cc	Thu May 06 14:21:20 2010 +0100
+++ b/src/common/buffer.cc	Thu May 06 14:55:16 2010 -0400
@@ -699,7 +699,7 @@
 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 @@
 }
 
 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 @@
   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 @@
   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);
--- a/src/common/buffer.h	Thu May 06 14:21:20 2010 +0100
+++ b/src/common/buffer.h	Thu May 06 14:55:16 2010 -0400
@@ -503,7 +503,7 @@
    * 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;
--- a/src/common/nix-vector.cc	Thu May 06 14:21:20 2010 +0100
+++ b/src/common/nix-vector.cc	Thu May 06 14:55:16 2010 -0400
@@ -287,10 +287,10 @@
 }
 
 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);
--- a/src/common/nix-vector.h	Thu May 06 14:21:20 2010 +0100
+++ b/src/common/nix-vector.h	Thu May 06 14:55:16 2010 -0400
@@ -125,7 +125,7 @@
      * 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
      *
--- a/src/common/packet-metadata.cc	Thu May 06 14:21:20 2010 +0100
+++ b/src/common/packet-metadata.cc	Thu May 06 14:55:16 2010 -0400
@@ -1113,7 +1113,7 @@
   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 @@
             {
               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 @@
       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 @@
                             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 @@
                              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 @@
                              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 @@
                              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 @@
                           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 @@
   
 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 @@
       return 0;
     }
   memcpy(&data, current, sizeof (uint64_t));
-  return current + sizeof (uint64_t);
+  return const_cast<uint8_t *> (current) + sizeof (uint64_t);
 }
 
 
--- a/src/common/packet-metadata.h	Thu May 06 14:21:20 2010 +0100
+++ b/src/common/packet-metadata.h	Thu May 06 14:55:16 2010 -0400
@@ -159,7 +159,7 @@
 
   // 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 @@
                             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. */
--- a/src/common/packet.cc	Thu May 06 14:21:20 2010 +0100
+++ b/src/common/packet.cc	Thu May 06 14:55:16 2010 -0400
@@ -132,7 +132,7 @@
      * 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 @@
      * 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 @@
      * 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::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 @@
 
       // 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 @@
 
       // 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 @@
 }
 
 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 @@
   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 @@
   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 
--- a/src/mpi/distributed-simulator-impl.cc	Thu May 06 14:21:20 2010 +0100
+++ b/src/mpi/distributed-simulator-impl.cc	Thu May 06 14:55:16 2010 -0400
@@ -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 @@
   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++;
--- a/src/mpi/distributed-simulator-impl.h	Thu May 06 14:21:20 2010 +0100
+++ b/src/mpi/distributed-simulator-impl.h	Thu May 06 14:55:16 2010 -0400
@@ -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;
--- a/src/mpi/mpi-interface.cc	Thu May 06 14:21:20 2010 +0100
+++ b/src/mpi/mpi-interface.cc	Thu May 06 14:55:16 2010 -0400
@@ -149,8 +149,8 @@
   // 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 @@
   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 @@
       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 @@
 
       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);