A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add a MC version of the s4u-synchro-mutex test
[simgrid.git]
/
include
/
xbt
/
Extendable.hpp
diff --git
a/include/xbt/Extendable.hpp
b/include/xbt/Extendable.hpp
index
d95d186
..
195f287
100644
(file)
--- a/
include/xbt/Extendable.hpp
+++ b/
include/xbt/Extendable.hpp
@@
-1,4
+1,4
@@
-/* Copyright (c) 2015-20
19
. The SimGrid Team.
+/* Copyright (c) 2015-20
22
. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
@@
-7,6
+7,7
@@
#ifndef SIMGRID_XBT_LIB_HPP
#define SIMGRID_XBT_LIB_HPP
#ifndef SIMGRID_XBT_LIB_HPP
#define SIMGRID_XBT_LIB_HPP
+#include "xbt/base.h" // XBT_ATTRIB_DEPRECATED_v334
#include <cstddef>
#include <limits>
#include <vector>
#include <cstddef>
#include <limits>
#include <vector>
@@
-19,12
+20,12
@@
template<class T> class Extendable;
template<class T, class U>
class Extension {
template<class T, class U>
class Extension {
- static const std::size_t INVALID_ID = std::numeric_limits<std::size_t>::max();
- std::size_t id_;
+ static const
expr
std::size_t INVALID_ID = std::numeric_limits<std::size_t>::max();
+ std::size_t id_
= INVALID_ID
;
friend class Extendable<T>;
explicit constexpr Extension(std::size_t id) : id_(id) {}
public:
friend class Extendable<T>;
explicit constexpr Extension(std::size_t id) : id_(id) {}
public:
- explicit constexpr Extension()
: id_(INVALID_ID) {}
+ explicit constexpr Extension()
= default;
std::size_t id() const { return id_; }
bool valid() const { return id_ != INVALID_ID; }
};
std::size_t id() const { return id_; }
bool valid() const { return id_ != INVALID_ID; }
};
@@
-48,7
+49,8
@@
template<class T>
class Extendable {
private:
static std::vector<void(*)(void*)> deleters_;
class Extendable {
private:
static std::vector<void(*)(void*)> deleters_;
- std::vector<void*> extensions_;
+ std::vector<void*> extensions_{std::max<decltype(deleters_.size())>(1, deleters_.size()), nullptr};
+
public:
static size_t extension_create(void (*deleter)(void*))
{
public:
static size_t extension_create(void (*deleter)(void*))
{
@@
-68,7
+70,7
@@
public:
{
return Extension<T, U>(extension_create([](void* p) { delete static_cast<U*>(p); }));
}
{
return Extension<T, U>(extension_create([](void* p) { delete static_cast<U*>(p); }));
}
- Extendable()
: extensions_((deleters_.size() > 0 ? deleters_.size() : 1), nullptr) {}
+ Extendable()
= default;
Extendable(const Extendable&) = delete;
Extendable& operator=(const Extendable&) = delete;
~Extendable()
Extendable(const Extendable&) = delete;
Extendable& operator=(const Extendable&) = delete;
~Extendable()
@@
-110,10
+112,12
@@
public:
void set_data(void* data){
extensions_[0]=data;
}
void set_data(void* data){
extensions_[0]=data;
}
- void* get_data(){
- return extensions_[0];
+ template <typename D> D* get_data() const { return static_cast<D*>(extensions_[0]); }
+ XBT_ATTRIB_DEPRECATED_v334("Please use typed template Extendable::get_data<>()") void* get_data() const
+ {
+ return get_data<void>();
}
}
- // Convenience extension access when the type has a associated EXTENSION ID:
+ // Convenience extension access when the type has a
n
associated EXTENSION ID:
template <class U> U* extension() const { return extension<U>(U::EXTENSION_ID); }
template<class U> void extension_set(U* p) { extension_set<U>(U::EXTENSION_ID, p); }
};
template <class U> U* extension() const { return extension<U>(U::EXTENSION_ID); }
template<class U> void extension_set(U* p) { extension_set<U>(U::EXTENSION_ID, p); }
};