add iterable
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include "iterators.h"
|
||||
|
||||
class IShape {
|
||||
IShape* next = nullptr;
|
||||
IShape* prev = nullptr;
|
||||
|
||||
public:
|
||||
virtual ~IShape() = default;
|
||||
virtual void draw() const = 0;
|
||||
virtual double area() const = 0;
|
||||
|
||||
void set_next(IShape* n) {
|
||||
next = n;
|
||||
if (n) n->prev = this;
|
||||
}
|
||||
|
||||
IShape* get_next() const { return next; }
|
||||
IShape* get_prev() const { return prev; }
|
||||
|
||||
template<typename Policy>
|
||||
Traversal<IShape, Policy> traverse() {
|
||||
return Traversal<IShape, Policy>(this);
|
||||
}
|
||||
|
||||
using forward = IteratorForward<IShape>;
|
||||
using backward = IteratorBackward<IShape>;
|
||||
};
|
||||
|
||||
class Circle : public IShape {
|
||||
double r;
|
||||
public:
|
||||
Circle(double radius) : r(radius) {}
|
||||
|
||||
void draw() const override {
|
||||
std::cout << "Drawing Circle of radius " << r << "\n";
|
||||
}
|
||||
|
||||
double area() const override {
|
||||
return 3.14159 * r * r;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user