debug.h

来自「这个刚才那个的源代码」· C头文件 代码 · 共 71 行

H
71
字号
#ifndef DEBUG_HPP
#define DEBUG_HPP


#ifdef _DEBUG
# ifndef CORONA_DEBUG
#  define CORONA_DEBUG
# endif
#endif


#ifdef CORONA_DEBUG

  #include <stdio.h>
  #include <string>

  class Log {
  public:
    static void Write(const char* str);
    static void IncrementIndent() { ++indent_count; }
    static void DecrementIndent() { --indent_count; }

  private:
    static void EnsureOpen();
    static void Close();

  private:
    static FILE* handle;
    static int indent_count;
  };


  class Guard {
  public:
    Guard(const char* label)
    : m_label(label) {
      Write("+");
      Log::IncrementIndent();
    }

    ~Guard() {
      Log::DecrementIndent();
      Write("-");
    }

    void Write(const char* prefix) {
      Log::Write((prefix + m_label).c_str());
    }

  private:
    std::string m_label;
  };


  #define COR_GUARD(label) Guard guard_obj__(label)
  #define COR_LOG(label)   (Log::Write(label))
  #define COR_IF_DEBUG     if (true)
  #define COR_ASSERT(condition, label) if (!(condition)) { __asm int 3 }

#else

  #define COR_GUARD(label) 
  #define COR_LOG(label)
  #define COR_IF_DEBUG     if (false)
  #define COR_ASSERT(condition, label)

#endif


#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?