Remove boost dependency

master
Jeremy HU 2022-09-18 17:54:55 +10:00
parent 4d93f5c3b7
commit d7a3bc7db8
8 changed files with 129 additions and 48 deletions

View File

@ -86,23 +86,6 @@ macx {
RESOURCES += resources.qrc 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 += ../
INCLUDEPATH += ../third_party INCLUDEPATH += ../third_party
INCLUDEPATH += ../third_party/rapidxml-1.13 INCLUDEPATH += ../third_party/rapidxml-1.13
@ -262,6 +245,7 @@ HEADERS += ../dust3d/base/vector3.h
SOURCES += ../dust3d/base/vector3.cc SOURCES += ../dust3d/base/vector3.cc
HEADERS += ../dust3d/base/vector2.h HEADERS += ../dust3d/base/vector2.h
HEADERS += ../dust3d/base/uuid.h HEADERS += ../dust3d/base/uuid.h
SOURCES += ../dust3d/base/uuid.cc
HEADERS += ../dust3d/mesh/box_mesh.h HEADERS += ../dust3d/mesh/box_mesh.h
SOURCES += ../dust3d/mesh/box_mesh.cc SOURCES += ../dust3d/mesh/box_mesh.cc
HEADERS += ../dust3d/mesh/centripetal_catmull_rom_spline.h HEADERS += ../dust3d/mesh/centripetal_catmull_rom_spline.h

View File

@ -1297,7 +1297,7 @@ void DocumentWindow::showCutFaceSettingPopup(const QPoint &globalPos, std::set<d
buttons.resize(cutFaceList.size()); buttons.resize(cutFaceList.size());
for (size_t i = 0; i < cutFaceList.size(); ++i) { for (size_t i = 0; i < cutFaceList.size(); ++i) {
QString cutFaceString = cutFaceList[i]; QString cutFaceString = cutFaceList[i];
dust3d::CutFace cutFace; dust3d::CutFace cutFace = dust3d::CutFace::Quad;
dust3d::Uuid cutFacePartId(cutFaceString.toUtf8().constData()); dust3d::Uuid cutFacePartId(cutFaceString.toUtf8().constData());
QPushButton *button = new QPushButton; QPushButton *button = new QPushButton;
button->setIconSize(QSize(Theme::toolIconSize * 0.75, Theme::toolIconSize * 0.75)); button->setIconSize(QSize(Theme::toolIconSize * 0.75, Theme::toolIconSize * 0.75));

View File

@ -67,7 +67,7 @@ public:
return m_data[0]; return m_data[0];
} }
inline const double right() const inline double right() const
{ {
return left() + width(); return left() + width();
} }
@ -77,7 +77,7 @@ public:
return m_data[1]; return m_data[1];
} }
inline const double bottom() const inline double bottom() const
{ {
return top() + height(); return top() + height();
} }

View File

@ -20,7 +20,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
#include <boost/algorithm/string/join.hpp> #include <numeric>
#include <dust3d/base/string.h> #include <dust3d/base/string.h>
namespace dust3d namespace dust3d
@ -30,7 +30,10 @@ namespace String
std::string join(const std::vector<std::string> &stringList, const char *separator) std::string join(const std::vector<std::string> &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;
});
} }
} }

View File

@ -98,7 +98,7 @@ inline std::string valueOrEmpty(const std::map<std::string, std::string> &map, c
return it->second; return it->second;
} }
static bool isTrue(const std::string &string) inline bool isTrue(const std::string &string)
{ {
return "true" == string || "True" == string || "1" == string; return "true" == string || "True" == string || "1" == string;
} }

30
dust3d/base/uuid.cc Normal file
View File

@ -0,0 +1,30 @@
/*
* Copyright (c) 2016-2021 Jeremy HU <jeremy-at-dust3d dot org>. 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 <dust3d/base/uuid.h>
namespace dust3d
{
Uuid::RandomGenerator *Uuid::m_generator = new Uuid::RandomGenerator;
} // namespace dust3d

View File

@ -23,12 +23,10 @@
#ifndef DUST3D_BASE_UUID_H_ #ifndef DUST3D_BASE_UUID_H_
#define DUST3D_BASE_UUID_H_ #define DUST3D_BASE_UUID_H_
#include <boost/uuid/uuid.hpp> #include <random>
#include <boost/uuid/uuid_generators.hpp> #include <sstream>
#include <boost/uuid/uuid_io.hpp> #include <chrono>
#include <boost/lexical_cast.hpp> #include <ctime>
#include <boost/functional/hash.hpp>
#include <string>
namespace dust3d namespace dust3d
{ {
@ -36,40 +34,105 @@ namespace dust3d
class Uuid class Uuid
{ {
public: public:
Uuid() class RandomGenerator
{
public:
RandomGenerator():
m_randomGenerator(m_randomDevice() + std::chrono::time_point_cast<std::chrono::seconds>(std::chrono::system_clock::now()).time_since_epoch().count()),
m_randomDistribution(0, 15)
{ {
m_uuid = boost::uuids::nil_uuid();
} }
Uuid(const boost::uuids::uuid &uuid) : int generate()
m_uuid(uuid)
{ {
return m_randomDistribution(m_randomGenerator);
} }
private:
std::random_device m_randomDevice;
std::mt19937 m_randomGenerator;
std::uniform_int_distribution<int> m_randomDistribution;
};
static RandomGenerator *m_generator;
Uuid() = default;
Uuid(const std::string &string) Uuid(const std::string &string)
{ {
if (sizeof("{hhhhhhhh-hhhh-hhhh-hhhh-hhhhhhhhhhhh}") - 1 != string.length() || if (sizeof("{hhhhhhhh-hhhh-hhhh-hhhh-hhhhhhhhhhhh}") - 1 == string.length() &&
'{' != string[0]) { '{' == string[0] &&
m_uuid = boost::uuids::nil_uuid(); validate(&string[1], string.length() - 2)) {
m_uuid = string.substr(1, string.length() - 2);
return; return;
} }
m_uuid = boost::lexical_cast<boost::uuids::uuid>( if (sizeof("hhhhhhhh-hhhh-hhhh-hhhh-hhhhhhhhhhhh") - 1 == string.length() &&
string.substr(1, sizeof("hhhhhhhh-hhhh-hhhh-hhhh-hhhhhhhhhhhh") - 1)); 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 bool isNull() const
{ {
return m_uuid.is_nil(); return m_uuid.empty();
} }
std::string toString() const std::string toString() const
{ {
return "{" + to_string(m_uuid) + "}"; return "{" + m_uuid + "}";
} }
static Uuid createUuid() 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: private:
friend std::string to_string(const Uuid &uuid); 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); 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) 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) inline bool operator==(const Uuid &lhs, const Uuid &rhs)
@ -110,7 +173,7 @@ struct hash<dust3d::Uuid>
{ {
size_t operator()(const dust3d::Uuid& uuid) const size_t operator()(const dust3d::Uuid& uuid) const
{ {
return boost::hash<boost::uuids::uuid>()(uuid.m_uuid); return std::hash<std::string>()(uuid.m_uuid);
} }
}; };

View File

@ -21,6 +21,7 @@
*/ */
#include <unordered_set> #include <unordered_set>
#include <functional>
#include <dust3d/base/string.h> #include <dust3d/base/string.h>
#include <dust3d/base/part_target.h> #include <dust3d/base/part_target.h>
#include <dust3d/base/part_base.h> #include <dust3d/base/part_base.h>