X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/2807fde4fd1f59c230d69a934634c5dfb77905f2..4d648ebbbe5705878080b9cbf1ca61497323c592:/include/xbt/Extendable.hpp diff --git a/include/xbt/Extendable.hpp b/include/xbt/Extendable.hpp index 785e337546..37a7d41c59 100644 --- a/include/xbt/Extendable.hpp +++ b/include/xbt/Extendable.hpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2015, 2017. The SimGrid Team. +/* Copyright (c) 2015-2019. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -26,7 +26,7 @@ class Extension { public: explicit constexpr Extension() : id_(INVALID_ID) {} std::size_t id() const { return id_; } - bool valid() { return id_ != INVALID_ID; } + bool valid() const { return id_ != INVALID_ID; } }; /** An Extendable is an object that you can extend with external elements. @@ -67,6 +67,8 @@ public: return Extension(extension_create([](void* p) { delete static_cast(p); })); } Extendable() : extensions_(deleters_.size(), nullptr) {} + Extendable(const Extendable&) = delete; + Extendable& operator=(const Extendable&) = delete; ~Extendable() { /* Call destructors in reverse order of their registrations @@ -81,7 +83,7 @@ public: } // Type-unsafe versions of the facet access methods: - void* extension(std::size_t rank) + void* extension(std::size_t rank) const { if (rank >= extensions_.size()) return nullptr; @@ -99,11 +101,7 @@ public: } // Type safe versions of the facet access methods: - template - U* extension(Extension rank) - { - return static_cast(extension(rank.id())); - } + template U* extension(Extension rank) const { return static_cast(extension(rank.id())); } template void extension_set(Extension rank, U* value, bool use_dtor = true) { @@ -111,13 +109,11 @@ public: } // Convenience extension access when the type has a associated EXTENSION ID: - template U* extension() { return extension(U::EXTENSION_ID); } + template U* extension() const { return extension(U::EXTENSION_ID); } template void extension_set(U* p) { extension_set(U::EXTENSION_ID, p); } }; -template -std::vector Extendable::deleters_ = {}; - +template std::vector Extendable::deleters_; } }