Changeset 20220 for lang/cplusplus/debugprint
- Timestamp:
- 09/29/08 21:20:46 (5 years ago)
- Location:
- lang/cplusplus/debugprint
- Files:
-
- 2 modified
-
README (modified) (1 diff)
-
indented_debugprint.hpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/cplusplus/debugprint/README
r20209 r20220 4 4 - debugprint.hpp 本体 5 5 - test_debugprint.cpp テスト(使い方はこれを見る) 6 2008-09-29 唐突にネストしたインデントをサポートしたくなったけど 7 それをやると既存のマクロも含めてだいぶいじらないと行けないので 8 とりあえず現状をリポジトリに入れて公開。 6 - indented_debugprint.hpp 新しいバージョン(枯れてない) 7 - test_indented_debugprint.cpp テスト(使い方はこれを見る) 9 8 10 9 * ChangeLog 11 2008-09-29 公開。indented_debugprint.hppは着手したばっかり。 10 2008-09-29 11 唐突にネストしたインデントをサポートしたくなったけど 12 それをやると既存のマクロも含めてだいぶいじらないと行けないので 13 とりあえず現状をリポジトリに入れて公開。 14 indented_debugprint.hppは着手したばっかり。 15 ある程度動くようになったら共通部分をまとめたりとかする。 16 2008-09-29 17 indented_debugprint.hppはそれなりに動くようになった。 -
lang/cplusplus/debugprint/indented_debugprint.hpp
r20209 r20220 65 65 ; 66 66 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;67 struct 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, ' '); 75 75 } 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; 83 77 } 78 void push(size_t w = 1){ 79 depth += w; 80 } 81 void pop(size_t w = 1){ 82 depth -= w; 83 } 84 }; 84 85 86 Indenter indent; 87 85 88 #define P(x) (std::string(#x) + ": " + repr(x)) 86 89 // 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; 88 91 // 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 92 99 93 100 }
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)