C++ features by examples
Chain_of_responsibility Struct Reference

list based implementation without recursion More...

Inheritance diagram for Chain_of_responsibility:
Collaboration diagram for Chain_of_responsibility:

Public Member Functions

void register_handler (Handler &&h, bool front=false)
 
int handle (Command &cmnd) override
 Specific handler can process a command and return non-negative. More...
 
- Public Member Functions inherited from Handler
virtual int handle (Command &cmnd)
 Specific handler can process a command and return non-negative. More...
 
virtual ~Handler ()=default
 

Detailed Description

list based implementation without recursion

Chain-of-responsibility pattern

https://refactoring.guru/design-patterns/chain-of-responsibility

Definition at line 522 of file patterns.cpp.

Member Function Documentation

◆ handle()

int Chain_of_responsibility::handle ( Command cmnd)
inlineoverridevirtual

Specific handler can process a command and return non-negative.

Reimplemented from Handler.

Definition at line 538 of file patterns.cpp.

538 {
539 int rc = -1;
540 for (Handler& h : handlers)
541 if ((rc = h.handle(cmnd)) >= 0)
542 return rc;
543 return rc;
544 }
is a virtual command handler of Chain_of_responsibility
Definition: patterns.cpp:516
Here is the caller graph for this function:

◆ register_handler()

void Chain_of_responsibility::register_handler ( Handler &&  h,
bool  front = false 
)
inline

Definition at line 532 of file patterns.cpp.

532 {
533 if (front)
534 handlers.push_front(h);
535 else
536 handlers.push_back(h);
537 }
Here is the caller graph for this function:

The documentation for this struct was generated from the following file: