# t00018 - Pimpl pattern
## Config
```yaml
compilation_database_dir: ..
output_directory: puml
diagrams:
  t00018_class:
    type: class
    glob:
      - ../../tests/t00018/**.cc
    using_namespace:
      - clanguml::t00018
    include:
      namespaces:
        - clanguml::t00018

```
## Source code
File t00018.h
```cpp
#pragma once

#ifndef _MSC_VER
#include <experimental/propagate_const>
#endif
#include <iostream>
#include <memory>

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<impl::widget> 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_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.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<impl::widget>(n)}
{
}

widget::widget(widget &&) = default;

widget::~widget() = default;

widget &widget::operator=(widget &&) = default;
} // namespace t00018
} // namespace clanguml

```
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';
}
} // namespace impl
} // namespace t00018
} // namespace clanguml

```
## Generated UML diagrams
![t00018_class](./t00018_class.svg "Pimpl pattern")
## Generated JSON models
```json
{
  "diagram_type": "class",
  "elements": [
    {
      "bases": [],
      "display_name": "clanguml::t00018::impl::widget",
      "id": "130502639682787993",
      "is_abstract": false,
      "is_nested": false,
      "is_struct": false,
      "is_template": false,
      "is_union": false,
      "members": [
        {
          "access": "private",
          "is_static": false,
          "name": "n",
          "source_location": {
            "file": "../../tests/t00018/t00018_impl.h",
            "line": 10
          },
          "type": "int"
        }
      ],
      "methods": [
        {
          "access": "public",
          "is_const": true,
          "is_defaulted": false,
          "is_implicit": false,
          "is_pure_virtual": false,
          "is_static": false,
          "is_virtual": false,
          "name": "draw",
          "parameters": [
            {
              "name": "w",
              "type": "const clanguml::t00018::widget &"
            }
          ],
          "type": "void"
        },
        {
          "access": "public",
          "is_const": false,
          "is_defaulted": false,
          "is_implicit": false,
          "is_pure_virtual": false,
          "is_static": false,
          "is_virtual": false,
          "name": "draw",
          "parameters": [
            {
              "name": "w",
              "type": "const clanguml::t00018::widget &"
            }
          ],
          "type": "void"
        },
        {
          "access": "public",
          "is_const": false,
          "is_defaulted": false,
          "is_implicit": false,
          "is_pure_virtual": false,
          "is_static": false,
          "is_virtual": false,
          "name": "widget",
          "parameters": [
            {
              "name": "n",
              "type": "int"
            }
          ],
          "type": "void"
        }
      ],
      "name": "widget",
      "namespace": "clanguml::t00018::impl",
      "source_location": {
        "file": "../../tests/t00018/t00018_impl.h",
        "line": 9
      },
      "template_parameters": [],
      "type": "class"
    },
    {
      "bases": [],
      "display_name": "clanguml::t00018::widget",
      "id": "1005661284373854088",
      "is_abstract": false,
      "is_nested": false,
      "is_struct": false,
      "is_template": false,
      "is_union": false,
      "members": [
        {
          "access": "private",
          "is_static": false,
          "name": "pImpl",
          "source_location": {
            "file": "../../tests/t00018/t00018.h",
            "line": 18
          },
          "type": "std::unique_ptr<impl::widget>"
        }
      ],
      "methods": [
        {
          "access": "public",
          "is_const": true,
          "is_defaulted": false,
          "is_implicit": false,
          "is_pure_virtual": false,
          "is_static": false,
          "is_virtual": false,
          "name": "draw",
          "parameters": [],
          "type": "void"
        },
        {
          "access": "public",
          "is_const": false,
          "is_defaulted": false,
          "is_implicit": false,
          "is_pure_virtual": false,
          "is_static": false,
          "is_virtual": false,
          "name": "draw",
          "parameters": [],
          "type": "void"
        },
        {
          "access": "public",
          "is_const": true,
          "is_defaulted": false,
          "is_implicit": false,
          "is_pure_virtual": false,
          "is_static": false,
          "is_virtual": false,
          "name": "shown",
          "parameters": [],
          "type": "bool"
        },
        {
          "access": "public",
          "is_const": false,
          "is_defaulted": false,
          "is_implicit": false,
          "is_pure_virtual": false,
          "is_static": false,
          "is_virtual": false,
          "name": "widget",
          "parameters": [
            {
              "name": "",
              "type": "int"
            }
          ],
          "type": "void"
        },
        {
          "access": "public",
          "is_const": false,
          "is_defaulted": false,
          "is_implicit": false,
          "is_pure_virtual": false,
          "is_static": false,
          "is_virtual": false,
          "name": "~widget",
          "parameters": [],
          "type": "void"
        },
        {
          "access": "public",
          "is_const": false,
          "is_defaulted": false,
          "is_implicit": false,
          "is_pure_virtual": false,
          "is_static": false,
          "is_virtual": false,
          "name": "widget",
          "parameters": [
            {
              "name": "",
              "type": "clanguml::t00018::widget &&"
            }
          ],
          "type": "void"
        },
        {
          "access": "public",
          "is_const": false,
          "is_defaulted": false,
          "is_implicit": false,
          "is_pure_virtual": false,
          "is_static": false,
          "is_virtual": false,
          "name": "widget",
          "parameters": [
            {
              "name": "",
              "type": "const clanguml::t00018::widget &"
            }
          ],
          "type": "void"
        },
        {
          "access": "public",
          "is_const": false,
          "is_defaulted": false,
          "is_implicit": false,
          "is_pure_virtual": false,
          "is_static": false,
          "is_virtual": false,
          "name": "operator=",
          "parameters": [
            {
              "name": "",
              "type": "clanguml::t00018::widget &&"
            }
          ],
          "type": "clanguml::t00018::widget &"
        },
        {
          "access": "public",
          "is_const": false,
          "is_defaulted": false,
          "is_implicit": false,
          "is_pure_virtual": false,
          "is_static": false,
          "is_virtual": false,
          "name": "operator=",
          "parameters": [
            {
              "name": "",
              "type": "const clanguml::t00018::widget &"
            }
          ],
          "type": "clanguml::t00018::widget &"
        }
      ],
      "name": "widget",
      "namespace": "clanguml::t00018",
      "source_location": {
        "file": "../../tests/t00018/t00018.h",
        "line": 17
      },
      "template_parameters": [],
      "type": "class"
    }
  ],
  "metadata": {
    "clang_uml_version": "0.3.5-27-g81c7ce7",
    "llvm_version": "Ubuntu clang version 15.0.6",
    "schema_version": 1
  },
  "name": "t00018_class",
  "relationships": [
    {
      "access": "public",
      "destination": "1005661284373854088",
      "source": "130502639682787993",
      "type": "dependency"
    },
    {
      "access": "private",
      "destination": "130502639682787993",
      "label": "pImpl",
      "source": "1005661284373854088",
      "type": "aggregation"
    }
  ],
  "using_namespace": "clanguml::t00018"
}
```
