X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/63c371bbca5afccc4708761d83af6fc2443ca553..1d83468696010801d74f8bc1e8c30918ffebabac:/src/mc/remote/RemotePtr.hpp diff --git a/src/mc/remote/RemotePtr.hpp b/src/mc/remote/RemotePtr.hpp index 3622eac522..6288fd5d02 100644 --- a/src/mc/remote/RemotePtr.hpp +++ b/src/mc/remote/RemotePtr.hpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2008-2015. The SimGrid Team. +/* Copyright (c) 2008-2018. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -38,13 +38,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(&buffer), static_cast(&p), sizeof(buffer)); } + Remote(Remote const& that) + { + std::memcpy(static_cast(&buffer), static_cast(&that.buffer), sizeof(buffer)); + } Remote& operator=(Remote const& that) { - std::memcpy(&buffer, &that.buffer, sizeof(buffer)); + std::memcpy(static_cast(&buffer), static_cast(&that.buffer), sizeof(buffer)); return *this; } T* getBuffer() { return &buffer; } @@ -52,7 +55,8 @@ public: std::size_t getBufferSize() const { return sizeof(T); } operator T() const { - static_assert(std::is_trivial::value, "Cannot convert non trivial type"); +//FIXME: assert turned off because smpi:Request is not seen as "trivial". +// static_assert(std::is_trivial::value, "Cannot convert non trivial type"); return buffer; } void clear() { std::memset(static_cast(&buffer), 0, sizeof(T)); } @@ -77,9 +81,10 @@ template class RemotePtr { public: RemotePtr() : address_(0) {} - RemotePtr(std::uint64_t address) : address_(address) {} - RemotePtr(T* address) : address_((std::uintptr_t)address) {} - RemotePtr(Remote 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 p) : address_((std::uintptr_t)*p.getBuffer()) {} std::uint64_t address() const { return address_; } /** Turn into a local pointer @@ -88,8 +93,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() const { return RemotePtr(address_); } + RemotePtr& operator=(std::nullptr_t) + { + address_ = 0; + return *this; + } RemotePtr operator+(std::uint64_t n) const { return RemotePtr(address_ + n * sizeof(T)); } RemotePtr operator-(std::uint64_t n) const { return RemotePtr(address_ - n * sizeof(T)); } RemotePtr& operator+=(std::uint64_t n)