Design Pattern Examples
Overview of object-oriented design patterns
Facade_Exercise.cpp
Go to the documentation of this file.
1
6
7#include <iostream>
8
9#include "helpers/formatstring.h"
10
11#include "Facade_Exercise.h"
13#include "Facade_Interface.h"
14
15namespace // Anonymous
16{
17 using namespace DesignPatternExamples_cpp;
18
25 void _Facade_ShowIdCodes(int chainIndex, const std::vector<uint32_t>& idcodes)
26 {
27 std::cout << Helpers::formatstring(" On chain %d, idcodes = [ ", chainIndex);
28 for (uint32_t idcode : idcodes)
29 {
30 std::cout << Helpers::formatstring("0x%X ", idcode);
31 }
32 std::cout << "]" << std::endl;
33 }
34
35} // end namespace Anonmyous
36
37
39{
40
57 // ! [Using Facade in C++]
59 {
60 std::cout << std::endl;
61 std::cout << "Facade Exercise" << std::endl;
62
64 int numChains = deviceChainFacade->NumChains();
65 std::cout
66 << " Showing idcodes of devices after a device reset (expect one device on each chain)..."
67 << std::endl;
68 for (int chainIndex = 0; chainIndex < numChains; ++chainIndex)
69 {
70 deviceChainFacade->DisableDevicesInDeviceChain(chainIndex);
71 std::vector<uint32_t> idcodes = deviceChainFacade->GetIdcodes(chainIndex);
72 _Facade_ShowIdCodes(chainIndex, idcodes);
73 }
74
75 std::cout << " Showing idcodes of devices after selecting all devices..."
76 << std::endl;
77 for (int chainIndex = 0; chainIndex < numChains; ++chainIndex)
78 {
79 deviceChainFacade->EnableDevicesInDeviceChain(chainIndex, 0xffffffff);
80 std::vector<uint32_t> idcodes = deviceChainFacade->GetIdcodes(chainIndex);
81 _Facade_ShowIdCodes(chainIndex, idcodes);
82 }
83
84 std::cout << " Done." << std::endl;
85 }
86 // ! [Using Facade in C++]
87
88} // end namespace
static void _Facade_ShowIdCodes(int chainIndex, UIntArray *idcodes)
Helper function to present a formatted list of idcodes for a particular device chain....
Declaration of the IDeviceNetworkLowLevel interface representing the complicated sub-system used in t...
Declaration of the Facade_Exercise() function as used in the Facade Pattern.
Declaration of the IDeviceNetworkHighLevel interface representing the high-level system used in the F...
The namespace containing all Design Pattern Examples implemented in C++.
IDeviceNetworkHighLevel * CreateHighLevelInstance()
Class factory for a singleton instance of the IDeviceNetworkHighLevel interface. Part of the Facade P...
void Facade_Exercise()
Example of using the Facade design pattern.
std::string formatstring(const char *fmt,...)
Use the given string and arguments to return a buffer containing the formatted string....
Represents a high level view of a complex network of device chains. A device chain can be thought of ...
virtual void EnableDevicesInDeviceChain(int chainIndex, uint32_t selectMask)=0
Make visible certain devices in the given device chain. The selectMask value has a bit set for each T...
virtual void DisableDevicesInDeviceChain(int chainIndex)=0
Resets the given device chain so that all devices except the TAP controller is no longer visible.
virtual std::vector< uint32_t > GetIdcodes(int chainIndex)=0
Returns a list of all idcodes from all selected devices in the given device chain.
virtual int NumChains()=0
The number of device chains available from the sub-system.