00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #if !defined(_XRB_INDENTFORMATTER_HPP_)
00012 #define _XRB_INDENTFORMATTER_HPP_
00013
00014 #include "xrb.hpp"
00015
00016 #include <stdarg.h>
00017 #include <stdio.h>
00018 #include <string>
00019
00020 namespace Xrb
00021 {
00022
00023 class IndentFormatter
00024 {
00025 public:
00026
00027 IndentFormatter (FILE *fptr, char const *indent_string);
00028 ~IndentFormatter () { }
00029
00030 void PrintLine (char const *format, ...);
00031 void BeginLine (char const *format, ...);
00032 void ContinueLine (char const *format, ...);
00033 void EndLine (char const *format, ...);
00034 void Indent ();
00035 void Unindent ();
00036
00037 private:
00038
00039 enum State
00040 {
00041 FRESH_LINE = 0,
00042 CONTINUING_LINE
00043 };
00044
00045 void InternalPrintf (
00046 char const *format,
00047 va_list list,
00048 bool prepend_indentation,
00049 bool append_newline);
00050 void UpdateNewlineReplacement ();
00051
00052 FILE *m_fptr;
00053 State m_state;
00054 char const *m_indent_string;
00055 Uint32 m_indent_level;
00056 std::string m_newline_replacement;
00057 std::string m_reformat;
00058 };
00059
00060 }
00061
00062 #endif // !defined(_XRB_INDENTFORMATTER_HPP_)
00063