helics  3.5.2
LocalFederateId.hpp
1 /*
2 Copyright (c) 2017-2024,
3 Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Sustainable
4 Energy, LLC. See the top-level NOTICE for additional details. All rights reserved.
5 SPDX-License-Identifier: BSD-3-Clause
6 */
7 
8 #pragma once
9 #include <cstdint>
10 #include <functional>
11 #include <iosfwd>
12 
13 namespace helics {
15 using 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
49 std::ostream& operator<<(std::ostream& os, LocalFederateId fid);
50 
51 #endif
53 constexpr LocalFederateId gLocalCoreId(-259);
54 
55 namespace 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
93 std::ostream& operator<<(std::ostream& os, InterfaceHandle handle);
94 #endif
95 
97  -1'745'234};
98 
99 } // namespace helics
100 
101 namespace std {
103 template<>
104 struct 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 
114 template<>
115 struct 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
bool operator<(InterfaceHandle id) const noexcept
Definition: LocalFederateId.hpp:79
BaseType * getBaseTypePointer()
Definition: LocalFederateId.hpp:83
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:918
int32_t IdentifierBaseType
Definition: LocalFederateId.hpp:15
std::size_t operator()(helics::InterfaceHandle const &key) const noexcept
Definition: LocalFederateId.hpp:117
std::size_t operator()(helics::LocalFederateId const &key) const noexcept
Definition: LocalFederateId.hpp:106