Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of framagit.org:simgrid/simgrid
[simgrid.git] / src / mc / remote / RemotePtr.hpp
index 6b367fd..b8dc09a 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2008-2019. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2008-2022. 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. */
@@ -6,11 +6,9 @@
 #ifndef SIMGRID_MC_REMOTE_PTR_HPP
 #define SIMGRID_MC_REMOTE_PTR_HPP
 
-#include "src/simix/smx_private.hpp"
-#include <type_traits>
+#include "src/kernel/actor/ActorImpl.hpp"
 
-namespace simgrid {
-namespace mc {
+namespace simgrid::mc {
 
 /** HACK, A value from another process
  *
@@ -28,19 +26,19 @@ namespace mc {
  */
 template <class T> class Remote {
 private:
-  typename std::aligned_storage<sizeof(T), alignof(T)>::type buffer;
+  typename std::aligned_storage_t<sizeof(T), alignof(T)> buffer;
 
 public:
   Remote() = default;
-  Remote(T const& p) { std::memcpy(&buffer, &p, sizeof buffer); }
+  explicit Remote(T const& p) { std::memcpy(&buffer, &p, sizeof buffer); }
 
-  T* getBuffer() { return reinterpret_cast<T*>(&buffer); }
-  const T* getBuffer() const { return reinterpret_cast<const T*>(&buffer); }
-  std::size_t getBufferSize() const { return sizeof(T); }
+  T* get_buffer() { return reinterpret_cast<T*>(&buffer); }
+  const T* get_buffer() const { return reinterpret_cast<const T*>(&buffer); }
+  std::size_t get_buffer_size() const { return sizeof(T); }
   operator T() const
   {
     static_assert(std::is_trivial<T>::value, "Cannot convert non trivial type");
-    return *getBuffer();
+    return *get_buffer();
   }
   void clear() { std::memset(&buffer, 0, sizeof buffer); }
 };
@@ -60,14 +58,14 @@ public:
  *  as a `uint64_t`.
  */
 template <class T> class RemotePtr {
-  std::uint64_t address_;
+  std::uint64_t address_ = 0;
 
 public:
-  RemotePtr() : address_(0) {}
-  explicit RemotePtr(std::nullptr_t) : address_(0) {}
+  RemotePtr() = default;
+  explicit RemotePtr(std::nullptr_t) {}
   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()) {}
+  explicit RemotePtr(Remote<T*> p) : address_((std::uintptr_t)*p.get_buffer()) {}
   std::uint64_t address() const { return address_; }
 
   /** Turn into a local pointer
@@ -136,7 +134,6 @@ template <class T = void> inline RemotePtr<T> remote(uint64_t p)
 {
   return RemotePtr<T>(p);
 }
-}
-}
+} // namespace simgrid::mc
 
 #endif