Remove external dependency on fmtlib in favor of std::format. Begin transition of model::Part into an interface

This commit is contained in:
Travis Hunter 2024-03-14 18:06:05 -06:00
parent 6a015d9797
commit e5c068ddf7
7 changed files with 45 additions and 60 deletions

View File

@ -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

View File

@ -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
} // namespace model

View File

@ -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.

View File

@ -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<double, StateData>& cond) override;
bool terminateCondition(const std::pair<double, StateData>& cond) override;
/**
* @brief setName sets the rocket name

View File

@ -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);
}
}

View File

@ -3,11 +3,10 @@
// C headers
// C++ headers
#include <algorithm>
#include <sstream>
#include <format>
#include <stdexcept>
// 3rd party headers
#include <fmt/core.h>
/// \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

View File

@ -25,5 +25,4 @@ target_include_directories(utils PRIVATE
target_link_libraries(utils PUBLIC
libcurl
jsoncpp_static
fmt::fmt-header-only
eigen)