1#include <bits/stdc++.h>
66template <
typename ValueType>
69 virtual void set(ValueType i) = 0;
73template <
typename ValueType>
76 virtual ValueType
get()
const = 0;
80template <
typename ValueType>
83 virtual void change(ValueType c) = 0;
87template <
typename ValueType>
96 void set(ValueType i)
override {
97 scoped_lock writer_lock(mtx);
101 ValueType get()
const override {
102 shared_lock reader_lock(mtx);
106 void change(ValueType c)
override {
107 scoped_lock writer_lock(mtx);
111 mutable shared_mutex mtx;
124 assert(g.get() == 1);
133 assert(g.
get() ==
"abc");
141 assert(g2.
get() ==
"abcde");
186#define SINGLETON(Singleton) \
189 static Singleton& instance() { \
190 static Singleton me; \
193 Singleton(const Singleton&) = delete; \
194 Singleton& operator=(const Singleton&) = delete; \
195 Singleton(Singleton&&) = delete; \
196 Singleton& operator=(Singleton&&) = delete; \
227 return make_unique<Sample_product>(123);
233 virtual unique_ptr<Interface>
create() = 0;
240 return make_unique<Sample_product>();
250 unique_ptr<Interface>
create()
override {
252 return unique_ptr<Interface>(clone);
278 auto product = factory->create();
284 assert(C.
client() == 123);
334 return this->subject.
method();
359 forward_list<reference_wrapper<Interface>>
children;
461 return string(__func__) +
" > " + visitor.
visit(*
this);
469string client_visit(
const forward_list<unique_ptr<Component>>& components,
470 const forward_list<unique_ptr<Visitor>>& visitors)
474 for (
auto&& comp : components)
475 for (
auto&& vis : visitors) {
476 res += string(__func__) +
" > " + comp->component_accept(*vis.get());
495 struct Sample_visitor
503 forward_list<unique_ptr<Component>> components;
506 forward_list<unique_ptr<Visitor>> visitors;
507 visitors.emplace_front(
new Sample_visitor);
509 "client_visit > component_accept > visit > component_method");
534 handlers.push_front(h);
536 handlers.push_back(h);
541 if ((rc = h.handle(cmnd)) >= 0)
546 list<reference_wrapper<Handler>> handlers;