TableDebugView.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "DebugView.hpp"
4 
5 #include "../Basics/RuntimeId.hpp"
6 #include "../Basics/StringIOIndex.hpp"
7 #include "../Instancing/instance_ptr.hpp"
8 
9 #include <string>
10 #include <vector>
11 #include <any>
12 
13 //----------------------------------------------------------------------------------------------------------------------
14 //------------- TableId ------------------------------------------------------------------------------------------------
15 namespace iv
16 {
17 
18 class TableId : public RuntimeId< TableId >
19 {
20 public:
21  static constexpr char TypeName[] = "TableId";
24 };
25 
26 }
27 
28 namespace std
29 {
30 template<>
31 struct hash< iv::TableId > : iv::hash< iv::TableId >{};
32 }
33 
34 namespace iv
35 {
36 
37 class TableDebugView;
38 
39 namespace table_debug_context
40 {
41 
42 struct HintData;
43 struct ColumnData;
44 struct RowData;
45 struct TableData;
46 
47 //---------------------- Handles -------------------------------------------------------------------
49 {
50 public:
51  template< class ColumnT >
52  ColumnHandle( RowData * _row, const char * col_name, ColumnT && value );
53 
54  template< class HintT >
55  ColumnHandle & Hint( const char * hint_name, HintT && value );
56 
57 private:
58  ColumnData * _column;
59 };
60 
61 class RowHandle
62 {
63 public:
64  RowHandle( TableData * _table, std::any const & row_id );
65 
66  template< class ColumnT >
67  ColumnHandle Column( char const * col_name, ColumnT && value );
68 
69 private:
70  RowData * _row;
71 };
72 
74 {
75 public:
76  TableHandle( TableDebugView * context, TableId table_id );
77 
78  RowHandle Row( std::any const & row_id );
79 
80 private:
81  TableData * _table;
82 };
83 
84 //---------------------- Data ----------------------------------------------------------------------
85 struct HintData
86 {
87  std::string name;
88  std::any hint;
89 };
90 
91 struct ColumnData
92 {
93  std::any value;
94  std::vector< HintData > hints;
95 };
96 
97 struct RowData
98 {
99  std::any identity;
100  std::unordered_map< std::string, ColumnData > columns;
101 };
102 
103 struct TableData
104 {
105  std::vector< RowData > rows;
106 };
107 
108 }
109 
110 //----------------------------------------------------------------------------------------------------------------------
111 //------------- TableDebugView --------------------------------------------------------------------------------------
115 class TableDebugView : public DebugView
116 {
117 public:
119 
121 
122  bool IsEmpty() const;
123  void Clear();
124 
125  //
127  std::unordered_map< TableId, TableData > const & Tables() const;
128  std::unordered_map< TableId, TableData > & Tables();
129 
130 private:
131  std::unordered_map< TableId, TableData > tables;
132 };
133 
134 //----------------------------------------------------------------------------------------------------------------------
135 //------------- Handles --------------------------------------------------------------------------------------------
136 }
137 
138 #include "TableDebugView.inl"