#ifndef MSP_GEOMETRY_COMPOSITESHAPE_H_
#define MSP_GEOMETRY_COMPOSITESHAPE_H_
+#include <stdexcept>
#include <vector>
#include "shape.h"
ShapeArray shapes;
+ CompositeShape() { }
CompositeShape(const Shape<T, D> &, const Shape<T, D> &);
- CompositeShape(const ShapeArray &);
CompositeShape(const CompositeShape &);
CompositeShape &operator=(const CompositeShape &);
+ template<typename Iter>
+ void init_from_iter_range(const Iter &, const Iter &);
public:
virtual ~CompositeShape();
}
template<typename T, unsigned D, typename O>
-inline CompositeShape<T, D, O>::CompositeShape(const ShapeArray &s)
+template<typename Iter>
+inline void CompositeShape<T, D, O>::init_from_iter_range(const Iter &begin, const Iter &end)
{
- if(s.empty())
- throw std::invalid_argument("CompositeShape::CompositeShape");
+ if(begin==end)
+ throw std::invalid_argument("CompositeShape::init_from_iter_range");
- shapes.reserve(s.size());
- for(typename ShapeArray::const_iterator i=s.begin(); i!=s.end(); ++i)
+ for(Iter i=begin; i!=end; ++i)
+ shapes.push_back((*i)->clone());
+}
+
+template<typename T, unsigned D, typename O>
+inline CompositeShape<T, D, O>::CompositeShape(const CompositeShape<T, D, O> &other)
+{
+ shapes.reserve(other.shapes.size());
+ for(typename ShapeArray::const_iterator i=other.shapes.begin(); i!=other.shapes.end(); ++i)
shapes.push_back((*i)->clone());
}
template<typename T, unsigned D>
class Intersection: public CompositeShape<T, D, IntersectionOps<T, D> >
{
+private:
+ Intersection() { }
public:
Intersection(const Shape<T, D> &, const Shape<T, D> &);
- Intersection(const std::vector<Shape<T, D> *> &);
+
+ template<typename Iter>
+ static Intersection from_iterator_range(const Iter &, const Iter &);
virtual Intersection *clone() const;
};
template<typename T, unsigned D>
-Intersection<T, D>::Intersection(const Shape<T, D> &s1, const Shape<T, D> &s2):
+inline Intersection<T, D>::Intersection(const Shape<T, D> &s1, const Shape<T, D> &s2):
CompositeShape<T, D, IntersectionOps<T, D> >(s1, s2)
{ }
template<typename T, unsigned D>
-Intersection<T, D>::Intersection(const std::vector<Shape<T, D> *> &s):
- CompositeShape<T, D, IntersectionOps<T, D> >(s)
-{ }
+template<typename Iter>
+inline Intersection<T, D> Intersection<T, D>::from_iterator_range(const Iter &begin, const Iter &end)
+{
+ Intersection<T, D> shape;
+ shape.init_from_iter_range(begin, end);
+ return shape;
+}
template<typename T, unsigned D>
-Intersection<T, D> *Intersection<T, D>::clone() const
+inline Intersection<T, D> *Intersection<T, D>::clone() const
{
- return new Intersection<T, D>(this->shapes);
+ return new Intersection<T, D>(*this);
}
template<typename T, unsigned D>
class Union: public CompositeShape<T, D, UnionOps<T, D> >
{
+private:
+ Union() { }
public:
Union(const Shape<T, D> &, const Shape<T, D> &);
- Union(const std::vector<Shape<T, D> *> &);
+
+ template<typename Iter>
+ static Union from_iterator_range(const Iter &, const Iter &);
virtual Union *clone() const;
};
{ }
template<typename T, unsigned D>
-inline Union<T, D>::Union(const std::vector<Shape<T, D> *> &s):
- CompositeShape<T, D, UnionOps<T, D> >(s)
-{ }
+template<typename Iter>
+inline Union<T, D> Union<T, D>::from_iterator_range(const Iter &begin, const Iter &end)
+{
+ Union<T, D> shape;
+ shape.init_from_iter_range(begin, end);
+ return shape;
+}
template<typename T, unsigned D>
inline Union<T, D> *Union<T, D>::clone() const
{
- return new Union<T, D>(this->shapes);
+ return new Union<T, D>(*this);
}