Honeycomb  0.1
Component-Model Framework
Listener.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/Object/Signal.h"
5 
6 namespace honey
7 {
8 
10 
11 class Listener : public SharedObj<Listener>, public SmallAllocatorObject
12 {
13 public:
16 
18  template<class Signal, class F>
19  static Listener& create(F&& f, const void* obj = nullptr, const Id& id = idnull)
20  {
21  return *new Listener(*new priv::Slot<Signal,F>(id, forward<F>(f)), obj, id);
22  }
23 
24  virtual ~Listener() {}
25 
27  SlotBase& slot() const { assert(_slot); return *_slot; }
29  const void* obj() const { return _obj; }
31  const Id& id() const { return _id; }
32 
33 protected:
34  Listener(SlotBase& slot, const void* obj, const Id& id) :
36  _slot(&slot), _obj(obj), _id(id) {};
37 
39  const void* _obj;
41 };
42 
43 }
const void * obj() const
Get object instance for listener identification.
Definition: Listener.h:29
Combined intrusive/non-intrusive smart pointer. Can reference and share any object automatically...
Definition: SharedPtr.h:175
static Listener & create(F &&f, const void *obj=nullptr, const Id &id=idnull)
Construct with slot to receive Signal using function F. The object instance and id are used together ...
Definition: Listener.h:19
Reference-counted object for intrusive shared pointers.
Definition: SharedPtr.h:93
SharedPtr< Listener > Ptr
Definition: Listener.h:14
Holds a slot that can receive signals.
Definition: Listener.h:11
Objects that inherit from this class will use Alloc for new/delete ops.
Definition: Allocator.h:129
#define assert(...)
Forwards to assert_#args. See assert_1(), assert_2().
Definition: Debug.h:24
#define idnull
Null id.
Definition: Id.h:124
const Id & id() const
Get listener id.
Definition: Listener.h:31
SharedPtr< const Listener > ConstPtr
Definition: Listener.h:15
const void * _obj
Definition: Listener.h:39
Listener(SlotBase &slot, const void *obj, const Id &id)
Definition: Listener.h:34
Global allocator for small memory blocks. To provide a custom pool define SmallAllocator_createSingle...
Definition: SmallAllocator.h:23
Multicast receiver.
Definition: Signal.h:29
UniquePtr< SlotBase > _slot
Definition: Listener.h:36
virtual ~Listener()
Definition: Listener.h:24
Id _id
Definition: Listener.h:40
Holds a name string and its hashed value for fast comparison ops. See String Identifier.
Definition: Id.h:25
Pointer to a unique, non-shared, object. Finalizer is run upon destruction (deletes object by default...
Definition: SharedPtr.h:164
SlotBase & slot() const
Get slot.
Definition: Listener.h:27
Global Honeycomb namespace.