]> git.tdb.fi Git - libs/math.git/blobdiff - source/geometry/compositeshape.h
Rewrite composite shape vector constructors with iterator ranges
[libs/math.git] / source / geometry / compositeshape.h
index 9476f99287843b33f52b1cf55fa0dfd6bdc85d94..50075d923b70c3c38f6671ae6ed585fe75f95ec1 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef MSP_GEOMETRY_COMPOSITESHAPE_H_
 #define MSP_GEOMETRY_COMPOSITESHAPE_H_
 
+#include <stdexcept>
 #include <vector>
 #include "shape.h"
 
@@ -19,10 +20,12 @@ protected:
 
        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();
 
@@ -41,13 +44,21 @@ inline CompositeShape<T, D, O>::CompositeShape(const Shape<T, D> &s1, const Shap
 }
 
 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());
 }