-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShape.h
35 lines (26 loc) · 762 Bytes
/
Shape.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#pragma once
#include <memory>
#include <iostream>
#include <any>
class Shape {
struct ShapeConcept {
virtual void drawCall(const std::any&) = 0;
};
template<typename T>
struct ShapeModel : public ShapeConcept {
T shape;
explicit ShapeModel(T &&s) : shape(std::move(s)) {}
explicit ShapeModel(const T &s) : shape(s) {}
void drawCall(const std::any& a) override {
draw(shape, a);
}
};
std::unique_ptr<ShapeConcept> shapePtr;
public:
template<typename T>
explicit Shape(const T &shape): shapePtr(new ShapeModel<T>(shape)) {}
Shape(Shape &&) = default;
friend void draw(const Shape &shape, const std::any& a) {
shape.shapePtr->drawCall(a);
}
};