ActorId.h
1 /*
2  * qb - C++ Actor Framework
3  * Copyright (C) 2011-2019 isndev (www.qbaf.io). All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef QB_ACTORID_H
19 # define QB_ACTORID_H
20 # include <limits>
21 # include <cstdint>
22 // include from qb
23 # include <qb/utility/prefix.h>
24 # include <qb/io.h>
25 
26 namespace qb {
27 
35  class ActorId {
36  friend class Main;
37  friend class VirtualCore;
38  friend class Actor;
39 
40  uint16_t _id;
41  uint16_t _index;
42 
43  protected:
44  ActorId(uint16_t const id, uint16_t const index);
45  public:
46  static constexpr uint32_t NotFound = 0;
47  static constexpr uint16_t BroadcastSid = std::numeric_limits<uint16_t>::max();
48 
52  ActorId();
57  ActorId(uint32_t const id);
58  ActorId(ActorId const &) = default;
59 
60  operator const uint32_t &() const;
61 
65  uint16_t sid() const;
69  uint16_t index() const;
70 
71  bool isBroadcast() const;
72  };
73 
74  class BroadcastId : public ActorId {
75  public:
76  BroadcastId() = delete;
77  explicit BroadcastId(uint32_t const core_id)
78  : ActorId(BroadcastSid, static_cast<uint16_t>(core_id)) {}
79  };
80 
81 }
82 
83 qb::io::stream &operator<<(qb::io::stream &os, qb::ActorId const &id);
84 
85 #endif //QB_ACTORID_H
Definition: ActorId.h:74
Actor base class.
Definition: Actor.h:41
Definition: VirtualCore.h:50
Actor unique identifier.
Definition: ActorId.h:35
uint16_t sid() const
uint16_t index() const
Core main class.
Definition: Main.h:39