From e5c068ddf75f544b03b87750cef076bd4b767220 Mon Sep 17 00:00:00 2001 From: Travis Hunter Date: Thu, 14 Mar 2024 18:06:05 -0600 Subject: [PATCH] Remove external dependency on fmtlib in favor of std::format. Begin transition of model::Part into an interface --- CMakeLists.txt | 8 +++--- model/Part.cpp | 20 ++------------- model/Part.h | 51 ++++++++++++++++++++++++--------------- model/Rocket.h | 2 +- model/tests/PartTests.cpp | 16 +++--------- utils/Bin.cpp | 7 +++--- utils/CMakeLists.txt | 1 - 7 files changed, 45 insertions(+), 60 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bc3dc87..122da0c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,10 +17,10 @@ endif() FetchContent_MakeAvailable(googletest) # fmtlib dependency -FetchContent_Declare(fmt - GIT_REPOSITORY https://github.com/fmtlib/fmt - GIT_TAG 9.1.0) -FetchContent_MakeAvailable(fmt) +#FetchContent_Declare(fmt +# GIT_REPOSITORY https://github.com/fmtlib/fmt +# GIT_TAG 9.1.0) +#FetchContent_MakeAvailable(fmt) # jsoncpp dependency FetchContent_Declare(jsoncpp diff --git a/model/Part.cpp b/model/Part.cpp index 8cae619..dedb0c7 100644 --- a/model/Part.cpp +++ b/model/Part.cpp @@ -7,12 +7,7 @@ namespace model Part::Part(const std::string& n, const Matrix3& I, double m, - const Vector3& centerMass, - double l, - double inRadTop, - double outRadTop, - double inRadBottom, - double outRadBottom) + const Vector3& centerMass) : parent(nullptr), name(n), inertiaTensor(I), @@ -20,11 +15,6 @@ Part::Part(const std::string& n, mass(m), compositeMass(m), cm(centerMass), - length(l), - innerRadiusTop(inRadTop), - outerRadiusTop(outRadTop), - innerRadiusBottom(inRadBottom), - outerRadiusBottom(outRadBottom), needsRecomputing(false), childParts() { } @@ -40,11 +30,6 @@ Part::Part(const Part& orig) mass(orig.mass), compositeMass(orig.compositeMass), cm(orig.cm), - length(orig.length), - innerRadiusTop(orig.innerRadiusTop), - outerRadiusTop(orig.outerRadiusTop), - innerRadiusBottom(orig.innerRadiusBottom), - outerRadiusBottom(orig.outerRadiusBottom), needsRecomputing(orig.needsRecomputing), childParts() { @@ -65,7 +50,6 @@ Part::Part(const Part& orig) } - double Part::getChildMasses(double t) { double childMasses{0.0}; @@ -122,4 +106,4 @@ void Part::recomputeInertiaTensor() needsRecomputing = false; } -} // namespace model \ No newline at end of file +} // namespace model diff --git a/model/Part.h b/model/Part.h index 434a65c..42fe0bc 100644 --- a/model/Part.h +++ b/model/Part.h @@ -22,17 +22,43 @@ public: Part(const std::string& name, const Matrix3& I, double m, - const Vector3& centerMass, - double length, - double inRadTop, - double outRadTop, - double inRadBottom, - double outRadBottom); + const Vector3& centerMass); virtual ~Part(); Part(const Part&); + Part& operator=(Part other) + { + if(this != &other) + { + std::swap(parent, other.parent); + std::swap(name, other.name); + std::swap(inertiaTensor, other.inertiaTensor); + std::swap(compositeInertiaTensor, other.compositeInertiaTensor); + std::swap(mass, other.mass); + std::swap(compositeMass, other.compositeMass); + std::swap(cm, other.cm); + std::swap(needsRecomputing, other.needsRecomputing); + std::swap(childParts, other.childParts); + } + return *this; + } + Part& operator=(Part&& other) + { + parent = std::move(other.parent); + name = std::move(other.name); + inertiaTensor = std::move(other.inertiaTensor); + compositeInertiaTensor = std::move(other.compositeInertiaTensor); + mass = std::move(other.mass); + compositeMass = std::move(other.compositeMass); + cm = std::move(other.cm); + needsRecomputing = std::move(other.needsRecomputing); + childParts = std::move(other.childParts); + + return *this; + } + void setMass(double m) { mass = m; } // Set the inertia tensor @@ -42,11 +68,6 @@ public: // Special version of setCM that assumes the cm lies along the body x-axis void setCm(double x) { cm = {x, 0.0, 0.0}; } - void setLength(double l) { length = l; } - - void setInnerRadius(double r) { innerRadiusTop = r; innerRadiusBottom = r; } - void setOuterRadius(double r) { outerRadiusTop = r; outerRadiusBottom = r; } - double getMass(double t) { return mass; @@ -101,14 +122,6 @@ private: Vector3 cm; // center of mass wrt middle of component - double length; - - double innerRadiusTop; - double outerRadiusTop; - - double innerRadiusBottom; - double outerRadiusBottom; - bool needsRecomputing{false}; /// @brief child parts and the relative positions of their center of mass w.r.t. diff --git a/model/Rocket.h b/model/Rocket.h index 4078924..d0c3bb4 100644 --- a/model/Rocket.h +++ b/model/Rocket.h @@ -76,7 +76,7 @@ public: * @param cond time/state pair * @return true if the passed-in time/state satisfies the terminate condition */ - virtual bool terminateCondition(const std::pair& cond) override; + bool terminateCondition(const std::pair& cond) override; /** * @brief setName sets the rocket name diff --git a/model/tests/PartTests.cpp b/model/tests/PartTests.cpp index f985d3a..6e23d7d 100644 --- a/model/tests/PartTests.cpp +++ b/model/tests/PartTests.cpp @@ -52,12 +52,7 @@ TEST(PartTest, CreationTests) model::Part testPart("testPart", inertia, 1.0, - cm, - 2.0, - 1.0, - 1.1, - 1.1, - 1.0); + cm); Matrix3 inertia2; inertia2 << 1, 0, 0, @@ -67,14 +62,9 @@ TEST(PartTest, CreationTests) model::Part testPart2("testPart2", inertia2, 1.0, - cm2, - 2.0, - 1.0, - 1.1, - 1.1, - 1.0); + cm2); Vector3 R{2.0, 2.0, 2.0}; testPart.addChildPart(testPart2, R); -} \ No newline at end of file +} diff --git a/utils/Bin.cpp b/utils/Bin.cpp index 5130bd1..8f9b15f 100644 --- a/utils/Bin.cpp +++ b/utils/Bin.cpp @@ -3,11 +3,10 @@ // C headers // C++ headers #include -#include +#include #include // 3rd party headers -#include /// \endcond // qtrocket headers @@ -56,7 +55,7 @@ double Bin::operator[](double key) if(key < iter->first) { throw std::out_of_range( - fmt::format("{} less than lower bound {} of BinMap", key, iter->first)); + std::format("{} less than lower bound {} of BinMap", key, iter->first)); } // Increment it and start searching If we reach the end without finding an existing key // greater than our search term, then we've just hit the last bin and return that @@ -84,7 +83,7 @@ double Bin::getBinBase(double key) if(key < iter->first) { throw std::out_of_range( - fmt::format("{} less than lower bound {} of BinMap", key, iter->first)); + std::format("{} less than lower bound {} of BinMap", key, iter->first)); } // Increment it and start searching If we reach the end without finding an existing key // greater than our search term, then we've just hit the last bin and return that diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index c748e02..b3a1765 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -25,5 +25,4 @@ target_include_directories(utils PRIVATE target_link_libraries(utils PUBLIC libcurl jsoncpp_static - fmt::fmt-header-only eigen)