From a3e9620c78ae1e4ff156fbd8c662684959a37a10 Mon Sep 17 00:00:00 2001 From: artem-ogre Date: Thu, 5 Dec 2024 10:11:19 +0100 Subject: [PATCH] #188 Provide polyfill for std::to_string for c++98 compatibility --- CDT/include/CDTUtils.h | 21 ++++++++++++++++++--- CDT/include/Triangulation.h | 12 ++++++------ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/CDT/include/CDTUtils.h b/CDT/include/CDTUtils.h index 1b9a0ff..0f9fb92 100644 --- a/CDT/include/CDTUtils.h +++ b/CDT/include/CDTUtils.h @@ -55,15 +55,18 @@ typedef char couldnt_parse_cxx_standard[-1]; ///< Error: couldn't parse standard #include #include +#include #include #include #include + namespace CDT { using std::array; using std::get; using std::make_tuple; using std::tie; +using std::to_string; using std::tuple; using std::unordered_map; using std::unordered_set; @@ -72,6 +75,7 @@ using std::unordered_set; #else #include #include +#include #include #include #include @@ -84,12 +88,17 @@ using boost::tie; using boost::tuple; using boost::unordered_map; using boost::unordered_set; + +template +std::string to_string(const T& value) +{ + return boost::lexical_cast(value); +} } // namespace CDT #endif namespace CDT { - /// 2D vector template struct CDT_EXPORT V2d @@ -168,6 +177,7 @@ struct CDT_EXPORT Box2d { envelopPoint(p.x, p.y); } + /// Envelop box around a point with given coordinates void envelopPoint(const T x, const T y) { @@ -209,14 +219,19 @@ struct CDT_EXPORT Edge { /// Constructor Edge(VertInd iV1, VertInd iV2); + /// Equals operator bool operator==(const Edge& other) const; + /// Not-equals operator bool operator!=(const Edge& other) const; + /// V1 getter VertInd v1() const; + /// V2 getter VertInd v2() const; + /// Edges' vertices const std::pair& verts() const; @@ -287,6 +302,7 @@ struct CDT_EXPORT Triangle } return std::make_pair(neighbors[2], vertices[0]); } + /// Previous triangle adjacent to a vertex (counter-clockwise) /// @returns pair of previous triangle and the other vertex of a common edge std::pair prev(const VertInd i) const @@ -428,7 +444,6 @@ CDT_EXPORT T distanceSquared(const V2d& a, const V2d& b); /// Check if any of triangle's vertices belongs to a super-triangle CDT_INLINE_IF_HEADER_ONLY bool touchesSuperTriangle(const Triangle& t); - } // namespace CDT #ifndef CDT_USE_AS_COMPILED_LIBRARY @@ -444,7 +459,6 @@ namespace std namespace boost #endif { - #ifdef CDT_USE_STRONG_TYPING /// Vertex index hasher @@ -491,6 +505,7 @@ struct hash #endif seed ^= Hasher()(key) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } + static std::size_t hashEdge(const CDT::Edge& e) { const std::pair& vv = e.verts(); diff --git a/CDT/include/Triangulation.h b/CDT/include/Triangulation.h index 7ca3a3d..071210c 100644 --- a/CDT/include/Triangulation.h +++ b/CDT/include/Triangulation.h @@ -142,7 +142,7 @@ class Error : public std::runtime_error Error(const std::string& description, const SourceLocation& srcLoc) : std::runtime_error( description + "\nin '" + srcLoc.func() + "' at " + srcLoc.file() + - ":" + std::to_string(srcLoc.line())) + ":" + CDT::to_string(srcLoc.line())) , m_description(description) , m_srcLoc(srcLoc) {} @@ -188,8 +188,8 @@ class DuplicateVertexError : public Error const VertInd v2, const SourceLocation& srcLoc) : Error( - "Duplicate vertex detected: #" + std::to_string(v1) + - " is a duplicate of #" + std::to_string(v2), + "Duplicate vertex detected: #" + CDT::to_string(v1) + + " is a duplicate of #" + CDT::to_string(v2), srcLoc) , m_v1(v1) , m_v2(v2) @@ -220,9 +220,9 @@ class IntersectingConstraintsError : public Error const SourceLocation& srcLoc) : Error( "Intersecting constraint edges detected: (" + - std::to_string(e1.v1()) + ", " + std::to_string(e1.v2()) + - ") intersects (" + std::to_string(e2.v1()) + ", " + - std::to_string(e2.v2()) + ")", + CDT::to_string(e1.v1()) + ", " + CDT::to_string(e1.v2()) + + ") intersects (" + CDT::to_string(e2.v1()) + ", " + + CDT::to_string(e2.v2()) + ")", srcLoc) , m_e1(e1) , m_e2(e2)