SystemContainer.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../DebugView/TextDebugView.hpp"
4 #include "../Basics/SrcInfo.hpp"
5 #include "../Basics/static_warning.hpp"
6 
7 #include <unordered_map>
8 #include <unordered_set>
9 #include <iostream>
10 #include <typeinfo>
11 #include <typeindex>
12 #include <csignal>
13 
14 namespace iv
15 {
16 
17 class SystemContainer;
18 class TextDebugView;
19 
20 class System : public Context
21 {
22 public:
23  System( SystemContainer * sc );
24  virtual ~System(){}
25 
26  virtual bool flushSystem(){ return false; }
27  virtual void status( TextDebugView * view ){}
28  virtual std::string debug_name() const{ return ""; }
29 
33 
37  void retain();
41  void release();
42 
43 protected:
44  virtual bool log_process_enabled( LogId id ) const override final;
45  virtual void log_process( SrcInfo const & info, LogId id, std::string const & message ) const override final;
46 
47 private:
48  SystemContainer * sc;
49  unsigned _refcounters;
50 };
51 
56 {
57 public:
62 
66  SystemContainer( SystemContainer const * sc );
67 
72 
73  void debug_print( TextDebugView * view ) const;
74 
78  std::unordered_map< std::type_index /*type*/, System * > const & debug_GetSystems() const;
79 
86  bool flushSystems();
87 
90  void nextFrame();
91 
94  unsigned frame_id() const;
95 
99  template< class TypedSystem >
100  TypedSystem * getSystem() const;
101 
105  System * getSystem( std::type_index type ) const;
106 
112  template< class TypedSystem, typename... Args >
113  TypedSystem * createOwnSystem( Args... constructor_arguments );
114 
120  template< class TypedSystem >
121  TypedSystem * addForeignSystem( TypedSystem * system );
122 
127  template< class TypedSystem >
128  void removeSystem();
129 
130 private:
131  std::unordered_map< std::type_index /*type*/, System * > systems;
132  std::unordered_set< System * > own_systems;
133  unsigned _frame_id;
134 };
135 }