<commit_before>/**********************************************************************
 *
 * GEOS - Geometry Engine Open Source
 * http://geos.osgeo.org
 *
 * Copyright (C) 2019 <NAME>
 *
 * This is free software; you can redistribute and/or modify it under
 * the terms of the GNU Lesser General Public Licence as published
 * by the Free Software Foundation.
 * See the COPYING file for more information.
 *
 **********************************************************************/

#ifndef GEOS_GEOM_FIXEDSIZECOORDINATESEQUENCE_H
#define GEOS_GEOM_FIXEDSIZECOORDINATESEQUENCE_H

#include <geos/geom/Coordinate.h>
#include <geos/geom/CoordinateFilter.h>
#include <geos/geom/CoordinateSequence.h>
#include <geos/util.h>

#include <algorithm>
#include <array>
#include <memory>
#include <sstream>
#include <vector>

namespace geos {
namespace geom {

    template<size_t N>
    class FixedSizeCoordinateSequence : public CoordinateSequence {
    public:
        explicit FixedSizeCoordinateSequence(size_t dimension_in = 0) : dimension(dimension_in) {}

        std::unique_ptr<CoordinateSequence> clone() const override {
            auto seq = detail::make_unique<FixedSizeCoordinateSequence<N>>();
            seq->m_data = m_data;
            return std::unique_ptr<CoordinateSequence>(seq.release());
        }

        const Coordinate& getAt(size_t i) const override {
            return m_data[i];
        }

        void getAt(size_t i, Coordinate& c) const override {
            c = m_data[i];
        }

        size_t getSize() const override {
            return N;
        }

        bool isEmpty() const override {
            return N == 0;
        }

        void setAt(const Coordinate & c, size_t pos) override {
            m_data[pos] = c;
        }

        void setOrdinate(size_t index, size_t ordinateIndex, double value)
        {
            switch(ordinateIndex) {
                case CoordinateSequence::X:
                    m_data[index].x = value;
                    break;
                case CoordinateSequence::Y:
                    m_data[index].y = value;
                    break;
                case CoordinateSequence::Z:
                    m_data[index].z = value;
                    break;
                default: {
                    std::stringstream ss;
                    ss << "Unknown ordinate index " << index;
                    throw geos::util::IllegalArgumentException(ss.str());
                    break;
                }
            }
        }

        size_t getDimension() const override {
            if(dimension != 0) {
                return dimension;
            }

            if(isEmpty()) {
                return 3;
            }

            if(std::isnan(m_data[0].z)) {
                dimension = 2;
            }
            else {
                dimension = 3;
            }

            return dimension;
        }

        void toVector(std::vector<Coordinate> & out) const {
            out.insert(out.end(), m_data.begin(), m_data.end());
        }

        void setPoints(const std::vector<Coordinate> & v) override {
            std::copy(v.begin(), v.end(), m_data.begin());
        }

        void apply_ro(CoordinateFilter* filter) const override {
            std::for_each(m_data.begin(), m_data.end(),
                    [&filter](const Coordinate & c) { filter->filter_ro(&c); });
        }

        void apply_rw(const CoordinateFilter* filter) override {
            std::for_each(m_data.begin(), m_data.end(),
                    [&filter](Coordinate &c) { filter->filter_rw(&c); });
            dimension = 0; // re-check (see http://trac.osgeo.org/geos/ticket/435)
        }

    private:
        std::array<Coordinate, N> m_data;
        mutable std::size_t dimension;
    };

}
}

#endif<commit_msg>Mark FixedSizeCoordinateSequence methods as final<commit_after>/**********************************************************************
 *
 * GEOS - Geometry Engine Open Source
 * http://geos.osgeo.org
 *
 * Copyright (C) 2019 <NAME>
 *
 * This is free software; you can redistribute and/or modify it under
 * the terms of the GNU Lesser General Public Licence as published
 * by the Free Software Foundation.
 * See the COPYING file for more information.
 *
 **********************************************************************/

#ifndef GEOS_GEOM_FIXEDSIZECOORDINATESEQUENCE_H
#define GEOS_GEOM_FIXEDSIZECOORDINATESEQUENCE_H

#include <geos/geom/Coordinate.h>
#include <geos/geom/CoordinateFilter.h>
#include <geos/geom/CoordinateSequence.h>
#include <geos/util.h>

#include <algorithm>
#include <array>
#include <memory>
#include <sstream>
#include <vector>

namespace geos {
namespace geom {

    template<size_t N>
    class FixedSizeCoordinateSequence : public CoordinateSequence {
    public:
        explicit FixedSizeCoordinateSequence(size_t dimension_in = 0) : dimension(dimension_in) {}

        std::unique_ptr<CoordinateSequence> clone() const final {
            auto seq = detail::make_unique<FixedSizeCoordinateSequence<N>>();
            seq->m_data = m_data;
            return std::unique_ptr<CoordinateSequence>(seq.release());
        }

        const Coordinate& getAt(size_t i) const final {
            return m_data[i];
        }

        void getAt(size_t i, Coordinate& c) const final {
            c = m_data[i];
        }

        size_t getSize() const final {
            return N;
        }

        bool isEmpty() const final {
            return N == 0;
        }

        void setAt(const Coordinate & c, size_t pos) final {
            m_data[pos] = c;
        }

        void setOrdinate(size_t index, size_t ordinateIndex, double value)
        {
            switch(ordinateIndex) {
                case CoordinateSequence::X:
                    m_data[index].x = value;
                    break;
                case CoordinateSequence::Y:
                    m_data[index].y = value;
                    break;
                case CoordinateSequence::Z:
                    m_data[index].z = value;
                    break;
                default: {
                    std::stringstream ss;
                    ss << "Unknown ordinate index " << index;
                    throw geos::util::IllegalArgumentException(ss.str());
                    break;
                }
            }
        }

        size_t getDimension() const final {
            if(dimension != 0) {
                return dimension;
            }

            if(isEmpty()) {
                return 3;
            }

            if(std::isnan(m_data[0].z)) {
                dimension = 2;
            }
            else {
                dimension = 3;
            }

            return dimension;
        }

        void toVector(std::vector<Coordinate> & out) const {
            out.insert(out.end(), m_data.begin(), m_data.end());
        }

        void setPoints(const std::vector<Coordinate> & v) final {
            std::copy(v.begin(), v.end(), m_data.begin());
        }

        void apply_ro(CoordinateFilter* filter) const final {
            std::for_each(m_data.begin(), m_data.end(),
                    [&filter](const Coordinate & c) { filter->filter_ro(&c); });
        }

        void apply_rw(const CoordinateFilter* filter) final {
            std::for_each(m_data.begin(), m_data.end(),
                    [&filter](Coordinate &c) { filter->filter_rw(&c); });
            dimension = 0; // re-check (see http://trac.osgeo.org/geos/ticket/435)
        }

    private:
        std::array<Coordinate, N> m_data;
        mutable std::size_t dimension;
    };

}
}

#endif
{'fraction_non_alphanumeric': 0.14083398898505115, 'fraction_numerical': 0.003933910306845004, 'mean_word_length': 1.8857359061672343, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7550323', 'n_tokens_mistral': 2204, 'n_tokens_neox': 2082, 'n_words': 473}