TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TextOutput.h
Go to the documentation of this file.
1 
12 #ifndef G3D_TextOutput_h
13 #define G3D_TextOutput_h
14 
15 #include "G3D/platform.h"
16 #include "G3D/Array.h"
17 #include <string>
18 
19 namespace G3D {
20 
60 class TextOutput {
61 public:
62 
63  class Settings {
64  public:
76 
79 
83 
86 
89 
94 
96 
100 
102  std::string trueSymbol;
103 
105  std::string falseSymbol;
106 
108  wordWrap(WRAP_WITHOUT_BREAKING),
109  allowWordWrapInsideDoubleQuotes(false),
110  numColumns(80),
111  spacesPerIndent(4),
112  convertNewlines(true),
113  trueSymbol("true"),
114  falseSymbol("false") {
115  #ifdef G3D_WINDOWS
116  newlineStyle = NEWLINE_WINDOWS;
117  #else
118  newlineStyle = NEWLINE_UNIX;
119  #endif
120  }
121  };
122 
123 private:
124 
134 
137 
139  bool inDQuote;
140 
142  std::string filename;
143 
145 
147 
150 
151  void setIndentLevel(int i);
152 
155 
157  std::string newline;
158 
161 
162  void setOptions(const Settings& _opt);
163 
165  void convertNewlines(const std::string& in, std::string& out);
166 
168  void wordWrapIndentAppend(const std::string& str);
169 
172  void indentAppend(char c);
173 
174 public:
175 
176  explicit TextOutput(const std::string& filename, const Settings& options = Settings());
177 
179  explicit TextOutput(const Settings& options = Settings());
180 
182  int line() const {
183  return m_currentLine;
184  }
185 
191  void commit(bool flush = true);
192 
194  void commitString(std::string& string);
195 
197  void pushIndent();
198 
199  void popIndent();
200 
202  std::string commitString();
203 
206  void writeString(const std::string& string);
207 
208  void writeBoolean(bool b);
209 
210  void writeNumber(double n);
211 
212  void writeNumber(int n);
213 
214  void writeNewline();
215  void writeNewlines(int numLines);
216 
218  bool deleteSpace();
219 
225  void writeSymbol(const std::string& string);
226 
227  void writeSymbol(char s);
228 
232  void writeSymbols(
233  const std::string& a,
234  const std::string& b = "",
235  const std::string& c = "",
236  const std::string& d = "",
237  const std::string& e = "",
238  const std::string& f = "");
239 
242  void __cdecl printf(const char* fmt, ...)
243  G3D_CHECK_PRINTF_METHOD_ARGS;
244 
245  // Can't pass by reference because that confuses va_start
246  void __cdecl printf(const std::string fmt, ...);
247  void __cdecl vprintf(const char* fmt, va_list argPtr)
248  G3D_CHECK_VPRINTF_METHOD_ARGS;
249 };
250 
251 // Primitive serializers
252 void serialize(const bool& b, TextOutput& to);
253 void serialize(const int& b, TextOutput& to);
254 void serialize(const uint8& b, TextOutput& to);
255 void serialize(const double& b, TextOutput& to);
256 void serialize(const float& b, TextOutput& to);
257 void serialize(const std::string& b, TextOutput& to);
258 void serialize(const char* b, TextOutput& to);
259 
260 }
261 
262 #endif
std::string newline
Definition: TextOutput.h:157
bool allowWordWrapInsideDoubleQuotes
Definition: TextOutput.h:82
NewlineStyle
Definition: TextOutput.h:93
bool inDQuote
Definition: TextOutput.h:139
NewlineStyle newlineStyle
Definition: TextOutput.h:95
Definition: TextOutput.h:63
int m_currentLine
Definition: TextOutput.h:160
void setOptions(const Settings &_opt)
Definition: TextOutput.cpp:56
void popIndent()
Definition: TextOutput.cpp:72
void pushIndent()
Definition: TextOutput.cpp:67
Definition: TextOutput.h:93
Definition: AABox.h:25
STL namespace.
#define false
Definition: CascPort.h:18
void commit(bool flush=true)
Definition: TextOutput.cpp:419
bool deleteSpace()
Definition: TextOutput.cpp:182
Settings option
Definition: TextOutput.h:146
void writeSymbol(const std::string &string)
Definition: TextOutput.cpp:139
#define true
Definition: CascPort.h:17
void writeNewlines(int numLines)
Definition: TextOutput.cpp:225
int spacesPerIndent
Definition: TextOutput.h:88
TextOutput(const std::string &filename, const Settings &options=Settings())
Definition: TextOutput.cpp:31
WordWrapMode
Definition: TextOutput.h:75
WordWrapMode wordWrap
Definition: TextOutput.h:78
void serialize(const std::string &s, BinaryOutput &b)
Definition: serialize.h:12
int numColumns
Definition: TextOutput.h:85
void writeSymbols(const std::string &a, const std::string &b="", const std::string &c="", const std::string &d="", const std::string &e="", const std::string &f="")
Definition: TextOutput.cpp:149
int indentSpaces
Definition: TextOutput.h:154
int line() const
Definition: TextOutput.h:182
void __cdecl vprintf(const char *fmt, va_list argPtr) G3D_CHECK_VPRINTF_METHOD_ARGS
Definition: TextOutput.cpp:410
std::string trueSymbol
Definition: TextOutput.h:102
int indentLevel
Definition: TextOutput.h:149
void writeString(const std::string &string)
Definition: TextOutput.cpp:112
Definition: TextOutput.h:60
void writeNewline()
Definition: TextOutput.cpp:218
void setIndentLevel(int i)
Definition: TextOutput.cpp:44
std::string filename
Definition: TextOutput.h:142
bool startingNewLine
Definition: TextOutput.h:133
void writeNumber(double n)
Definition: TextOutput.cpp:129
uint8_t uint8
Definition: g3dmath.h:164
Settings()
Definition: TextOutput.h:107
Array< char > data
Definition: TextOutput.h:144
void indentAppend(char c)
Definition: TextOutput.cpp:380
std::string falseSymbol
Definition: TextOutput.h:105
void wordWrapIndentAppend(const std::string &str)
Definition: TextOutput.cpp:232
Definition: TextOutput.h:75
std::string commitString()
Definition: TextOutput.cpp:443
void __cdecl printf(const char *fmt,...) G3D_CHECK_PRINTF_METHOD_ARGS
Definition: TextOutput.cpp:174
Definition: format.h:285
bool convertNewlines
Definition: TextOutput.h:99
void writeBoolean(bool b)
Definition: TextOutput.cpp:125
#define const
Definition: zconf.h:217
Definition: TextOutput.h:75
void convertNewlines(const std::string &in, std::string &out)
Definition: TextOutput.cpp:193
int currentColumn
Definition: TextOutput.h:136