File indexing completed on 2025-01-18 10:10:27
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef roofit_roofitcore_RooFit_UniqueId_h
0014 #define roofit_roofitcore_RooFit_UniqueId_h
0015
0016 #include <atomic>
0017
0018 namespace RooFit {
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 template <class Class>
0039 struct UniqueId {
0040 public:
0041 using Value_t = unsigned long;
0042
0043
0044 UniqueId() : _val{++counter} {}
0045
0046
0047 UniqueId(const UniqueId &) = delete;
0048 UniqueId &operator=(const UniqueId &) = delete;
0049 UniqueId(UniqueId &&) = delete;
0050 UniqueId &operator=(UniqueId &&) = delete;
0051
0052 operator Value_t() const { return _val; }
0053
0054
0055
0056
0057
0058
0059 constexpr Value_t value() const { return _val; }
0060
0061 bool operator==(UniqueId const &other) const { return _val == other._val; }
0062 bool operator<(UniqueId const &other) const { return _val < other._val; }
0063
0064
0065 static UniqueId const &nullid()
0066 {
0067 static const UniqueId nid{nullval};
0068 return nid;
0069 }
0070
0071 static constexpr Value_t nullval = 0UL;
0072
0073 private:
0074 UniqueId(Value_t val) : _val{val} {}
0075
0076 Value_t _val;
0077
0078 static std::atomic<Value_t> counter;
0079 };
0080
0081 template <class Class>
0082 std::atomic<typename UniqueId<Class>::Value_t> UniqueId<Class>::counter{UniqueId<Class>::nullval};
0083
0084
0085
0086
0087 template <class Class,
0088 class UniqueId_t = std::remove_reference_t<decltype(std::declval<std::remove_pointer_t<Class>>().uniqueId())>>
0089 UniqueId_t const &getUniqueId(Class const *ptr)
0090 {
0091 return ptr ? ptr->uniqueId() : UniqueId_t::nullid();
0092 }
0093
0094 }
0095
0096 #endif