1 /************************************************************************ 2 * file name : common_types.h 3 * ----------------- : 4 * creation time : 2016/07/31 5 * author : Victor Zarubkin 6 * email : v.s.zarubkin@gmail.com 7 * ----------------- : 8 * description : The file contains declaration of common types for both GraphicsView 9 * : and TreeWidget. 10 * ----------------- : 11 * change log : * 2016/07/31 Victor Zarubkin: initial commit. 12 * : 13 * : * 14 * ----------------- : 15 * license : Lightweight profiler library for c++ 16 * : Copyright(C) 2016-2017 Sergey Yagovtsev, Victor Zarubkin 17 * : 18 * : Licensed under either of 19 * : * MIT license (LICENSE.MIT or http://opensource.org/licenses/MIT) 20 * : * Apache License, Version 2.0, (LICENSE.APACHE or http://www.apache.org/licenses/LICENSE-2.0) 21 * : at your option. 22 * : 23 * : The MIT License 24 * : 25 * : Permission is hereby granted, free of charge, to any person obtaining a copy 26 * : of this software and associated documentation files (the "Software"), to deal 27 * : in the Software without restriction, including without limitation the rights 28 * : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 29 * : of the Software, and to permit persons to whom the Software is furnished 30 * : to do so, subject to the following conditions: 31 * : 32 * : The above copyright notice and this permission notice shall be included in all 33 * : copies or substantial portions of the Software. 34 * : 35 * : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 36 * : INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 37 * : PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 38 * : LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 39 * : TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 40 * : USE OR OTHER DEALINGS IN THE SOFTWARE. 41 * : 42 * : The Apache License, Version 2.0 (the "License") 43 * : 44 * : You may not use this file except in compliance with the License. 45 * : You may obtain a copy of the License at 46 * : 47 * : http://www.apache.org/licenses/LICENSE-2.0 48 * : 49 * : Unless required by applicable law or agreed to in writing, software 50 * : distributed under the License is distributed on an "AS IS" BASIS, 51 * : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 52 * : See the License for the specific language governing permissions and 53 * : limitations under the License. 54 ************************************************************************/ 55 56 #ifndef EASY_PROFILER__GUI_COMMON_TYPES_H 57 #define EASY_PROFILER__GUI_COMMON_TYPES_H 58 59 #include <vector> 60 #include <easy/reader.h> 61 #include <QObject> 62 63 ////////////////////////////////////////////////////////////////////////// 64 ////////////////////////////////////////////////////////////////////////// 65 66 namespace profiler_gui { 67 68 #define EASY_GRAPHICS_ITEM_RECURSIVE_PAINT 69 //#undef EASY_GRAPHICS_ITEM_RECURSIVE_PAINT 70 71 #pragma pack(push, 1) 72 struct EasyBlockItem Q_DECL_FINAL 73 { 74 qreal x; ///< x coordinate of the item (this is made qreal=double to avoid mistakes on very wide scene) 75 float w; ///< Width of the item 76 ::profiler::block_index_t block; ///< Index of profiler block 77 78 #ifndef EASY_GRAPHICS_ITEM_RECURSIVE_PAINT 79 ::profiler::block_index_t neighbours; ///< Number of neighbours (parent.children.size()) 80 uint32_t children_begin; ///< Index of first child item on the next sublevel 81 int8_t state; ///< 0 = no change, 1 = paint, -1 = do not paint 82 #else 83 ::profiler::block_index_t max_depth_child; ///< Index of child with maximum tree depth 84 uint32_t children_begin; ///< Index of first child item on the next sublevel 85 #endif 86 87 // Possible optimizations: 88 // 1) We can save 1 more byte per block if we will use char instead of short + real time calculations for "totalHeight" var; 89 // 2) We can save 12 bytes per block if "x" and "w" vars will be removed (all this information exist inside BlocksTree), 90 // but this requires runtime x-coodinate calculation because BlocksTree has x value in nanoseconds. 91 setPosQ_DECL_FINAL92 inline void setPos(qreal _x, float _w) { x = _x; w = _w; } leftQ_DECL_FINAL93 inline qreal left() const { return x; } rightQ_DECL_FINAL94 inline qreal right() const { return x + w; } widthQ_DECL_FINAL95 inline float width() const { return w; } 96 97 }; // END of struct EasyBlockItem. 98 99 //#define EASY_TREE_WIDGET__USE_VECTOR 100 struct EasyBlock Q_DECL_FINAL 101 { 102 ::profiler::BlocksTree tree; 103 #ifdef EASY_TREE_WIDGET__USE_VECTOR 104 uint32_t tree_item; 105 #endif 106 uint32_t graphics_item_index; 107 uint8_t graphics_item_level; 108 uint8_t graphics_item; 109 bool expanded; 110 111 EasyBlock() = default; 112 EasyBlockQ_DECL_FINAL113 EasyBlock(EasyBlock&& that) 114 : tree(::std::move(that.tree)) 115 #ifdef EASY_TREE_WIDGET__USE_VECTOR 116 , tree_item(that.tree_item) 117 #endif 118 , graphics_item_index(that.graphics_item_index) 119 , graphics_item_level(that.graphics_item_level) 120 , graphics_item(that.graphics_item) 121 , expanded(that.expanded) 122 { 123 } 124 125 private: 126 127 EasyBlock(const EasyBlock&) = delete; 128 }; 129 #pragma pack(pop) 130 131 typedef ::std::vector<EasyBlockItem> EasyItems; 132 typedef ::std::vector<EasyBlock> EasyBlocks; 133 134 ////////////////////////////////////////////////////////////////////////// 135 136 struct EasySelectedBlock Q_DECL_FINAL 137 { 138 const ::profiler::BlocksTreeRoot* root; 139 ::profiler::block_index_t tree; 140 EasySelectedBlockQ_DECL_FINAL141 EasySelectedBlock() : root(nullptr), tree(0xffffffff) 142 { 143 } 144 EasySelectedBlockQ_DECL_FINAL145 EasySelectedBlock(const ::profiler::BlocksTreeRoot* _root, const ::profiler::block_index_t _tree) 146 : root(_root) 147 , tree(_tree) 148 { 149 } 150 151 }; // END of struct EasySelectedBlock. 152 153 typedef ::std::vector<EasySelectedBlock> TreeBlocks; 154 155 ////////////////////////////////////////////////////////////////////////// 156 157 enum TimeUnits : int8_t 158 { 159 TimeUnits_ms = 0, 160 TimeUnits_us, 161 TimeUnits_ns, 162 TimeUnits_auto 163 164 }; // END of enum TimeUnits. 165 166 ////////////////////////////////////////////////////////////////////////// 167 168 } // END of namespace profiler_gui. 169 170 template <typename ... Args> 171 struct Overload 172 { 173 template <typename TClass, typename TReturn> 174 static EASY_CONSTEXPR_FCN auto of(TReturn (TClass::*method)(Args...)) -> decltype(method) 175 { 176 return method; 177 } 178 179 template <typename TReturn> 180 static EASY_CONSTEXPR_FCN auto of(TReturn (*func)(Args...)) -> decltype(func) 181 { 182 return func; 183 } 184 }; 185 186 template <> 187 struct Overload<void> 188 { 189 template <typename TClass, typename TReturn> 190 static EASY_CONSTEXPR_FCN auto of(TReturn (TClass::*method)()) -> decltype(method) 191 { 192 return method; 193 } 194 195 template <typename TReturn> 196 static EASY_CONSTEXPR_FCN auto of(TReturn (*func)()) -> decltype(func) 197 { 198 return func; 199 } 200 }; 201 202 ////////////////////////////////////////////////////////////////////////// 203 ////////////////////////////////////////////////////////////////////////// 204 205 #endif // EASY_PROFILER__GUI_COMMON_TYPES_H 206