Skip to content

Commit

Permalink
Reformat basic pointer usages to west-const
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkewley committed Jun 18, 2024
1 parent 36bae52 commit b562e36
Show file tree
Hide file tree
Showing 63 changed files with 388 additions and 388 deletions.
8 changes: 4 additions & 4 deletions src/OpenSimCreator/ComponentRegistry/ComponentRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ namespace osc
ComponentRegistryBase{name_, description_}
{}

value_type const* begin() const
const value_type* begin() const
{
const auto& base = static_cast<const ComponentRegistryBase&>(*this);
return static_cast<value_type const*>(base.begin());
return static_cast<const value_type*>(base.begin());
}

value_type const* end() const
const value_type* end() const
{
const auto& base = static_cast<const ComponentRegistryBase&>(*this);
return static_cast<value_type const*>(base.end());
return static_cast<const value_type*>(base.end());
}

const value_type& operator[](size_t i) const
Expand Down
4 changes: 2 additions & 2 deletions src/OpenSimCreator/ComponentRegistry/ComponentRegistryBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ namespace osc
CStringView name() const { return m_Name; }
CStringView description() const { return m_Description; }

value_type const* begin() const { return m_Entries.data(); }
value_type const* end() const { return m_Entries.data() + m_Entries.size(); }
const value_type* begin() const { return m_Entries.data(); }
const value_type* end() const { return m_Entries.data() + m_Entries.size(); }
size_t size() const { return m_Entries.size(); }
const value_type& operator[](size_t i) const { return m_Entries[i]; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,28 +277,28 @@ void osc::fd::ActionCreateBodyFromFrame(
// validate external inputs

log_debug("validate external inputs");
auto const* const meshFrame = FindComponent<OpenSim::PhysicalFrame>(model->getModel(), frameAbsPath);
const auto* const meshFrame = FindComponent<OpenSim::PhysicalFrame>(model->getModel(), frameAbsPath);
if (!meshFrame)
{
log_error("%s: cannot find frame: skipping body creation", frameAbsPath.toString().c_str());
return;
}

auto const* const mesh = FindComponent<OpenSim::Mesh>(model->getModel(), meshAbsPath);
const auto* const mesh = FindComponent<OpenSim::Mesh>(model->getModel(), meshAbsPath);
if (!mesh)
{
log_error("%s: cannot find mesh: skipping body creation", meshAbsPath.toString().c_str());
return;
}

auto const* const jointFrame = FindComponent<OpenSim::PhysicalFrame>(model->getModel(), jointFrameAbsPath);
const auto* const jointFrame = FindComponent<OpenSim::PhysicalFrame>(model->getModel(), jointFrameAbsPath);
if (!jointFrame)
{
log_error("%s: cannot find joint frame: skipping body creation", jointFrameAbsPath.toString().c_str());
return;
}

auto const* const parentFrame = FindComponent<OpenSim::PhysicalFrame>(model->getModel(), parentFrameAbsPath);
const auto* const parentFrame = FindComponent<OpenSim::PhysicalFrame>(model->getModel(), parentFrameAbsPath);
if (!parentFrame)
{
log_error("%s: cannot find parent frame: skipping body creation", parentFrameAbsPath.toString().c_str());
Expand Down Expand Up @@ -386,7 +386,7 @@ void osc::fd::ActionCreateBodyFromFrame(

// if the mesh's PoF was only used by the mesh then reassign
// everything to the new PoF and delete the old one
if (auto const* pof = GetOwner<OpenSim::PhysicalOffsetFrame>(*mesh);
if (const auto* pof = GetOwner<OpenSim::PhysicalOffsetFrame>(*mesh);
pof && GetNumChildren(*pof) == 3) // mesh+frame geom+wrap object set
{
log_debug("reassign sockets");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,22 +161,22 @@ void osc::fd::SetupDefault3DViewportRenderingParams(ModelRendererParams& renderP

bool osc::fd::IsPoint(const OpenSim::Component& component)
{
return dynamic_cast<OpenSim::Point const*>(&component) != nullptr;
return dynamic_cast<const OpenSim::Point*>(&component) != nullptr;
}

bool osc::fd::IsMesh(const OpenSim::Component& component)
{
return dynamic_cast<OpenSim::Mesh const*>(&component) != nullptr;
return dynamic_cast<const OpenSim::Mesh*>(&component) != nullptr;
}

bool osc::fd::IsPhysicalFrame(const OpenSim::Component& component)
{
return dynamic_cast<OpenSim::PhysicalFrame const*>(&component) != nullptr;
return dynamic_cast<const OpenSim::PhysicalFrame*>(&component) != nullptr;
}

bool osc::fd::IsEdge(const OpenSim::Component& component)
{
return dynamic_cast<Edge const*>(&component) != nullptr;
return dynamic_cast<const Edge*>(&component) != nullptr;
}

SimTK::UnitVec3 osc::fd::CalcDirection(const EdgePoints& a)
Expand Down
6 changes: 3 additions & 3 deletions src/OpenSimCreator/Documents/MeshImporter/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ namespace osc::mi

bool deleteByID(UID id)
{
MIObject const* const obj = tryGetByID(id);
const MIObject* const obj = tryGetByID(id);
if (!obj)
{
return false; // ID doesn't exist in the document
Expand Down Expand Up @@ -291,7 +291,7 @@ namespace osc::mi

void select(UID id)
{
MIObject const* const e = tryGetByID(id);
const MIObject* const e = tryGetByID(id);

if (e && e->canSelect())
{
Expand Down Expand Up @@ -389,7 +389,7 @@ namespace osc::mi
return *ptr;
}

MIObject const* implFind(UID id) const final
const MIObject* implFind(UID id) const final
{
return findByID(m_Objects, id);
}
Expand Down
12 changes: 6 additions & 6 deletions src/OpenSimCreator/Documents/MeshImporter/DocumentHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ bool osc::mi::IsJointAttachedToGround(
return true; // it's directly attached to ground
}

auto const* const parent = doc.tryGetByID<Body>(joint.getParentID());
const auto* const parent = doc.tryGetByID<Body>(joint.getParentID());
if (!parent)
{
return false; // joint's parent is garbage
Expand Down Expand Up @@ -185,12 +185,12 @@ bool osc::mi::IsInSelectionGroupOf(
return true;
}

Body const* body = nullptr;
if (auto const* be = doc.tryGetByID<Body>(parent))
const Body* body = nullptr;
if (const auto* be = doc.tryGetByID<Body>(parent))
{
body = be;
}
else if (auto const* me = doc.tryGetByID<Mesh>(parent))
else if (const auto* me = doc.tryGetByID<Mesh>(parent))
{
body = doc.tryGetByID<Body>(me->getParentID());
}
Expand All @@ -200,11 +200,11 @@ bool osc::mi::IsInSelectionGroupOf(
return false; // parent isn't attached to any body (or isn't a body)
}

if (auto const* be = doc.tryGetByID<Body>(id))
if (const auto* be = doc.tryGetByID<Body>(id))
{
return be->getID() == body->getID();
}
else if (auto const* me = doc.tryGetByID<Mesh>(id))
else if (const auto* me = doc.tryGetByID<Mesh>(id))
{
return me->getParentID() == body->getID();
}
Expand Down
4 changes: 2 additions & 2 deletions src/OpenSimCreator/Documents/MeshImporter/IObjectFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ namespace osc::mi
public:
virtual ~IObjectFinder() noexcept = default;

MIObject const* find(UID id) const
const MIObject* find(UID id) const
{
return implFind(id);
}
private:
virtual MIObject const* implFind(UID) const = 0;
virtual const MIObject* implFind(UID) const = 0;
};
}
50 changes: 25 additions & 25 deletions src/OpenSimCreator/Documents/MeshImporter/OpenSimBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ namespace
struct JointAttachmentCachedLookupResult final {

// can be nullptr (indicating Ground)
Body const* bodyEl = nullptr;
const Body* bodyEl = nullptr;

// can be nullptr (indicating ground/cache hit)
std::unique_ptr<OpenSim::Body> createdBody;
Expand Down Expand Up @@ -216,11 +216,11 @@ namespace
// returns the indices of each degree of freedom that the joint supports
JointDegreesOfFreedom GetDegreesOfFreedom(const OpenSim::Joint& joint)
{
if (dynamic_cast<OpenSim::FreeJoint const*>(&joint))
if (dynamic_cast<const OpenSim::FreeJoint*>(&joint))
{
return JointDegreesOfFreedom{{0, 1, 2}, {3, 4, 5}};
}
else if (dynamic_cast<OpenSim::PinJoint const*>(&joint))
else if (dynamic_cast<const OpenSim::PinJoint*>(&joint))
{
return JointDegreesOfFreedom{{-1, -1, 0}, {-1, -1, -1}};
}
Expand Down Expand Up @@ -420,28 +420,28 @@ namespace

// tries to find the first body connected to the given PhysicalFrame by assuming
// that the frame is either already a body or is an offset to a body
OpenSim::PhysicalFrame const* TryInclusiveRecurseToBodyOrGround(
const OpenSim::PhysicalFrame* TryInclusiveRecurseToBodyOrGround(
const OpenSim::Frame& f,
std::unordered_set<OpenSim::Frame const*> visitedFrames)
std::unordered_set<const OpenSim::Frame*> visitedFrames)
{
if (!visitedFrames.emplace(&f).second)
{
return nullptr;
}

if (auto const* body = dynamic_cast<OpenSim::Body const*>(&f))
if (const auto* body = dynamic_cast<const OpenSim::Body*>(&f))
{
return body;
}
else if (auto const* ground = dynamic_cast<OpenSim::Ground const*>(&f))
else if (const auto* ground = dynamic_cast<const OpenSim::Ground*>(&f))
{
return ground;
}
else if (auto const* pof = dynamic_cast<OpenSim::PhysicalOffsetFrame const*>(&f))
else if (const auto* pof = dynamic_cast<const OpenSim::PhysicalOffsetFrame*>(&f))
{
return TryInclusiveRecurseToBodyOrGround(pof->getParentFrame(), visitedFrames);
}
else if (auto const* station = dynamic_cast<OpenSim::Station const*>(&f))
else if (const auto* station = dynamic_cast<const OpenSim::Station*>(&f))
{
return TryInclusiveRecurseToBodyOrGround(station->getParentFrame(), visitedFrames);
}
Expand All @@ -453,7 +453,7 @@ namespace

// tries to find the first body connected to the given PhysicalFrame by assuming
// that the frame is either already a body or is an offset to a body
OpenSim::PhysicalFrame const* TryInclusiveRecurseToBodyOrGround(const OpenSim::Frame& f)
const OpenSim::PhysicalFrame* TryInclusiveRecurseToBodyOrGround(const OpenSim::Frame& f)
{
return TryInclusiveRecurseToBodyOrGround(f, {});
}
Expand All @@ -468,10 +468,10 @@ namespace
Document rv;

// used to figure out how a body in the OpenSim::Model maps into the docuemnt
std::unordered_map<OpenSim::Body const*, UID> bodyLookup;
std::unordered_map<const OpenSim::Body*, UID> bodyLookup;

// used to figure out how a joint in the OpenSim::Model maps into the document
std::unordered_map<OpenSim::Joint const*, UID> jointLookup;
std::unordered_map<const OpenSim::Joint*, UID> jointLookup;

// import all the bodies from the model file
for (const OpenSim::Body& b : m.getComponentList<OpenSim::Body>())
Expand All @@ -491,8 +491,8 @@ namespace
const OpenSim::PhysicalFrame& parentFrame = j.getParentFrame();
const OpenSim::PhysicalFrame& childFrame = j.getChildFrame();

OpenSim::PhysicalFrame const* const parentBodyOrGround = TryInclusiveRecurseToBodyOrGround(parentFrame);
OpenSim::PhysicalFrame const* const childBodyOrGround = TryInclusiveRecurseToBodyOrGround(childFrame);
const OpenSim::PhysicalFrame* const parentBodyOrGround = TryInclusiveRecurseToBodyOrGround(parentFrame);
const OpenSim::PhysicalFrame* const childBodyOrGround = TryInclusiveRecurseToBodyOrGround(childFrame);

if (!parentBodyOrGround || !childBodyOrGround)
{
Expand All @@ -501,13 +501,13 @@ namespace
}

UID parent = MIIDs::Empty();
if (dynamic_cast<OpenSim::Ground const*>(parentBodyOrGround))
if (dynamic_cast<const OpenSim::Ground*>(parentBodyOrGround))
{
parent = MIIDs::Ground();
}
else
{
if (auto const* body = lookup_or_nullptr(bodyLookup, dynamic_cast<OpenSim::Body const*>(parentBodyOrGround))) {
if (const auto* body = lookup_or_nullptr(bodyLookup, dynamic_cast<const OpenSim::Body*>(parentBodyOrGround))) {
parent = *body;
}
else {
Expand All @@ -516,14 +516,14 @@ namespace
}

UID child = MIIDs::Empty();
if (dynamic_cast<OpenSim::Ground const*>(childBodyOrGround))
if (dynamic_cast<const OpenSim::Ground*>(childBodyOrGround))
{
// ground can't be a child in a joint
continue;
}
else
{
if (auto const* body = lookup_or_nullptr(bodyLookup, dynamic_cast<OpenSim::Body const*>(childBodyOrGround))) {
if (const auto* body = lookup_or_nullptr(bodyLookup, dynamic_cast<const OpenSim::Body*>(childBodyOrGround))) {
child = *body;
}
else {
Expand Down Expand Up @@ -568,7 +568,7 @@ namespace
}

const OpenSim::Frame& frame = mesh.getFrame();
OpenSim::PhysicalFrame const* const frameBodyOrGround = TryInclusiveRecurseToBodyOrGround(frame);
const OpenSim::PhysicalFrame* const frameBodyOrGround = TryInclusiveRecurseToBodyOrGround(frame);

if (!frameBodyOrGround)
{
Expand All @@ -577,13 +577,13 @@ namespace
}

UID attachment = MIIDs::Empty();
if (dynamic_cast<OpenSim::Ground const*>(frameBodyOrGround))
if (dynamic_cast<const OpenSim::Ground*>(frameBodyOrGround))
{
attachment = MIIDs::Ground();
}
else
{
if (auto const* body = lookup_or_nullptr(bodyLookup, dynamic_cast<OpenSim::Body const*>(frameBodyOrGround))) {
if (const auto* body = lookup_or_nullptr(bodyLookup, dynamic_cast<const OpenSim::Body*>(frameBodyOrGround))) {
attachment = *body;
}
else {
Expand All @@ -609,7 +609,7 @@ namespace
for (const OpenSim::Station& station : m.getComponentList<OpenSim::Station>())
{
// edge-case: it's a path point: ignore it because it will spam the converter
if (dynamic_cast<OpenSim::AbstractPathPoint const*>(&station))
if (dynamic_cast<const OpenSim::AbstractPathPoint*>(&station))
{
continue;
}
Expand All @@ -620,16 +620,16 @@ namespace
}

const OpenSim::PhysicalFrame& frame = station.getParentFrame();
OpenSim::PhysicalFrame const* const frameBodyOrGround = TryInclusiveRecurseToBodyOrGround(frame);
const OpenSim::PhysicalFrame* const frameBodyOrGround = TryInclusiveRecurseToBodyOrGround(frame);

UID attachment = MIIDs::Empty();
if (dynamic_cast<OpenSim::Ground const*>(frameBodyOrGround))
if (dynamic_cast<const OpenSim::Ground*>(frameBodyOrGround))
{
attachment = MIIDs::Ground();
}
else
{
if (auto const it = bodyLookup.find(dynamic_cast<OpenSim::Body const*>(frameBodyOrGround)); it != bodyLookup.end())
if (auto const it = bodyLookup.find(dynamic_cast<const OpenSim::Body*>(frameBodyOrGround)); it != bodyLookup.end())
{
attachment = it->second;
}
Expand Down
Loading

0 comments on commit b562e36

Please sign in to comment.