OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4LogBuf.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
5  * Copyright (c) 2013-2016, The OpenClonk Team and contributors
6  *
7  * Distributed under the terms of the ISC license; see accompanying file
8  * "COPYING" for details.
9  *
10  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11  * See accompanying file "TRADEMARK" for details.
12  *
13  * To redistribute this file separately, substitute the full license texts
14  * for the above references.
15  */
16 // a buffer holding a log history
17 
18 #ifndef INC_C4LogBuf
19 #define INC_C4LogBuf
20 
21 // circular log buffer to holding line-wise log data
23 {
24 private:
25  struct LineData
26  {
27  CStdFont *pFont; // line font
28  DWORD dwClr; // line clr
29  bool fNewParagraph; // if set, this line marks a new paragraph (and is not the wrapped line of a previous par)
30  };
31 
32  char *szBuf; // string buffer
33  LineData *pLineDataBuf; // line data buffer
34  int iBufSize; // size of string buffer
35  int iFirstLinePos, iAfterLastLinePos; // current string buffer positions
36  int iLineDataPos, iNextLineDataPos; // current line data buffer positions
37  int iMaxLineCount; // max number of valid lines - size of line data buffer
38  int iLineCount; // number of valid lines in buffer
39  int iLineBreakWidth; // line breaking width
40  char *szIndent; // chars inserted as indent space
41  bool fDynamicGrow; // if true, lines are always added to the buffer. If false, the buffer is used circular and old lines removed
42  bool fMarkup; // if set, '|' is treated as linebreak
43 
44  void GrowLineCountBuffer(size_t iGrowBy);
45  void GrowTextBuffer(size_t iGrowBy);
46  void DiscardFirstLine(); // discard oldest line in buffer
47  void AppendSingleLine(const char *szLine, int iLineLength, const char *szIndent, CStdFont *pFont, DWORD dwClr, bool fNewParagraph); // append given string as single line
48 
49 public:
50  C4LogBuffer(int iSize, int iMaxLines, int iLBWidth, const char *szIndentChars=" ", bool fDynamicGrow = false, bool fMarkup = true); // ctor
51  ~C4LogBuffer(); // dtor
52 
53  void AppendLines(const char *szLine, CStdFont *pFont, DWORD dwClr, CStdFont *pFirstLineFont=nullptr); // append message line to buffer; overwriting old lines if necessary
54  const char *GetLine(int iLineIndex, CStdFont **ppFont, DWORD *pdwClr, bool *pNewParagraph) const; // get indexed line - negative indices -n return last-n'th-line
55  void Clear(); // clear all lines
56 
57  int GetCount() const { return iLineCount; }// retrieve number of valid lines in buffer
58  void SetLBWidth(int iToWidth);
59 };
60 
61 #endif // C4LogBuf
const char * GetLine(int iLineIndex, CStdFont **ppFont, DWORD *pdwClr, bool *pNewParagraph) const
Definition: C4LogBuf.cpp:244
void SetLBWidth(int iToWidth)
Definition: C4LogBuf.cpp:278
void AppendLines(const char *szLine, CStdFont *pFont, DWORD dwClr, CStdFont *pFirstLineFont=nullptr)
Definition: C4LogBuf.cpp:170
void Clear()
Definition: C4LogBuf.cpp:272
int GetCount() const
Definition: C4LogBuf.h:57
uint32_t DWORD
C4LogBuffer(int iSize, int iMaxLines, int iLBWidth, const char *szIndentChars=" ", bool fDynamicGrow=false, bool fMarkup=true)
Definition: C4LogBuf.cpp:23
int iSize
Definition: TstC4NetIO.cpp:35