geometry_io.hpp 2.29 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
#pragma once

#include <mapbox/geometry/empty.hpp>
#include <mapbox/feature.hpp>

#include <iostream>
#include <string>

namespace mapbox {
namespace geometry {

std::ostream& operator<<(std::ostream& os, const empty&)
{
    return os << "[]";
}

template <typename T>
std::ostream& operator<<(std::ostream& os, const point<T>& point)
{
    return os << "[" << point.x << "," << point.y << "]";
}

template <typename T, template <class, class...> class C, class... Args>
std::ostream& operator<<(std::ostream& os, const C<T, Args...>& cont)
{
    os << "[";
    for (auto it = cont.cbegin();;)
    {
        os << *it;
        if (++it == cont.cend())
        {
            break;
        }
        os << ",";
    }
    return os << "]";
}

template <typename T>
std::ostream& operator<<(std::ostream& os, const line_string<T>& geom)
{
    return os << static_cast<typename line_string<T>::container_type>(geom);
}

template <typename T>
std::ostream& operator<<(std::ostream& os, const linear_ring<T>& geom)
{
    return os << static_cast<typename linear_ring<T>::container_type>(geom);
}

template <typename T>
std::ostream& operator<<(std::ostream& os, const polygon<T>& geom)
{
    return os << static_cast<typename polygon<T>::container_type>(geom);
}

template <typename T>
std::ostream& operator<<(std::ostream& os, const multi_point<T>& geom)
{
    return os << static_cast<typename multi_point<T>::container_type>(geom);
}

template <typename T>
std::ostream& operator<<(std::ostream& os, const multi_line_string<T>& geom)
{
    return os << static_cast<typename multi_line_string<T>::container_type>(geom);
}

template <typename T>
std::ostream& operator<<(std::ostream& os, const multi_polygon<T>& geom)
{
    return os << static_cast<typename multi_polygon<T>::container_type>(geom);
}

template <typename T>
std::ostream& operator<<(std::ostream& os, const geometry<T>& geom)
{
    geometry<T>::visit(geom, [&](const auto& g) { os << g; });
    return os;
}

template <typename T>
std::ostream& operator<<(std::ostream& os, const geometry_collection<T>& geom)
{
    return os << static_cast<typename geometry_collection<T>::container_type>(geom);
}

} // namespace geometry

namespace feature {

std::ostream& operator<<(std::ostream& os, const null_value_t&)
{
    return os << "[]";
}

} // namespace feature
} // namespace mapbox