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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| //les factories, qui prolonge le précédent.
namespace geom {
class Mask {
protected:
Mask(int width, int height, int originX=0, int originY=0):
width(width),height(height),left(originX),top(originY){}
public:
~Mask(){};
protected:
int width,height;
int left,top;
friend class MaskFactory;
friend class RepetitiveMaskFactory;
};
class MaskFactory {
public:
Mask create(int width, int height, int originX=0, int originY=0) {
return Mask(width, height, originX, originY);
}
Mask create(Box<int> const& box) {
return Mask(box.sizeX(), box.sizeY(), box.GetA()[0], box.GetA()[1]);
}
Mask create(std::vector<int> const & a, std::vector<int> const& b) {
return create(Box<int>(a, b));
}
};
class RepetitiveMaskFactory {
public:
const int width, height;
public:
RepetitiveMaskFactory(int width, int height) : width(width), (height) {}
Mask createAt(int x=0, int y=0) {
return Mask(width, height, x, y);
}
Mask createAt(Mask const& other) {
return Mask(width, height, other.left, other.top);
}
};
}//geom::
using namespace geom;
int main() {
MaskFactory factory;
Mask a = factory.create(50, 50, 8, 12);
RepetitiveMaskFactory creator(12, 18);
Mask b = creator.createAt(a);
Mask c = creator.createAt(1, 2);
return 0;
} |