ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
TransferElementID.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3#pragma once
4
5#include <cstddef>
6#include <functional>
7#include <iosfwd>
8
9namespace ChimeraTK {
10
11 /********************************************************************************************************************/
12
18 public:
22 TransferElementID() = default;
23
27 TransferElementID(const TransferElementID& other) = default;
28
32 bool operator==(const TransferElementID& other) const { return (_id != 0) && (_id == other._id); }
33 bool operator!=(const TransferElementID& other) const { return !(operator==(other)); }
34
36 [[nodiscard]] bool isValid() const { return _id != 0; }
37
40
41 protected:
45 void makeUnique();
46
48 size_t _id{0};
49
50 // Hash function for putting TransferElement::ID e.g. into an std::unordered_map
51 friend struct std::hash<TransferElementID>;
52
53 // Comparison for putting TransferElement::ID e.g. into an std::map
54 friend struct std::less<TransferElementID>;
55
56 friend std::ostream& operator<<(std::ostream& os, const TransferElementID& me);
57 friend class TransferElement;
58 };
59
60 /********************************************************************************************************************/
61
65 std::ostream& operator<<(std::ostream& os, const TransferElementID& me);
66
67 /********************************************************************************************************************/
68
69} // namespace ChimeraTK
70
71namespace std {
72
73 /********************************************************************************************************************/
74
77 template<>
78 struct hash<ChimeraTK::TransferElementID> {
79 std::size_t operator()(const ChimeraTK::TransferElementID& f) const { return std::hash<size_t>{}(f._id); }
80 };
81
82 /********************************************************************************************************************/
83
85 template<>
86 struct less<ChimeraTK::TransferElementID> {
88 return a._id < b._id;
89 }
90 };
91} // namespace std
Base class for register accessors which can be part of a TransferGroup.
Simple class holding a unique ID for a TransferElement.
TransferElementID & operator=(const TransferElementID &other)=default
Assign ID from another.
size_t _id
The actual ID value.
bool operator!=(const TransferElementID &other) const
void makeUnique()
Assign an ID to this instance.
bool operator==(const TransferElementID &other) const
Compare ID with another.
bool isValid() const
Check whether the ID is valid.
friend std::ostream & operator<<(std::ostream &os, const TransferElementID &me)
Streaming operator to stream the TransferElementID e.g.
TransferElementID(const TransferElementID &other)=default
Copy ID from another.
TransferElementID()=default
Default constructor constructs an invalid ID, which may be assigned with another ID.
std::ostream & operator<<(std::ostream &stream, const DataDescriptor::FundamentalType &fundamentalType)
STL namespace.
std::size_t operator()(const ChimeraTK::TransferElementID &f) const
bool operator()(const ChimeraTK::TransferElementID &a, const ChimeraTK::TransferElementID &b) const