diff --git a/README.md b/README.md index d51a3582..453599e0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![linux build](https://github.com/bkryza/clang-uml/actions/workflows/build.yml/badge.svg) -`clang-uml` is an automatic !(PlantUML)[https://plantuml.com/] class and sequence +`clang-uml` is an automatic ![PlantUML](https://plantuml.com/) class and sequence diagram generator, driven by YAML configuration files. The main idea behind the project is to easily maintain up-to-date diagrams within a code-base or document existing project code. The configuration file or files for `clang-uml` define the diff --git a/docs/test_cases/t00018.md b/docs/test_cases/t00018.md new file mode 100644 index 00000000..760615a8 --- /dev/null +++ b/docs/test_cases/t00018.md @@ -0,0 +1,136 @@ +# t00018 - Pimpl pattern +## Config +```yaml +compilation_database_dir: .. +output_directory: puml +diagrams: + t00018_class: + type: class + glob: + - ../../tests/t00018/**.h + - ../../tests/t00018/**.cc + using_namespace: + - clanguml::t00018 + include: + namespaces: + - clanguml::t00018 + +``` +## Source code +File t00018_impl.h +```cpp +#pragma once + +#include "t00018.h" + +namespace clanguml { +namespace t00018 { +namespace impl { + +class widget { + int n; + +public: + void draw(const clanguml::t00018::widget &w) const; + void draw(const clanguml::t00018::widget &w); + widget(int n); +}; +} +} +} + +``` +File t00018.h +```cpp +#pragma once + +#include +#include +#include + +namespace clanguml { +namespace t00018 { + +namespace impl { +class widget; +} + +// Pimpl example based on https://en.cppreference.com/w/cpp/language/pimpl +class widget { + std::unique_ptr pImpl; + +public: + void draw() const; + void draw(); + bool shown() const { return true; } + widget(int); + ~widget(); + + widget(widget &&); + + widget(const widget &) = delete; + widget &operator=(widget &&); + widget &operator=(const widget &) = delete; +}; +} +} + +``` +File t00018.cc +```cpp +#include "t00018.h" +#include "t00018_impl.h" + +namespace clanguml { +namespace t00018 { + +void widget::draw() const { pImpl->draw(*this); } + +void widget::draw() { pImpl->draw(*this); } + +widget::widget(int n) + : pImpl{std::make_unique(n)} +{ +} + +widget::widget(widget &&) = default; + +widget::~widget() = default; + +widget &widget::operator=(widget &&) = default; +} +} + +``` +File t00018_impl.cc +```cpp +#include "t00018_impl.h" +#include "t00018.h" + +namespace clanguml { +namespace t00018 { +namespace impl { + +widget::widget(int n) + : n(n) +{ +} + +void widget::draw(const clanguml::t00018::widget &w) const +{ + if (w.shown()) + std::cout << "drawing a const widget " << n << '\n'; +} + +void widget::draw(const clanguml::t00018::widget &w) +{ + if (w.shown()) + std::cout << "drawing a non-const widget " << n << '\n'; +} +} +} +} + +``` +## Generated UML diagrams +![t00018_class](./t00018_class.png "Pimpl pattern") diff --git a/docs/test_cases/t00018_class.png b/docs/test_cases/t00018_class.png new file mode 100644 index 00000000..a5911e01 Binary files /dev/null and b/docs/test_cases/t00018_class.png differ