Scid  4.7.0
textbuf.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////
2 //
3 // FILE: textbuf.h
4 // TextBuffer class
5 //
6 // Part of: Scid (Shane's Chess Information Database)
7 // Version: 2.7
8 //
9 // Notice: Copyright (c) 1999-2001 Shane Hudson. All rights reserved.
10 //
11 // Author: Shane Hudson (sgh@users.sourceforge.net)
12 //
13 ///////////////////////////////////////////////////////////////////////////
14 
15 
16 #ifndef SCID_TEXTBUF_H
17 #define SCID_TEXTBUF_H
18 
19 #include "common.h"
20 #include <stdio.h>
21 
23 {
24 private:
25  //----------------------------------
26  // TextBuffer: Data Structures
27 
28  uint Column;
29  uint IndentColumn;
30  uint WrapColumn;
31  uint LineIsEmpty; // true if current line is empty.
32  uint LineCount;
33  uint ByteCount;
34  uint BufferSize;
35  bool ConvertNewlines; // If true, convert newlines to spaces.
36  char * Buffer;
37  char * Current;
38 
39  bool PausedTranslations;
40  bool HasTranslations;
41  const char * Translation [256];
42 
43  inline void AddChar (char ch);
44  TextBuffer(const TextBuffer&);
45  TextBuffer& operator=(const TextBuffer&);
46 
47  //----------------------------------
48  // TextBuffer: Public Functions
49 public:
51  Init();
52  SetBufferSize(1280000);
53  }
54  ~TextBuffer() { Free(); }
55 
56  void Init ();
57  void Free ();
58  void Empty ();
59 
60  void SetBufferSize (uint length);
61  uint GetBufferSize() { return BufferSize; }
62  uint GetByteCount() { return ByteCount; }
63  uint GetLineCount() { return LineCount; }
64  uint GetColumn() { return Column; }
65  uint GetWrapColumn () { return WrapColumn; }
66  void SetWrapColumn (uint column) { WrapColumn = column; }
67  uint GetIndent () { return IndentColumn; }
68  void SetIndent (uint column) { IndentColumn = column; }
69  char * GetBuffer () { return Buffer; }
70  void NewlinesToSpaces (bool b) { ConvertNewlines = b; }
71 
72  void AddTranslation (char ch, const char * str);
73  // void ClearTranslation (char ch) { Translation[ch] = NULL; }
74  // Changed ch to int, to avoid compiler warnings.
75  void ClearTranslation (int ch) { Translation[ch] = NULL; }
76  void ClearTranslations () { HasTranslations = false; }
77  void PauseTranslations () { PausedTranslations = true; }
78  void ResumeTranslations () { PausedTranslations = false; }
79 
80  errorT NewLine();
81  errorT Indent();
82  errorT PrintLine (const char * str);
83  errorT PrintWord (const char * str);
84  errorT PrintString (const char * str);
85  errorT PrintSpace ();
86  errorT PrintChar (char b);
87 
88  errorT PrintInt (uint i, const char * str);
89  inline errorT PrintInt (uint i) { return PrintInt (i, ""); }
90 
91 };
92 
93 inline void
94 TextBuffer::AddChar (char ch)
95 {
96  if (HasTranslations && !PausedTranslations) {
97  byte b = (byte) ch;
98  const char * str = Translation[b];
99  if (str != NULL) {
100  const char * s = str;
101  while (*s) {
102  *Current++ = *s++;
103  ByteCount++;
104  }
105  return;
106  }
107  }
108  *Current = ch;
109  Current++;
110  ByteCount++;
111 }
112 
113 #endif // SCID_TEXTBUF_H
114 
115 ///////////////////////////////////////////////////////////////////////////
116 // EOF: textbuf.h
117 ///////////////////////////////////////////////////////////////////////////
118 
unsigned char byte
Definition: common.h:89
uint GetLineCount()
Definition: textbuf.h:63
void ClearTranslation(int ch)
Definition: textbuf.h:75
void ClearTranslations()
Definition: textbuf.h:76
~TextBuffer()
Definition: textbuf.h:54
void PauseTranslations()
Definition: textbuf.h:77
uint GetIndent()
Definition: textbuf.h:67
void Init()
Definition: textbuf.cpp:21
void Free()
Definition: textbuf.cpp:35
void SetWrapColumn(uint column)
Definition: textbuf.h:66
uint GetWrapColumn()
Definition: textbuf.h:65
void NewlinesToSpaces(bool b)
Definition: textbuf.h:70
uint GetColumn()
Definition: textbuf.h:64
uint32_t uint
Definition: common.h:91
void SetIndent(uint column)
Definition: textbuf.h:68
errorT PrintLine(const char *str)
Definition: textbuf.cpp:135
errorT NewLine()
Definition: textbuf.cpp:98
uint GetBufferSize()
Definition: textbuf.h:61
unsigned short errorT
Definition: error.h:20
errorT PrintInt(uint i)
Definition: textbuf.h:89
void ResumeTranslations()
Definition: textbuf.h:78
errorT PrintWord(const char *str)
Definition: textbuf.cpp:151
TextBuffer()
Definition: textbuf.h:50
errorT PrintString(const char *str)
Definition: textbuf.cpp:200
errorT PrintChar(char b)
Definition: textbuf.cpp:187
uint GetByteCount()
Definition: textbuf.h:62
void SetBufferSize(uint length)
Definition: textbuf.cpp:80
void AddTranslation(char ch, const char *str)
Definition: textbuf.cpp:66
errorT PrintSpace()
Definition: textbuf.cpp:172
errorT PrintInt(uint i, const char *str)
Definition: textbuf.cpp:232
char * GetBuffer()
Definition: textbuf.h:69
errorT Indent()
Definition: textbuf.cpp:116
void Empty()
Definition: textbuf.cpp:51