adapter.c

来自「Design Pattern C Source Code」· C语言 代码 · 共 134 行

C
134
字号
/**/#include "Geom.H"// Compilation Instructions// With ClassAdapter defined and not defined#define ClassAdapter 0/**/class Manipulator;/**/class Shape {public:    Shape();    virtual void BoundingBox(        Point& bottomLeft, Point& topRight    ) const;    virtual Manipulator* CreateManipulator() const;};/**/class TextView {public:    TextView();    void GetOrigin(Coord& x, Coord& y) const;    void GetExtent(Coord& width, Coord& height) const;    virtual bool IsEmpty() const;};/**/#ifdef ClassAdapter/**/class TextShape : public Shape, private TextView {public:    TextShape();    virtual void BoundingBox(        Point& bottomLeft, Point& topRight    ) const;    virtual bool IsEmpty() const;    virtual Manipulator* CreateManipulator() const;};/**/void TextShape::BoundingBox (    Point& bottomLeft, Point& topRight) const {    Coord bottom, left, width, height;    GetOrigin(bottom, left);    GetExtent(width, height);/**/    bottomLeft = Point(bottom, left);    topRight = Point(bottom + height, left + width);}/**/bool TextShape::IsEmpty () const {    return TextView::IsEmpty();}/**/class Manipulator {};class TextManipulator : public Manipulator {  public:    TextManipulator(const TextShape*);};/**/Manipulator* TextShape::CreateManipulator () const {    return new TextManipulator(this);}/**/#endif#ifndef ClassAdapterclass TextView;class Manipulator {};class TextManipulator : public Manipulator {  public:    TextManipulator();};/**/class TextShape : public Shape {public:    TextShape(TextView*);    virtual void BoundingBox(        Point& bottomLeft, Point& topRight    ) const;    virtual bool IsEmpty() const;    virtual Manipulator* CreateManipulator() const;private:    TextView* _text;};/**/TextShape::TextShape (TextView* t) {    _text = t;}/**/void TextShape::BoundingBox (    Point& bottomLeft, Point& topRight) const {    Coord bottom, left, width, height;    _text->GetOrigin(bottom, left);    _text->GetExtent(width, height);    bottomLeft = Point(bottom, left);    topRight = Point(bottom + height, left + width);}/**/bool TextShape::IsEmpty () const {    return _text->IsEmpty();}/**/Manipulator* TextShape::CreateManipulator () const {    return new TextManipulator(this);}/**/#endif/**/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?