X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/34bbb917a7967e63d8eaa841cdb79f3c711f7ecc..4634214e18b847f6346048fa12179d3d99ae82c9:/include/xbt/Extendable.hpp diff --git a/include/xbt/Extendable.hpp b/include/xbt/Extendable.hpp index fd4f59adea..0f51c234f2 100644 --- a/include/xbt/Extendable.hpp +++ b/include/xbt/Extendable.hpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2015. The SimGrid Team. +/* Copyright (c) 2015-2018. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -22,9 +22,9 @@ class Extension { static const std::size_t INVALID_ID = std::numeric_limits::max(); std::size_t id_; friend class Extendable; - constexpr Extension(std::size_t id) : id_(id) {} + explicit constexpr Extension(std::size_t id) : id_(id) {} public: - constexpr Extension() : id_(INVALID_ID) {} + explicit constexpr Extension() : id_(INVALID_ID) {} std::size_t id() const { return id_; } bool valid() { return id_ != INVALID_ID; } }; @@ -41,14 +41,13 @@ public: * with a notion of Host extended with another concept (such as mobility). * You could completely externalize these data with an associative map Host->EnergyHost. * It would work, provided that you implement this classical feature correctly (and it would induce a little performance penalty). - * Instead, you should add a new facet to the Host class, that happens to be Facetable. + * Instead, you should add a new extension to the Host class, that happens to be Extendable. * */ template class Extendable { private: static std::vector deleters_; -protected: std::vector extensions_; public: static size_t extension_create(void (*deleter)(void*)) @@ -65,7 +64,7 @@ public: template static Extension extension_create() { - return extension_create([](void* p){ delete static_cast(p); }); + return Extension(extension_create([](void* p) { delete static_cast(p); })); } Extendable() : extensions_(deleters_.size(), nullptr) {} ~Extendable() @@ -77,7 +76,7 @@ public: * an extension of B might need to have the extension of A around when executing * its cleanup function/destructor. */ for (std::size_t i = extensions_.size(); i > 0; --i) - if (extensions_[i - 1] != nullptr) + if (extensions_[i - 1] != nullptr && deleters_[i - 1] != nullptr) deleters_[i - 1](extensions_[i - 1]); } @@ -111,7 +110,6 @@ public: extension_set(rank.id(), value, use_dtor); } -public: // Convenience extension access when the type has a associated EXTENSION ID: template U* extension() { return extension(U::EXTENSION_ID); } template void extension_set(U* p) { extension_set(U::EXTENSION_ID, p); }