client_ptr.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <unordered_set>
4 #include <unordered_map>
5 #include <functional>
6 
7 #include "instance_ptr.hpp"
8 
9 namespace iv
10 {
11 
12 class Instance;
13 
17 template<class TypedClient>
19 {
20 public:
21  client_ptr ( TypedClient * client = nullptr );
22  client_ptr ( client_ptr<TypedClient> const & other );
23  ~client_ptr ( );
24 
26  client_ptr<TypedClient> & operator = ( TypedClient * client );
27 
28 
29  bool operator == ( client_ptr<TypedClient> const & other );
30  bool operator != ( client_ptr<TypedClient> const & other );
31  bool operator < ( client_ptr<TypedClient> const & other );
32  bool operator > ( client_ptr<TypedClient> const & other );
33  bool operator <= ( client_ptr<TypedClient> const & other );
34  bool operator >= ( client_ptr<TypedClient> const & other );
35 
36  TypedClient * get ( ) const;
37  TypedClient & operator * ( ) const;
38  TypedClient * operator -> ( ) const;
39  operator bool ( ) const;
40 
41 protected:
42  virtual void invalidate ( Instance * inst ) override;
43 private:
44  TypedClient * client;
45 };
46 
52 template<class TypedClient>
53 class callback_client_ptr : public client_ptr< TypedClient >
54 {
55 public:
57 
59  callback_client_ptr<TypedClient> & operator=( TypedClient * instance );
60 
61  void set_change_callback( std::function< void() > const & );
62 
63 protected:
64  virtual void invalidate( Instance * inst ) override;
65 
66 private:
67  std::function< void() > _change_callback;
68 };
69 
70 }
71 
72 #include "InstanceSystem.hpp"
73 #include "client_ptr.inl"
74 
75 namespace std
76 {
77 template< class TypedClient >
78 struct hash< iv::client_ptr< TypedClient > >
79 {
81  {
82  return std::hash< TypedClient * >()( ptr.get() );
83  }
84 };
85 }