Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added initial version of Flyweight, which compiles but is not compl…
…ete yet.
- Loading branch information
1 parent
be1c991
commit c50a0f5
Showing
16 changed files
with
279 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include_directories(../../Foundation_Classes) | ||
#include_directories(../../Behavioral_Patterns/Iterator) | ||
|
||
set(flyweight_SRCS | ||
Character.cpp | ||
Font.cpp | ||
Glyph.cpp | ||
GlyphContext.cpp | ||
GlyphFactory.cpp) | ||
|
||
add_executable(flyweight1 flyweight1.cpp) | ||
add_library(flyweight SHARED ${flyweight_SRCS}) | ||
target_link_libraries(flyweight1 flyweight) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include "Character.h" | ||
|
||
Character::Character(char charcode) | ||
: _charcode(charcode) | ||
{} | ||
|
||
void Character::Draw(Window*, GlyphContext&) | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef CHARACTER_H | ||
#define CHARACTER_H | ||
|
||
#include "Glyph.h" | ||
|
||
class Window; | ||
class GlyphContext; | ||
|
||
class Character : public Glyph { | ||
public: | ||
Character(char); | ||
|
||
virtual void Draw(Window*, GlyphContext&); | ||
private: | ||
char _charcode; | ||
}; | ||
|
||
#endif /* CHARACTER_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#ifndef COLUMN_H | ||
#define COLUMN_H | ||
|
||
class Column { | ||
}; | ||
|
||
#endif /* COLUMN_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include "Font.h" | ||
|
||
Font::Font(char* name) | ||
: _name(name) | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ifndef FONT_H | ||
#define FONT_H | ||
|
||
class Font { | ||
public: | ||
Font(char*); | ||
private: | ||
char* _name; | ||
}; | ||
|
||
#endif /* FONT_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include "Glyph.h" | ||
|
||
#include <iostream> | ||
using namespace std; | ||
|
||
Glyph::Glyph() | ||
{ | ||
cout << "Glyph::Glyph()" << endl; | ||
} | ||
|
||
Glyph::~Glyph() | ||
{ | ||
cout << "Glyph::~Glyph()" << endl; | ||
} | ||
|
||
void Glyph::Draw(Window*, GlyphContext&) | ||
{ | ||
cout << "Glyph::Draw(Window*, GlyphContext&)" << endl; | ||
} | ||
|
||
void Glyph::SetFont(Font*, GlyphContext&) | ||
{ | ||
cout << "Glyph::SetFont(Font*, GlyphContext&)" << endl; | ||
} | ||
|
||
Font* Glyph::GetFont(GlyphContext&) | ||
{ | ||
cout << "Glyph::GetFont(GlyphContext&)" << endl; | ||
return 0; | ||
} | ||
|
||
void Glyph::First(GlyphContext&){ | ||
cout << "Glyph::First(GlyphContext&)" << endl; | ||
} | ||
|
||
void Glyph::Next(GlyphContext&) | ||
{ | ||
cout << "Glyph::Next(GlyphContext&)" << endl; | ||
} | ||
|
||
bool Glyph::IsDone(GlyphContext&) | ||
{ | ||
cout << "Glyph::IsDone(GlyphContext&)" << endl; | ||
return 0; | ||
} | ||
|
||
Glyph* Glyph::Current(GlyphContext&) | ||
{ | ||
cout << "Glyph* Glyph::Current(GlyphContext&)" << endl; | ||
return 0; | ||
} | ||
|
||
void Glyph::Insert(Glyph*, GlyphContext&) | ||
{ | ||
cout << "void Glyph::Insert(Glyph*, GlyphContext&)" << endl; | ||
} | ||
|
||
void Glyph::Remove(GlyphContext&) | ||
{ | ||
cout << "void Glyph::Remove(GlyphContext&)" << endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef GLYPH_H | ||
#define GLYPH_H | ||
|
||
class GlyphContext; | ||
class Font; | ||
class Window; | ||
|
||
class Glyph { | ||
public: | ||
virtual ~Glyph(); | ||
|
||
virtual void Draw(Window*, GlyphContext&); | ||
|
||
virtual void SetFont(Font*, GlyphContext&); | ||
virtual Font* GetFont(GlyphContext&); | ||
|
||
virtual void First(GlyphContext&); | ||
virtual void Next(GlyphContext&); | ||
virtual bool IsDone(GlyphContext&); | ||
virtual Glyph* Current(GlyphContext&); | ||
|
||
virtual void Insert(Glyph*, GlyphContext&); | ||
virtual void Remove(GlyphContext&); | ||
protected: | ||
Glyph(); | ||
}; | ||
|
||
#endif /* GLYPH_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// TODO: implement these. | ||
#include "GlyphContext.h" | ||
|
||
GlyphContext::GlyphContext() | ||
{} | ||
|
||
GlyphContext::~GlyphContext() | ||
{} | ||
|
||
void GlyphContext::Next(int step) | ||
{} | ||
|
||
void GlyphContext::Insert(int quantity1) | ||
{} | ||
|
||
Font* GlyphContext::GetFont() | ||
{ | ||
// TODO | ||
return 0; | ||
} | ||
|
||
void GlyphContext::SetFont(Font*, int span) | ||
{} | ||
|
||
// int _index; | ||
// BTree* _fonts; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef GLYPH_CONTEXT_H | ||
#define GLYPH_CONTEXT_H | ||
|
||
class BTree; | ||
class Font; | ||
|
||
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; | ||
}; | ||
|
||
#endif /* GLYPH_CONTEXT_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "GlyphFactory.h" | ||
#include "Character.h" | ||
#include "Row.h" | ||
#include "Column.h" | ||
|
||
GlyphFactory::GlyphFactory() | ||
{ | ||
for (int i = 0; i < NCHARCODES; ++i) { | ||
_character[i] = 0; | ||
} | ||
} | ||
|
||
GlyphFactory:: ~GlyphFactory() | ||
{ | ||
delete[] _character; | ||
} | ||
|
||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef GLYPH_FACTORY_H | ||
#define GLYPH_FACTORY_H | ||
|
||
class Character; | ||
class Column; | ||
class Row; | ||
|
||
const int NCHARCODES = 128; | ||
|
||
class GlyphFactory { | ||
public: | ||
GlyphFactory(); | ||
virtual ~GlyphFactory(); | ||
|
||
virtual Character* CreateCharacter(char); | ||
virtual Row* CreateRow(); | ||
virtual Column* CreateColumn(); | ||
// ... | ||
private: | ||
Character* _character[NCHARCODES]; | ||
}; | ||
|
||
#endif /* GLYPH_FACTORY_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#ifndef ROW_H | ||
#define ROW_H | ||
|
||
class Row { | ||
}; | ||
|
||
#endif /* ROW_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include "Font.h" | ||
#include "GlyphContext.h" | ||
|
||
int main() | ||
{ | ||
GlyphContext gc; | ||
Font* times12 = new Font("Times-Roman-12"); | ||
Font* timesItalic12 = new Font("Times-Italic-12"); | ||
// ... | ||
|
||
gc.SetFont(times12, 6); | ||
|
||
gc.Insert(6); | ||
gc.SetFont(timesItalic12, 6); | ||
} |