/*
* 5_9_Strategy.cpp
*
* Created on: 2010-9-25
* Author: wyiu
*/
class Compositor
{
public:
virtual int compose(Coord natural[], Coord stretch[], Coord shrink[],
int componentCount, int lineWidth, int breaks) = 0;
protected:
Compositor();
};
//------------------------------------------------------------------------
class Composition
{
public:
Composition(Compositor *);
void repair();
private:
Compositor *_compositor;
Component *_components;
int _componentCount;
int _lineWidth;
int *_lineBreaks;
int _lineCount;
};
void Composition::repair()
{
Coord *natural;
Coord *stretchability;
Coord *shrinkability;
int componentCount;
int *breaks;
//prepare the arrays with the desired component sizes
//
//determine where the breaks are:
int breakCount;
breakCount = _compositor->compose(natural, stretchability, shrinkability,
componentCount, _lineWidth, breaks);
//lay out components according to breaks
//
}
//--------------------------------------------------------------------
//subclass of Compositor
class SimpleCompositor : public Compositor
{
public:
SimpleCompositor();
virtual int compose(Coord natural[], Coord stretch[], Coord shrink[],
int componentCount, int lineWidth, int breaks);
//
};
class TeXCompositor : public Compositor
{
public:
TeXCompositor();
virtual int compose(Coord natural[], Coord stretch[], Coord shrink[],
int componentCount, int lineWidth, int breaks);
//
};
class ArrayCompositor : public Compositor
{
public:
ArrayCompositor();
virtual int compose(Coord natural[], Coord stretch[], Coord shrink[],
int componentCount, int lineWidth, int breaks);
//
};
//-----------------------------------------
//using example
int main()
{
//
Composition *quick = new Composition(new SimpleCompositor);
Composition *slick = new Composition(new TeXCompositor);
Composition *iconic = new Composition(new ArrayCompositor);
//.
return 0;
}
posted on 2010-10-04 12:27
wyiu 阅读(296)
评论(0) 编辑 收藏 引用 所属分类:
Design Pattern