helics 3.7.0
Loading...
Searching...
No Matches
LocalFederateId.hpp
1/*
2Copyright (c) 2017-2026,
3Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Energy
4Innovation LLC. See the top-level NOTICE for additional details. All rights reserved.
5SPDX-License-Identifier: BSD-3-Clause
6*/
7
8#pragma once
9#include <cstdint>
10#include <functional>
11#include <iosfwd>
12
13namespace helics {
15using IdentifierBaseType = int32_t;
16
23 public:
24 using BaseType = IdentifierBaseType;
26 constexpr LocalFederateId() = default;
28 constexpr explicit LocalFederateId(BaseType val) noexcept: fid(val) {}
30 constexpr BaseType baseValue() const { return fid; }
32 bool operator==(LocalFederateId id) const noexcept { return (fid == id.fid); }
34 bool operator!=(LocalFederateId id) const noexcept { return (fid != id.fid); }
36 bool operator<(LocalFederateId id) const noexcept { return (fid < id.fid); }
39 bool isValid() const { return (fid != invalid_fid); }
40
41 private:
42 static constexpr BaseType invalid_fid{-2'000'000'000};
43 BaseType fid{invalid_fid};
44};
45
46#if defined HELICS_STATIC_CORE_LIBRARY && !defined HELICS_SHARED_LIBRARY
49std::ostream& operator<<(std::ostream& os, LocalFederateId fid);
50
51#endif
54
55namespace detail {
57 constexpr IdentifierBaseType gInvalidInterfaceHandle{-1'700'000'000};
58} // namespace detail
59
66 public:
67 using BaseType = IdentifierBaseType;
69 constexpr InterfaceHandle() = default;
70
71 constexpr explicit InterfaceHandle(BaseType val) noexcept: hid(val) {}
73 constexpr BaseType baseValue() const { return hid; }
75 bool operator==(InterfaceHandle id) const noexcept { return (hid == id.hid); }
77 bool operator!=(InterfaceHandle id) const noexcept { return (hid != id.hid); }
79 bool operator<(InterfaceHandle id) const noexcept { return (hid < id.hid); }
80 bool operator>(InterfaceHandle id) const noexcept { return (hid > id.hid); }
81 bool isValid() const { return (hid != mInvalidHandle); }
83 BaseType* getBaseTypePointer() { return &hid; }
84
85 private:
86 static constexpr BaseType mInvalidHandle{detail::gInvalidInterfaceHandle};
87 BaseType hid{mInvalidHandle};
88};
89
90#if defined HELICS_STATIC_CORE_LIBRARY && !defined HELICS_SHARED_LIBRARY
93std::ostream& operator<<(std::ostream& os, InterfaceHandle handle);
94#endif
95
97 -1'745'234};
98
99} // namespace helics
100
101namespace std {
103template<>
104struct hash<helics::LocalFederateId> {
106 std::size_t operator()(helics::LocalFederateId const& key) const noexcept
107 {
108 return std::hash<helics::LocalFederateId::BaseType>{}(key.baseValue());
109 }
110};
111
114template<>
115struct hash<helics::InterfaceHandle> {
117 std::size_t operator()(helics::InterfaceHandle const& key) const noexcept
118 {
119 return std::hash<helics::InterfaceHandle::BaseType>{}(key.baseValue());
120 }
121};
122
123} // namespace std
Definition LocalFederateId.hpp:65
bool operator!=(InterfaceHandle id) const noexcept
Definition LocalFederateId.hpp:77
constexpr BaseType baseValue() const
Definition LocalFederateId.hpp:73
constexpr InterfaceHandle()=default
bool operator==(InterfaceHandle id) const noexcept
Definition LocalFederateId.hpp:75
BaseType * getBaseTypePointer()
Definition LocalFederateId.hpp:83
bool operator<(InterfaceHandle id) const noexcept
Definition LocalFederateId.hpp:79
Definition LocalFederateId.hpp:22
bool operator<(LocalFederateId id) const noexcept
Definition LocalFederateId.hpp:36
bool operator!=(LocalFederateId id) const noexcept
Definition LocalFederateId.hpp:34
constexpr BaseType baseValue() const
Definition LocalFederateId.hpp:30
bool operator==(LocalFederateId id) const noexcept
Definition LocalFederateId.hpp:32
bool isValid() const
Definition LocalFederateId.hpp:39
constexpr LocalFederateId()=default
constexpr LocalFederateId(BaseType val) noexcept
Definition LocalFederateId.hpp:28
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition AsyncFedCallInfo.hpp:14
constexpr LocalFederateId gLocalCoreId(-259)
constexpr InterfaceHandle gDirectSendHandle
this special handle can be used to directly send a message in a core
Definition LocalFederateId.hpp:96
std::ostream & operator<<(std::ostream &out, const ActionMessage &command)
Definition ActionMessage.cpp:965
int32_t IdentifierBaseType
Definition LocalFederateId.hpp:15
STL namespace.