Instance.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../Basics/LogId.hpp"
4 #include "../Basics/SrcInfo.hpp"
5 #include "../Basics/volatile_set.hpp"
6 #include "../Basics/StringIO_defs.hpp"
7 
8 #include <unordered_set>
9 #include <string>
10 #include <sstream>
11 #include <type_traits>
12 #include <vector>
13 #include <functional>
14 #include <typeindex>
15 #include <list>
16 #include <type_traits>
17 
18 namespace iv
19 {
20 
21 class InstanceSystem;
22 class DebugInstanceListener;
23 class SystemContainer;
24 class instance_ptr_interface;
25 class ClientMarker;
26 class TextDebugView;
27 
30 class Instance
31 {
32 public:
33  //------------------------- structors ------------------------------
34  Instance( const SystemContainer * sc );
35  virtual ~Instance( );
36  Instance * instance(){ return this; }
37 
38 
39  //------------------------- SystemContainer manipulation -----------
44  SystemContainer const * getSystemContainer() const;
45 
56 
60  template< class TypedSystem >
61  TypedSystem * getSystem() const;
62 
65  unsigned frame_id() const;
66 
67  //------------------------- instance introspection --------------------------
71  std::string const & instance_name();
72 
77  void instance_parent( Instance * parent );
78 
84  void instance_finalize( std::string const & inst_name, ClientMarker const * root_client );
85 
89  void client_register( ClientMarker const * marker );
90  void client_unregister( ClientMarker const * marker );
91 
92  //------------------------- logging --------------------------------
93  void client_log( ClientMarker const * cm, SrcInfo const & info, LogId id, std::string const & message );
94  bool client_log_enabled( ClientMarker const * cm, LogId id );
95 
96  //------------------------- debug access ---------------------------------
97  void debug_print_clients( TextDebugView * view );
98 
102  std::unordered_set< Instance * > const & Debug_Children();
103 
104  ClientMarker const * Debug_RootClient();
105  std::unordered_set< ClientMarker const * > const & Debug_Clients();
106 
112  template< class TypedClient >
113  void Debug_ForeachClient( std::function< void( TypedClient * ) > const & lambda );
114 
115 private:
116  InstanceSystem * getOS();
117 
118 private:
119  //------------------ systems -------------------------------
120  SystemContainer const * sc;
121  SystemContainer * sc_dup;
122 
123  InstanceSystem * os;
124 
125  //----------------- structure introspection -------------------------------
126  std::string _instance_name;
127 
128  Instance * _parent;
129  std::unordered_set< Instance * > _children;
130 
131  ClientMarker const * _root_client;
132  std::unordered_set< ClientMarker const * > _clients;
133 
134  //------------- debug ----------------------
135  int _logging_cnt;
136 
137  //------------- weak pointer impl ----------
139  std::unordered_set< instance_ptr_interface * > instance_pointers;
140 };
141 
142 }
143 
144 #include "SystemContainer.hpp"
145 #include "InstanceSystem.hpp"
146 #include "ClientMarker.hpp"
147 
148 #include "Instance.inl"