GEOS  3.9.1dev
DefaultCoordinateSequenceFactory.h
Go to the documentation of this file.
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 
21 
22 namespace geos {
23 namespace geom {
24 
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
#define GEOS_DLL
Definition: export.h:28
std::unique_ptr< CoordinateSequence > create() const finaloverride
Returns an empty CoordinateSequence, the dimensions will be autodetected when it is populated...
std::unique_ptr< CoordinateSequence > create(const CoordinateSequence &coordSeq) const finaloverride
Creates a CoordinateSequence which is a copy of the given one.
Basic namespace for all GEOS functionalities.
std::unique_ptr< CoordinateSequence > create(std::size_t size, std::size_t dims=0) const finaloverride
Creates a CoordinateSequence of the specified size and dimension.
std::unique_ptr< CoordinateSequence > create(std::vector< Coordinate > &&coords, std::size_t dims=0) const finaloverride
Returns a CoordinateSequence based on the given array.
A factory to create concrete instances of CoordinateSequences.
The internal representation of a list of coordinates inside a Geometry.
std::unique_ptr< CoordinateSequence > create(std::vector< Coordinate > *coords, std::size_t dims=0) const finaloverride
Returns a CoordinateSequence based on the given array.