Show
Ignore:
Timestamp:
09/29/08 21:20:46 (5 years ago)
Author:
nishio
Message:

/lang/cplusplus/debugprint indented_debugprintがそれなりに動くようになった

Location:
lang/cplusplus/debugprint
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/cplusplus/debugprint/README

    r20209 r20220  
    44 - debugprint.hpp 本体 
    55  - test_debugprint.cpp テスト(使い方はこれを見る) 
    6   2008-09-29 唐突にネストしたインデントをサポートしたくなったけど 
    7   それをやると既存のマクロも含めてだいぶいじらないと行けないので 
    8   とりあえず現状をリポジトリに入れて公開。 
     6  - indented_debugprint.hpp 新しいバージョン(枯れてない) 
     7  - test_indented_debugprint.cpp テスト(使い方はこれを見る) 
    98 
    109* ChangeLog 
    11 2008-09-29 公開。indented_debugprint.hppは着手したばっかり。 
     102008-09-29 
     11        唐突にネストしたインデントをサポートしたくなったけど 
     12        それをやると既存のマクロも含めてだいぶいじらないと行けないので 
     13        とりあえず現状をリポジトリに入れて公開。 
     14        indented_debugprint.hppは着手したばっかり。 
     15        ある程度動くようになったら共通部分をまとめたりとかする。 
     162008-09-29 
     17        indented_debugprint.hppはそれなりに動くようになった。 
  • lang/cplusplus/debugprint/indented_debugprint.hpp

    r20209 r20220  
    6565; 
    6666 
    67   namespace indent{ 
    68     size_t depth = 0; 
    69     size_t indent_width = 2; 
    70     void indent(){ 
    71       if(head_of_line){ 
    72         std::cout << std::string(depth * indent_width, ' '); 
    73       } 
    74       head_of_line = false; 
     67struct Indenter{ 
     68  size_t depth ; 
     69  size_t indent_width; 
     70  bool head_of_line; 
     71  Indenter():depth(0),indent_width(2),head_of_line(true){}; 
     72  std::ostream& indent(){ 
     73    if(head_of_line && depth > 0){ 
     74      std::cout << std::string(depth * indent_width, ' '); 
    7575    } 
    76     void push(size_t w = 1){ 
    77       depth += w; 
    78     } 
    79     void pop(size_t w = 1){ 
    80       depth -= w; 
    81     } 
    82     bool head_of_line = true; 
     76    return std::cout; 
    8377  } 
     78  void push(size_t w = 1){ 
     79    depth += w; 
     80  } 
     81  void pop(size_t w = 1){ 
     82    depth -= w; 
     83  } 
     84}; 
    8485 
     86Indenter indent; 
     87   
    8588#define P(x) (std::string(#x) + ": " + repr(x)) 
    8689// debug print 
    87 #define DP(x) std::cout << P(x) << std::endl; 
     90#define DP(x) indent.indent() << P(x) << std::endl; indent.head_of_line = true; 
    8891// debug print with comma 
    89 #define DPC(x) std::cout << P(x) << ", "; 
    90 // message(indented) 
    91 #define MSG(x) std::cout << #x << std::endl; 
     92#define DPC(x) indent.indent() << P(x) << ", "; indent.head_of_line = false; 
     93// message 
     94#define MSG(x) indent.indent() << #x << std::endl; indent.head_of_line = true; 
     95// begin~end indent region 
     96#define BEGIN(x) indent.indent() << "BEGIN " << P(x) << std::endl; indent.push(); 
     97#define END(x) indent.pop(); indent.indent() << "END " << P(x) << std::endl; 
     98 
    9299 
    93100}