Line data Source code
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 :
22 : class TextBuffer
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:
50 1 : TextBuffer() {
51 1 : Init();
52 1 : SetBufferSize(1280000);
53 1 : }
54 1 : ~TextBuffer() { Free(); }
55 :
56 : void Init ();
57 : void Free ();
58 : void Empty ();
59 :
60 : void SetBufferSize (uint length);
61 0 : uint GetBufferSize() { return BufferSize; }
62 2037 : uint GetByteCount() { return ByteCount; }
63 : uint GetLineCount() { return LineCount; }
64 : uint GetColumn() { return Column; }
65 2037 : uint GetWrapColumn () { return WrapColumn; }
66 6111 : void SetWrapColumn (uint column) { WrapColumn = column; }
67 0 : uint GetIndent () { return IndentColumn; }
68 0 : void SetIndent (uint column) { IndentColumn = column; }
69 2037 : char * GetBuffer () { return Buffer; }
70 4074 : 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 1 : void ClearTranslation (int ch) { Translation[ch] = NULL; }
76 : void ClearTranslations () { HasTranslations = false; }
77 0 : void PauseTranslations () { PausedTranslations = true; }
78 0 : 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 0 : inline errorT PrintInt (uint i) { return PrintInt (i, ""); }
90 :
91 : };
92 :
93 : inline void
94 44219079 : TextBuffer::AddChar (char ch)
95 : {
96 44219079 : if (HasTranslations && !PausedTranslations) {
97 0 : byte b = (byte) ch;
98 0 : const char * str = Translation[b];
99 0 : if (str != NULL) {
100 0 : const char * s = str;
101 0 : while (*s) {
102 0 : *Current++ = *s++;
103 0 : ByteCount++;
104 : }
105 0 : return;
106 : }
107 : }
108 44219079 : *Current = ch;
109 44219079 : Current++;
110 44219079 : ByteCount++;
111 : }
112 :
113 : #endif // SCID_TEXTBUF_H
114 :
115 : ///////////////////////////////////////////////////////////////////////////
116 : // EOF: textbuf.h
117 : ///////////////////////////////////////////////////////////////////////////
118 :
|