Added layer cake patter
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
* [t00016](./test_cases/t00016.md) - Unnamed enums and empty templates
|
||||
* [t00017](./test_cases/t00017.md) - Test include relations also as members flag
|
||||
* [t00018](./test_cases/t00018.md) - Pimpl pattern
|
||||
* [t00019](./test_cases/t00019.md) - Layercake pattern
|
||||
## Sequence diagrams
|
||||
* [t20001](./test_cases/t20001.md) - Basic sequence diagram
|
||||
## Configuration diagrams
|
||||
|
||||
160
docs/test_cases/t00019.md
Normal file
160
docs/test_cases/t00019.md
Normal file
@@ -0,0 +1,160 @@
|
||||
# t00019 - Layercake pattern
|
||||
## Config
|
||||
```yaml
|
||||
compilation_database_dir: ..
|
||||
output_directory: puml
|
||||
diagrams:
|
||||
t00019_class:
|
||||
type: class
|
||||
glob:
|
||||
- ../../tests/t00019/**.h
|
||||
- ../../tests/t00019/**.cc
|
||||
using_namespace:
|
||||
- clanguml::t00019
|
||||
include:
|
||||
namespaces:
|
||||
- clanguml::t00019
|
||||
plantuml:
|
||||
after:
|
||||
- '@A(Base) <|-- @A(Layer3<LowerLayer>)'
|
||||
- '@A(Layer3<LowerLayer>) <|-- @A(Layer2<LowerLayer>)'
|
||||
- '@A(Layer2<LowerLayer>) <|-- @A(Layer1<LowerLayer>)'
|
||||
|
||||
```
|
||||
## Source code
|
||||
File t00019_layer2.h
|
||||
```cpp
|
||||
#pragma once
|
||||
|
||||
namespace clanguml {
|
||||
namespace t00019 {
|
||||
|
||||
template <typename LowerLayer> class Layer2 : public LowerLayer {
|
||||
|
||||
using LowerLayer::LowerLayer;
|
||||
|
||||
using LowerLayer::m1;
|
||||
|
||||
using LowerLayer::m2;
|
||||
|
||||
int all_calls_count() const
|
||||
{
|
||||
return LowerLayer::m1_calls() + LowerLayer::m2_calls();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
File t00019_base.h
|
||||
```cpp
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace clanguml {
|
||||
namespace t00019 {
|
||||
|
||||
class Base {
|
||||
|
||||
Base() = default;
|
||||
|
||||
virtual ~Base() = default;
|
||||
|
||||
virtual int m1() { return 2; }
|
||||
|
||||
virtual std::string m2() { return "two"; }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
File t00019_layer1.h
|
||||
```cpp
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
namespace clanguml {
|
||||
namespace t00019 {
|
||||
|
||||
template <typename LowerLayer> class Layer1 : public LowerLayer {
|
||||
|
||||
using LowerLayer::LowerLayer;
|
||||
|
||||
int m1() override
|
||||
{
|
||||
std::cout << "m1 called\n";
|
||||
return LowerLayer::m1();
|
||||
}
|
||||
|
||||
std::string m2() override
|
||||
{
|
||||
std::cout << "m2 called\n";
|
||||
return LowerLayer::m2();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
File t00019.cc
|
||||
```cpp
|
||||
#include "t00019_base.h"
|
||||
#include "t00019_layer1.h"
|
||||
#include "t00019_layer2.h"
|
||||
#include "t00019_layer3.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace clanguml {
|
||||
namespace t00019 {
|
||||
|
||||
class A {
|
||||
public:
|
||||
std::unique_ptr<Layer1<Layer2<Layer3<Base>>>> layers;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
File t00019_layer3.h
|
||||
```cpp
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace clanguml {
|
||||
namespace t00019 {
|
||||
|
||||
template <typename LowerLayer> class Layer3 : public LowerLayer {
|
||||
|
||||
using LowerLayer::LowerLayer;
|
||||
|
||||
virtual int m1() override
|
||||
{
|
||||
m_m1_calls++;
|
||||
return LowerLayer::m1();
|
||||
}
|
||||
|
||||
virtual std::string m2() override
|
||||
{
|
||||
m_m2_calls++;
|
||||
return LowerLayer::m2();
|
||||
}
|
||||
|
||||
int m1_calls() const { return m_m1_calls; }
|
||||
|
||||
int m2_calls() const { return m_m2_calls; }
|
||||
|
||||
private:
|
||||
int m_m1_calls{};
|
||||
int m_m2_calls{};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
## Generated UML diagrams
|
||||

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