GEOS  3.9.0dev
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 #ifndef GEOS_GEOM_DEFAULTCOORDINATESEQUENCEFACTORY_H
16 #define GEOS_GEOM_DEFAULTCOORDINATESEQUENCEFACTORY_H
17 
18 #include <geos/geom/CoordinateSequenceFactory.h>
19 #include <geos/geom/CoordinateArraySequence.h>
20 #include <geos/geom/FixedSizeCoordinateSequence.h>
21 
22 namespace geos {
23 namespace geom {
24 
25 class GEOS_DLL DefaultCoordinateSequenceFactory : public CoordinateSequenceFactory {
26 public:
27 
28  std::unique_ptr<CoordinateSequence> create() const final override {
29  return detail::make_unique<CoordinateArraySequence>();
30  }
31 
32  std::unique_ptr<CoordinateSequence> create(std::vector<Coordinate> *coords, std::size_t dims = 0) const final override {
33  return detail::make_unique<CoordinateArraySequence>(coords, dims);
34  }
35 
36  std::unique_ptr <CoordinateSequence> create(std::vector <Coordinate> &&coords, std::size_t dims = 0) const final override {
37  return detail::make_unique<CoordinateArraySequence>(std::move(coords), dims);
38  }
39 
40  std::unique_ptr <CoordinateSequence> create(std::size_t size, std::size_t dims = 0) const final override {
41  switch(size) {
42  case 5: return detail::make_unique<FixedSizeCoordinateSequence<5>>(dims);
43  case 4: return detail::make_unique<FixedSizeCoordinateSequence<4>>(dims);
44  case 3: return detail::make_unique<FixedSizeCoordinateSequence<3>>(dims);
45  case 2: return detail::make_unique<FixedSizeCoordinateSequence<2>>(dims);
46  case 1: return detail::make_unique<FixedSizeCoordinateSequence<1>>(dims);
47  default:
48  return detail::make_unique<CoordinateArraySequence>(size, dims);
49  }
50  }
51 
52  std::unique_ptr <CoordinateSequence> create(const CoordinateSequence &coordSeq) const final override {
53  auto cs = create(coordSeq.size(), coordSeq.getDimension());
54  for (size_t i = 0; i < cs->size(); i++) {
55  cs->setAt(coordSeq[i], i);
56  }
57  return cs;
58  }
59 
60  static const CoordinateSequenceFactory *instance();
61 };
62 
63 }
64 }
65 
66 #endif //GEOS_DEFAULTCOORDINATESEQUENCEFACTORY_H
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:26
CoordinateArraySequenceFactory DefaultCoordinateSequenceFactory
This is for backward API compatibility.
Definition: CoordinateArraySequenceFactory.h:64