Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Cosmetics around std::unique_ptr.
[simgrid.git] / src / mc / remote / RemotePtr.hpp
index 88effca..5d13c42 100644 (file)
@@ -1,5 +1,4 @@
-/* Copyright (c) 2008-2015. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2008-2019. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -7,12 +6,7 @@
 #ifndef SIMGRID_MC_REMOTE_PTR_HPP
 #define SIMGRID_MC_REMOTE_PTR_HPP
 
-#include <cstddef>
-#include <cstdint>
-#include <cstring>
-
-#include <stdexcept>
-#include <type_traits>
+#include "src/simix/smx_private.hpp"
 
 namespace simgrid {
 namespace mc {
@@ -38,13 +32,16 @@ private:
   T buffer;
 
 public:
-  Remote() {}
-  ~Remote() {}
-  Remote(T& p) { std::memcpy(&buffer, &p, sizeof(buffer)); }
-  Remote(Remote const& that) { std::memcpy(&buffer, &that.buffer, sizeof(buffer)); }
+  Remote() { /* Nothing to do */}
+  ~Remote() { /* Nothing to do */}
+  Remote(T const& p) { std::memcpy(static_cast<void*>(&buffer), static_cast<const void*>(&p), sizeof(buffer)); }
+  Remote(Remote const& that)
+  {
+    std::memcpy(static_cast<void*>(&buffer), static_cast<const void*>(&that.buffer), sizeof(buffer));
+  }
   Remote& operator=(Remote const& that)
   {
-    std::memcpy(&buffer, &that.buffer, sizeof(buffer));
+    std::memcpy(static_cast<void*>(&buffer), static_cast<const void*>(&that.buffer), sizeof(buffer));
     return *this;
   }
   T* getBuffer() { return &buffer; }
@@ -78,9 +75,10 @@ template <class T> class RemotePtr {
 
 public:
   RemotePtr() : address_(0) {}
-  RemotePtr(std::uint64_t address) : address_(address) {}
-  RemotePtr(T* address) : address_((std::uintptr_t)address) {}
-  RemotePtr(Remote<T*> p) : RemotePtr(*p.getBuffer()) {}
+  explicit RemotePtr(std::nullptr_t) : address_(0) {}
+  explicit RemotePtr(std::uint64_t address) : address_(address) {}
+  explicit RemotePtr(T* address) : address_((std::uintptr_t)address) {}
+  explicit RemotePtr(Remote<T*> p) : address_((std::uintptr_t)*p.getBuffer()) {}
   std::uint64_t address() const { return address_; }
 
   /** Turn into a local pointer
@@ -89,8 +87,13 @@ public:
   T* local() const { return (T*)address_; }
 
   operator bool() const { return address_; }
-  bool operator!() const { return !address_; }
+  bool operator!() const { return not address_; }
   operator RemotePtr<void>() const { return RemotePtr<void>(address_); }
+  RemotePtr<T>& operator=(std::nullptr_t)
+  {
+    address_ = 0;
+    return *this;
+  }
   RemotePtr<T> operator+(std::uint64_t n) const { return RemotePtr<T>(address_ + n * sizeof(T)); }
   RemotePtr<T> operator-(std::uint64_t n) const { return RemotePtr<T>(address_ - n * sizeof(T)); }
   RemotePtr<T>& operator+=(std::uint64_t n)