Honeycomb  0.1
Component-Model Framework
Signal.h
Go to the documentation of this file.
1 // Honeycomb, Copyright (C) 2015 NewGamePlus Inc. Distributed under the Boost Software License v1.0.
2 #pragma once
3 
4 #include "Honey/String/Id.h"
6 
7 namespace honey
8 {
9 
15 
18 #define SIGNAL_DECL(BaseClass) \
19  static mt_global(const String, _signalBase, (#BaseClass));
20 
22 #define SIGNAL(Name, Param) \
23  struct Name : Signal<void Param> { static mt_global(const Id, id, (sout() << _signalBase() << "::"#Name)); };
24 
26 template<class Sig_> struct Signal : mt::funcTraits<Sig_> { typedef Sig_ Sig; };
27 
30 {
31 public:
32  SlotBase(const Id& id, const Id& signalId) : _id(id), _signalId(signalId) {}
33  virtual ~SlotBase() {}
34 
35  const Id& id() const { return _id; }
36  const Id& signalId() const { return _signalId; }
37 private:
38  Id _id;
39  Id _signalId;
40 };
41 
43 namespace priv
44 {
45  template<class Signal, class Seq = mt::make_idxseq<Signal::arity>>
46  struct SlotSignal;
47  template<class Signal, szt... Seq>
48  struct SlotSignal<Signal,mt::idxseq<Seq...>> : SlotBase
49  {
50  SlotSignal(const Id& id) : SlotBase(id, Signal::id()) {}
51  virtual void operator()(const typename Signal::template param<Seq>&... args) = 0;
52  };
53 
54  template<class Signal, class F, class Seq = mt::make_idxseq<Signal::arity>>
55  struct Slot;
56  template<class Signal, class F, szt... Seq>
57  struct Slot<Signal,F,mt::idxseq<Seq...>> : public SlotSignal<Signal>
58  {
59  typedef SlotSignal<Signal> Super;
60  public:
61  Slot(const Id& id, F&& f) : Super(id), _f(forward<F>(f)) {}
62 
63  virtual void operator()(const typename Signal::template param<Seq>&... args)
64  {
65  _f(args...);
66  }
67 
68  private:
69  F _f;
70  };
71 }
74 
76 }
77 
78 
const Id & id() const
Definition: Signal.h:35
std::index_sequence< Ints... > idxseq
Shorthand for std::index_sequence.
Definition: Meta.h:111
SlotBase(const Id &id, const Id &signalId)
Definition: Signal.h:32
const Id & signalId() const
Definition: Signal.h:36
virtual ~SlotBase()
Definition: Signal.h:33
Objects that inherit from this class will use Alloc for new/delete ops.
Definition: Allocator.h:129
Multicast sender.
Definition: Signal.h:26
Get function type traits.
Definition: Meta.h:227
size_t szt
Size type, shorthand for size_t.
Definition: Core.h:90
Sig_ Sig
Definition: Signal.h:26
Multicast receiver.
Definition: Signal.h:29
Holds a name string and its hashed value for fast comparison ops. See String Identifier.
Definition: Id.h:25
Global Honeycomb namespace.