1 // [Blend2D] 2 // 2D Vector Graphics Powered by a JIT Compiler. 3 // 4 // [License] 5 // Zlib - See LICENSE.md file in the package. 6 7 #ifndef BLEND2D_TRACE_P_H 8 #define BLEND2D_TRACE_P_H 9 10 #include "./api-internal_p.h" 11 12 //! \cond INTERNAL 13 //! \addtogroup blend2d_internal 14 //! \{ 15 16 // ============================================================================ 17 // [BLDummyTrace] 18 // ============================================================================ 19 20 //! Dummy trace - no tracing, no runtime overhead. 21 class BLDummyTrace { 22 public: enabled()23 BL_INLINE bool enabled() const noexcept { return false; }; indent()24 BL_INLINE void indent() noexcept {} deindent()25 BL_INLINE void deindent() noexcept {} 26 27 template<typename... Args> out(Args &&...)28 BL_INLINE void out(Args&&...) noexcept {} 29 30 template<typename... Args> info(Args &&...)31 BL_INLINE void info(Args&&...) noexcept {} 32 33 template<typename... Args> warn(Args &&...)34 BL_INLINE bool warn(Args&&...) noexcept { return false; } 35 36 template<typename... Args> fail(Args &&...)37 BL_INLINE bool fail(Args&&...) noexcept { return false; } 38 }; 39 40 // ============================================================================ 41 // [BLDebugTrace] 42 // ============================================================================ 43 44 //! Debug trace - active / enabled trace that can be useful during debugging. 45 class BLDebugTrace { 46 public: BLDebugTrace()47 BL_INLINE BLDebugTrace() noexcept 48 : indentation(0) {} BLDebugTrace(const BLDebugTrace & other)49 BL_INLINE BLDebugTrace(const BLDebugTrace& other) noexcept 50 : indentation(other.indentation) {} 51 enabled()52 BL_INLINE bool enabled() const noexcept { return true; }; indent()53 BL_INLINE void indent() noexcept { indentation++; } deindent()54 BL_INLINE void deindent() noexcept { indentation--; } 55 56 template<typename... Args> out(Args &&...args)57 BL_INLINE void out(Args&&... args) noexcept { log(0, 0xFFFFFFFFu, std::forward<Args>(args)...); } 58 59 template<typename... Args> info(Args &&...args)60 BL_INLINE void info(Args&&... args) noexcept { log(0, indentation, std::forward<Args>(args)...); } 61 62 template<typename... Args> warn(Args &&...args)63 BL_INLINE bool warn(Args&&... args) noexcept { log(1, indentation, std::forward<Args>(args)...); return false; } 64 65 template<typename... Args> fail(Args &&...args)66 BL_INLINE bool fail(Args&&... args) noexcept { log(2, indentation, std::forward<Args>(args)...); return false; } 67 68 BL_HIDDEN static void log(uint32_t severity, uint32_t indentation, const char* fmt, ...) noexcept; 69 70 int indentation; 71 }; 72 73 //! \} 74 //! \endcond 75 76 #endif // BLEND2D_TRACE_P_H 77