私は変更できないレガシーなクラス階層を持っています。外部ライブラリの要件のために、私はLineとRingのBoost.Rangesを定義する必要があります.Bost.Rangesは、1回の実行でポイントを公開するだけです(つまり、ラインとリングの両方がポイントのブーストです) 。ベクトルの複数のレイヤーを隠し、単一の範囲として公開するBoost.Rangeを作成する方法は?
説明するための擬似コード:
Line l1 = Line{{1.0,2.0},{3.0,4.0},{5.0,6.0}} // init Line with three Points
Line l2 = Line{{7.0,8.0},{9.0,10.0},{11.0,12.0}} // init Line with three Points
auto lit = boost::begin(l1); // points to the Point{1.0,2.0}
++lit; // points to the Point{3.0,4.0}
Ring r1 = Ring{l1,l2} // init Ring with two Lines
auto rit = boost::begin(r1); // points to the Point{1.0,2.0}
++rit; // points to the Point{3.0,4.0}
++rit; // points to the Point{5.0,6.0}
++rit; // points to the Point{7.0,8.0}
++rit; // points to the Point{9.0,10.0}
// etc...
ラインが簡単である点が直接格納されているので、(私はBoost.Range see the exampleで正常にこれを行っています)。しかし、私は各ラインのポイントに直接到達する必要があるので、私はリングでこれを行う方法がわかりません。
class Point
{
public:
double x, y;
}
class Line
{
public:
std::vector<Point> points;
}
class Ring
{
public:
std::vector<Line> lines;
}
が前進トラバーサルによって範囲にすることができる、またはそれはランダムアクセスする必要がありますか。 –
@EmileCormier Boost.Geometryの文書によると、「Boost.Rangeのランダムアクセス範囲のように動作しなければならない」[こちらを参照](http://www.boost.org/doc/libs/1_48_0/libs/geometry/ doc/html/geometry/reference/concepts/concept_ring.html) – meastp
@EmileCormier ['boost :: iterator_facade'](http://www.boost.org/doc/libs/release/libs/iterator/doc/)から、 iterator_facade.html)リンクを使用すると、ランダムアクセスのサポートのように、 'distance_to'の定義を追加し、' boost :: forward_traversal_tag'を 'boost :: random_access_traversal_tag'に置き換える必要があります。これは正しいです? – meastp