GEOS 3.11.1
DefaultCoordinateSequenceFactory.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2019 Daniel Baston
7 *
8 * This is free software; you can redistribute and/or modify it under
9 * the terms of the GNU Lesser General Public Licence as published
10 * by the Free Software Foundation.
11 * See the COPYING file for more information.
12 *
13 **********************************************************************/
14
15#pragma once
16
17#include <geos/geom/CoordinateSequenceFactory.h>
18#include <geos/geom/CoordinateArraySequence.h>
19#include <geos/geom/FixedSizeCoordinateSequence.h>
20
21namespace geos {
22namespace geom {
23
24class GEOS_DLL DefaultCoordinateSequenceFactory : public CoordinateSequenceFactory {
25public:
26
27 std::unique_ptr<CoordinateSequence> create() const final override {
28 return detail::make_unique<CoordinateArraySequence>();
29 }
30
31 std::unique_ptr<CoordinateSequence> create(std::vector<Coordinate> *coords, std::size_t dims = 0) const final override {
32 return detail::make_unique<CoordinateArraySequence>(coords, dims);
33 }
34
35 std::unique_ptr <CoordinateSequence> create(std::vector <Coordinate> &&coords, std::size_t dims = 0) const final override {
36 return detail::make_unique<CoordinateArraySequence>(std::move(coords), dims);
37 }
38
39 std::unique_ptr <CoordinateSequence> create(std::size_t size, std::size_t dims = 0) const final override {
40 switch(size) {
41 case 5: return detail::make_unique<FixedSizeCoordinateSequence<5>>(dims);
42 case 4: return detail::make_unique<FixedSizeCoordinateSequence<4>>(dims);
43 case 3: return detail::make_unique<FixedSizeCoordinateSequence<3>>(dims);
44 case 2: return detail::make_unique<FixedSizeCoordinateSequence<2>>(dims);
45 case 1: return detail::make_unique<FixedSizeCoordinateSequence<1>>(dims);
46 default:
47 return detail::make_unique<CoordinateArraySequence>(size, dims);
48 }
49 }
50
51 std::unique_ptr <CoordinateSequence> create(const CoordinateSequence &coordSeq) const final override {
52 auto cs = create(coordSeq.size(), coordSeq.getDimension());
53 for (std::size_t i = 0; i < cs->size(); i++) {
54 cs->setAt(coordSeq[i], i);
55 }
56 return cs;
57 }
58
59 static const CoordinateSequenceFactory *instance();
60};
61
62}
63}
64
CoordinateArraySequenceFactory DefaultCoordinateSequenceFactory
This is for backward API compatibility.
Definition: CoordinateArraySequenceFactory.h:82
Basic namespace for all GEOS functionalities.
Definition: geos.h:39