File: Area.h

package info (click to toggle)
html2text 1.3.2a-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 736 kB
  • ctags: 1,694
  • sloc: cpp: 9,311; yacc: 828; sh: 209; makefile: 144
file content (191 lines) | stat: -rw-r--r-- 5,319 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191

 /***************************************************************************/

/*
 * Portions Copyright (c) 1999 GMRS Software GmbH
 * Carl-von-Linde-Str. 38, D-85716 Unterschleissheim, http://www.gmrs.de
 * All rights reserved.
 *
 * Author: Arno Unkrig <arno@unkrig.de>
 */
 
/* This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License in the file COPYING for more details.
 */

 /***************************************************************************/

/*
 * Changes to version 1.2.2 were made by Martin Bayer <mbayer@zedat.fu-berlin.de>
 * Dates and reasons of modifications:
 * Thu Oct  4 21:21:10 CEST 2001: ported to g++ 3.0
 * Wed Jul  2 21:59:41 CEST 2003: ported to g++ 3.3
 */
  
 /***************************************************************************/

 
#ifndef __Area_h_INCLUDED__ /* { */
#define __Area_h_INCLUDED__

/* ------------------------------------------------------------------------- */


#include <sys/types.h>
#include <string>
#include <istream>

#ifdef BOOL_DEFINITION
BOOL_DEFINITION
#undef BOOL_DEFINITION
#endif

using std::string;
using std::ostream;


/* ------------------------------------------------------------------------- */

struct Cell {
  char character;
  char attribute;

  enum { NONE = 0, UNDERLINE = 1, BOLD = 2, STRIKETHROUGH = 4 };

  void clear() { character = ' '; attribute = NONE; }
};

/* ------------------------------------------------------------------------- */

class Line {

public:
  typedef size_t size_type;

  Line(size_type l = 0);
  Line(const char *);
  Line(const string &);
  ~Line();

  size_type length() const { return length_;      }
  bool      empty()  const { return length_ == 0; }

  const Cell &operator[](size_type x) const { return cells_[x]; }
  Cell       &operator[](size_type x)       { return cells_[x]; }
  const Cell *cells() const { return cells_; }

  void resize(size_type l);
  void enlarge(size_type l) { if (l > length_) resize(l); }

  void insert(const Line &, size_type x);
  void insert(const char *, size_type x);
  void insert(const string &, size_type x);

  void append(char       c );
  void append(const Line &l);
  void append(const char *p);

  const Line &operator+=(char       c ) { append(c); return *this; }
  const Line &operator+=(const Line &l) { append(l); return *this; }
  const Line &operator+=(const char *p) { append(p); return *this; }

  void add_attribute(char addition);

private:
  Line(const Line &);
  const Line &operator=(const Line &);

  size_type length_;
  Cell      *cells_;

  friend class Area;
};

/* ------------------------------------------------------------------------- */

class Area {

public:
  typedef size_t size_type;

  enum {
    LEFT, CENTER, RIGHT,
    TOP, MIDDLE, BOTTOM
  };

  Area();
  Area(size_type w, size_type h = 0, char = ' ', char = Cell::NONE);
  Area(const char *);
  Area(const string &);
  Area(const Line &);
  ~Area();

  size_type width() const { return width_; }
  size_type height() const { return height_; }

  const Cell *operator[](size_type y) const { return cells_[y]; }
  Cell       *operator[](size_type y)       { return cells_[y]; }
  const Area &operator>>=(size_type rs);

  void resize(size_type w, size_type h);
  void enlarge(size_type w, size_type h);

  void insert(const Line &l, size_type x, size_type y)
                                  { insert(l.cells_, l.length_, x, y); }
  void insert(const Area &, size_type x, size_type y);
  void insert(
    const Area &,
    size_type  x,
    size_type  y,
    size_type  w,
    size_type  h,
    int        halign,
    int        valign
  );
  void insert(const Cell &, size_type x, size_type y);
  void insert(const Cell *, size_type count, size_type x, size_type y);
  void insert(char, size_type x, size_type y);
  void insert(const string &, size_type x, size_type y);
  void prepend(int n);    // Prepend blank lines at top
  void append(int n)      // Append blank lines at bottom
                { enlarge(width(), height() + n); }
  const Area &operator+=(const Area &);   // Append at bottom!
  const Area &operator+=(int n) { append(n); return *this; }

  void fill(const Cell &, size_type x, size_type y, size_type w, size_type h);
  void fill(char,         size_type x, size_type y, size_type w, size_type h);

  void add_attribute(char addition); // ...but not to left and right free areas
  void add_attribute(
    char      addition,
    size_type x,
    size_type y,
    size_type w,
    size_type h
  );
  static bool use_backspaces; // "true" by default.

private:
  Area(const Area &);
  const Area &operator=(const Area &);

  size_type width_;
  size_type height_;
  Cell      **cells_;

  friend ostream &operator<<(ostream &, const Area &);
};

/* ------------------------------------------------------------------------- */

#endif /* } */

/* ------------------------------------------------------------------------- */