Line data Source code
1 : #pragma once 2 : 3 : #include <string> 4 : #include "compile_export.hpp" 5 : #include "proxy/proxy.h" 6 : 7 : #define STRINGIFY(x) #x 8 : #define MACRO_STRINGIFY(x) STRINGIFY(x) 9 : 10 : namespace compile { 11 : namespace geo { 12 : 13 : // proxy-runtime-polymorphism,see 14 : // https://github.com/microsoft/proxy 15 : // https://devblogs.microsoft.com/cppblog/proxy-runtime-polymorphism-made-easier-than-ever/ 16 : 17 : // Abstraction Draw interface for polymorphic call 18 : struct compile_EXPORT Draw : pro::dispatch<void(std::ostream&)> { 19 : public: 20 : template <class T> 21 1 : void operator()(const T& self, std::ostream& out) { 22 1 : self.Draw(out); 23 1 : } 24 : }; 25 : 26 : // Abstraction Area interface for polymorphic call 27 : struct compile_EXPORT Area : pro::dispatch<double()> { 28 : public: 29 : template <class T> 30 1 : double operator()(const T& self) { 31 1 : return self.Area(); 32 : } 33 : }; 34 : 35 : // Interface facade for Draw, Area 36 : struct compile_EXPORT DrawableFacade : pro::facade<Draw, Area> {}; 37 : 38 : // Client API - Consumer 39 : std::string compile_EXPORT PrintDrawableToString(const pro::proxy<DrawableFacade>& p); 40 : 41 : // Client API - Producer 42 : pro::proxy<DrawableFacade> compile_EXPORT CreateRectangleAsDrawable(int width, int height); 43 : 44 : }; // namespace geo 45 : }; // namespace compile