Added template decorator pattern
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
* [t00024](./test_cases/t00024.md) - Proxy pattern
|
||||
* [t00025](./test_cases/t00025.md) - Template proxy pattern
|
||||
* [t00026](./test_cases/t00026.md) - Template memento pattern
|
||||
* [t00027](./test_cases/t00027.md) - Template decorator pattern
|
||||
## Sequence diagrams
|
||||
* [t20001](./test_cases/t20001.md) - Basic sequence diagram
|
||||
## Configuration diagrams
|
||||
|
||||
@@ -74,7 +74,6 @@ struct StringMemento {
|
||||
Caretaker<std::string> caretaker;
|
||||
Originator<std::string> originator;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
79
docs/test_cases/t00027.md
Normal file
79
docs/test_cases/t00027.md
Normal file
@@ -0,0 +1,79 @@
|
||||
# t00027 - Template decorator pattern
|
||||
## Config
|
||||
```yaml
|
||||
compilation_database_dir: ..
|
||||
output_directory: puml
|
||||
diagrams:
|
||||
t00027_class:
|
||||
type: class
|
||||
glob:
|
||||
- ../../tests/t00027/t00027.cc
|
||||
using_namespace:
|
||||
- clanguml::t00027
|
||||
include:
|
||||
namespaces:
|
||||
- clanguml::t00027
|
||||
|
||||
```
|
||||
## Source code
|
||||
File t00027.cc
|
||||
```cpp
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
|
||||
namespace clanguml {
|
||||
namespace t00027 {
|
||||
|
||||
class Shape {
|
||||
public:
|
||||
virtual void display() = 0;
|
||||
virtual ~Shape() = default;
|
||||
};
|
||||
|
||||
template <template <typename> class... T>
|
||||
class Line : public Shape, public T<Line<>>... {
|
||||
public:
|
||||
void display() override
|
||||
{
|
||||
std::apply([](auto &&... x) { (x.display(), ...); },
|
||||
std::forward_as_tuple(T<Line<>>()...));
|
||||
}
|
||||
};
|
||||
|
||||
template <template <typename> class... T>
|
||||
class Text : public Shape, public T<Text<>>... {
|
||||
public:
|
||||
void display() override
|
||||
{
|
||||
std::apply([](auto &&... x) { (x.display(), ...); },
|
||||
std::forward_as_tuple(T<Text<>>()...));
|
||||
}
|
||||
};
|
||||
|
||||
struct ShapeDecorator {
|
||||
virtual void display() = 0;
|
||||
};
|
||||
|
||||
template <typename T> class Color : public ShapeDecorator {
|
||||
public:
|
||||
void display() override {}
|
||||
};
|
||||
|
||||
template <typename T> class Weight : public ShapeDecorator {
|
||||
public:
|
||||
void display() override {}
|
||||
};
|
||||
|
||||
struct Window {
|
||||
Line<Color, Weight> border;
|
||||
Line<Color> divider;
|
||||
Text<Color, Weight> title;
|
||||
Text<Color> description;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
## Generated UML diagrams
|
||||

|
||||
BIN
docs/test_cases/t00027_class.png
Normal file
BIN
docs/test_cases/t00027_class.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 43 KiB |
Reference in New Issue
Block a user