From d7a3bc7db8d91bb2a0c15c7b7130354f39f27f47 Mon Sep 17 00:00:00 2001 From: Jeremy HU Date: Sun, 18 Sep 2022 17:54:55 +1000 Subject: [PATCH] Remove boost dependency --- application/application.pro | 18 +--- application/sources/document_window.cc | 2 +- dust3d/base/rectangle.h | 4 +- dust3d/base/string.cc | 9 +- dust3d/base/string.h | 2 +- dust3d/base/uuid.cc | 30 +++++++ dust3d/base/uuid.h | 111 +++++++++++++++++++------ dust3d/mesh/mesh_generator.cc | 1 + 8 files changed, 129 insertions(+), 48 deletions(-) create mode 100644 dust3d/base/uuid.cc diff --git a/application/application.pro b/application/application.pro index e5313d4a..72a12918 100644 --- a/application/application.pro +++ b/application/application.pro @@ -86,23 +86,6 @@ macx { RESOURCES += resources.qrc -DEFINES += BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE -win32 { - isEmpty(BOOST_INCLUDEDIR) { - BOOST_INCLUDEDIR = $$(BOOST_INCLUDEDIR) - } - isEmpty(BOOST_INCLUDEDIR) { - error("No BOOST_INCLUDEDIR define found in environment variables") - } -} -macx { - BOOST_INCLUDEDIR = /usr/local/opt/boost/include -} -unix:!macx { - BOOST_INCLUDEDIR = /usr/local/include -} -INCLUDEPATH += $$BOOST_INCLUDEDIR - INCLUDEPATH += ../ INCLUDEPATH += ../third_party INCLUDEPATH += ../third_party/rapidxml-1.13 @@ -262,6 +245,7 @@ HEADERS += ../dust3d/base/vector3.h SOURCES += ../dust3d/base/vector3.cc HEADERS += ../dust3d/base/vector2.h HEADERS += ../dust3d/base/uuid.h +SOURCES += ../dust3d/base/uuid.cc HEADERS += ../dust3d/mesh/box_mesh.h SOURCES += ../dust3d/mesh/box_mesh.cc HEADERS += ../dust3d/mesh/centripetal_catmull_rom_spline.h diff --git a/application/sources/document_window.cc b/application/sources/document_window.cc index 6ec4e3ae..952bb70c 100644 --- a/application/sources/document_window.cc +++ b/application/sources/document_window.cc @@ -1297,7 +1297,7 @@ void DocumentWindow::showCutFaceSettingPopup(const QPoint &globalPos, std::setsetIconSize(QSize(Theme::toolIconSize * 0.75, Theme::toolIconSize * 0.75)); diff --git a/dust3d/base/rectangle.h b/dust3d/base/rectangle.h index 0ebcbb47..4351b454 100644 --- a/dust3d/base/rectangle.h +++ b/dust3d/base/rectangle.h @@ -67,7 +67,7 @@ public: return m_data[0]; } - inline const double right() const + inline double right() const { return left() + width(); } @@ -77,7 +77,7 @@ public: return m_data[1]; } - inline const double bottom() const + inline double bottom() const { return top() + height(); } diff --git a/dust3d/base/string.cc b/dust3d/base/string.cc index f019fc5c..5c9c6fcb 100644 --- a/dust3d/base/string.cc +++ b/dust3d/base/string.cc @@ -19,8 +19,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - -#include + +#include #include namespace dust3d @@ -30,7 +30,10 @@ namespace String std::string join(const std::vector &stringList, const char *separator) { - return boost::algorithm::join(stringList, separator); + return std::accumulate(stringList.begin(), stringList.end(), std::string(), + [=](const std::string &a, const std::string &b) -> std::string { + return a + (a.length() > 0 ? separator : "") + b; + }); } } diff --git a/dust3d/base/string.h b/dust3d/base/string.h index 6daf3c29..7e23a812 100644 --- a/dust3d/base/string.h +++ b/dust3d/base/string.h @@ -98,7 +98,7 @@ inline std::string valueOrEmpty(const std::map &map, c return it->second; } -static bool isTrue(const std::string &string) +inline bool isTrue(const std::string &string) { return "true" == string || "True" == string || "1" == string; } diff --git a/dust3d/base/uuid.cc b/dust3d/base/uuid.cc new file mode 100644 index 00000000..edb3cb21 --- /dev/null +++ b/dust3d/base/uuid.cc @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2016-2021 Jeremy HU . All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include + +namespace dust3d +{ + +Uuid::RandomGenerator *Uuid::m_generator = new Uuid::RandomGenerator; + +} // namespace dust3d diff --git a/dust3d/base/uuid.h b/dust3d/base/uuid.h index 874bc454..54b8e657 100644 --- a/dust3d/base/uuid.h +++ b/dust3d/base/uuid.h @@ -23,12 +23,10 @@ #ifndef DUST3D_BASE_UUID_H_ #define DUST3D_BASE_UUID_H_ -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include namespace dust3d { @@ -36,40 +34,105 @@ namespace dust3d class Uuid { public: - Uuid() + class RandomGenerator { - m_uuid = boost::uuids::nil_uuid(); - } + public: + RandomGenerator(): + m_randomGenerator(m_randomDevice() + std::chrono::time_point_cast(std::chrono::system_clock::now()).time_since_epoch().count()), + m_randomDistribution(0, 15) + { + } + + int generate() + { + return m_randomDistribution(m_randomGenerator); + } - Uuid(const boost::uuids::uuid &uuid) : - m_uuid(uuid) - { - } + private: + std::random_device m_randomDevice; + std::mt19937 m_randomGenerator; + std::uniform_int_distribution m_randomDistribution; + }; + + static RandomGenerator *m_generator; + + Uuid() = default; Uuid(const std::string &string) { - if (sizeof("{hhhhhhhh-hhhh-hhhh-hhhh-hhhhhhhhhhhh}") - 1 != string.length() || - '{' != string[0]) { - m_uuid = boost::uuids::nil_uuid(); + if (sizeof("{hhhhhhhh-hhhh-hhhh-hhhh-hhhhhhhhhhhh}") - 1 == string.length() && + '{' == string[0] && + validate(&string[1], string.length() - 2)) { + m_uuid = string.substr(1, string.length() - 2); return; } - m_uuid = boost::lexical_cast( - string.substr(1, sizeof("hhhhhhhh-hhhh-hhhh-hhhh-hhhhhhhhhhhh") - 1)); + if (sizeof("hhhhhhhh-hhhh-hhhh-hhhh-hhhhhhhhhhhh") - 1 == string.length() && + validate(&string[0], string.length())) { + m_uuid = string; + return; + } + } + + static bool validate(const char *string, size_t length) + { + return length >= 24 && + '-' == string[8] && + '-' == string[13] && + '-' == string[18] && + '-' == string[23]; } bool isNull() const { - return m_uuid.is_nil(); + return m_uuid.empty(); } std::string toString() const { - return "{" + to_string(m_uuid) + "}"; + return "{" + m_uuid + "}"; } static Uuid createUuid() { - return Uuid(boost::uuids::random_generator()()); + std::ostringstream ss; + ss << std::hex; + ss << m_generator->generate(); + ss << m_generator->generate(); + ss << m_generator->generate(); + ss << m_generator->generate(); + ss << m_generator->generate(); + ss << m_generator->generate(); + ss << m_generator->generate(); + ss << m_generator->generate(); + ss << "-"; + ss << m_generator->generate(); + ss << m_generator->generate(); + ss << m_generator->generate(); + ss << m_generator->generate(); + ss << "-"; + ss << m_generator->generate(); + ss << m_generator->generate(); + ss << m_generator->generate(); + ss << m_generator->generate(); + ss << "-"; + ss << m_generator->generate(); + ss << m_generator->generate(); + ss << m_generator->generate(); + ss << m_generator->generate(); + ss << "-"; + ss << m_generator->generate(); + ss << m_generator->generate(); + ss << m_generator->generate(); + ss << m_generator->generate(); + ss << m_generator->generate(); + ss << m_generator->generate(); + ss << m_generator->generate(); + ss << m_generator->generate(); + ss << m_generator->generate(); + ss << m_generator->generate(); + ss << m_generator->generate(); + ss << m_generator->generate(); + return Uuid(ss.str()); } private: friend std::string to_string(const Uuid &uuid); @@ -77,12 +140,12 @@ private: friend bool operator==(const Uuid &lhs, const Uuid &rhs); friend bool operator!=(const Uuid &lhs, const Uuid &rhs); friend bool operator<(const Uuid &lhs, const Uuid &rhs); - boost::uuids::uuid m_uuid; + std::string m_uuid; }; inline std::string to_string(const Uuid &uuid) { - return "{" + to_string(uuid.m_uuid) + "}"; + return "{" + uuid.m_uuid + "}"; } inline bool operator==(const Uuid &lhs, const Uuid &rhs) @@ -110,7 +173,7 @@ struct hash { size_t operator()(const dust3d::Uuid& uuid) const { - return boost::hash()(uuid.m_uuid); + return std::hash()(uuid.m_uuid); } }; diff --git a/dust3d/mesh/mesh_generator.cc b/dust3d/mesh/mesh_generator.cc index 81d4d0da..e13bd88e 100644 --- a/dust3d/mesh/mesh_generator.cc +++ b/dust3d/mesh/mesh_generator.cc @@ -21,6 +21,7 @@ */ #include +#include #include #include #include