-
Notifications
You must be signed in to change notification settings - Fork 11
/
GoF.h
94 lines (73 loc) · 1.7 KB
/
GoF.h
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
#pragma once
namespace FlyweightPattern::GoF
{
class Window;
class GlyphContext;
class Font;
class Glyph {
public:
virtual ~Glyph() {}
virtual void Draw(Window*, GlyphContext&) {}
virtual void SetFont(Font*, GlyphContext&) {}
virtual Font* GetFont(GlyphContext&) { return nullptr; }
virtual void First(GlyphContext&) {}
virtual void Next(GlyphContext&) {}
virtual bool IsDone(GlyphContext&) { return true; }
virtual Glyph* Current(GlyphContext&) { return nullptr; }
virtual void Insert(Glyph*, GlyphContext&) {}
virtual void Remove(GlyphContext&) {}
protected:
Glyph() {}
};
class Character : public Glyph {
public:
Character(char) {}
virtual void Draw(Window*, GlyphContext&) {}
private:
char _charcode;
};
class BTree;
class GlyphContext {
public:
GlyphContext() {}
virtual ~GlyphContext() {}
virtual void Next(int step = 1) {}
virtual void Insert(int quantity = 1) {}
virtual Font* GetFont() {}
virtual void SetFont(Font*, int span = 1) {}
private:
int _index;
BTree* _fonts;
};
class Row {};
class Column {};
const int NCHARCODES = 128;
class GlyphFactory {
public:
GlyphFactory();
virtual ~GlyphFactory() {}
virtual Character* CreateCharacter(char);
virtual Row* CreateRow();
virtual Column* CreateColumn();
// ...
private:
Character* _character[NCHARCODES];
};
GlyphFactory::GlyphFactory() {
for (int i = 0; i < NCHARCODES; ++i) {
_character[i] = 0;
}
}
Character* GlyphFactory::CreateCharacter(char c) {
if (!_character[c]) {
_character[c] = new Character(c);
}
return _character[c];
}
Row* GlyphFactory::CreateRow() {
return new Row;
}
Column* GlyphFactory::CreateColumn() {
return new Column;
}
}