Skip to content

Commit

Permalink
Reformat west-const the remainder of src/OpenSimCreator
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkewley committed Jun 18, 2024
1 parent bdc9004 commit 8dd3e98
Show file tree
Hide file tree
Showing 132 changed files with 476 additions and 607 deletions.
8 changes: 4 additions & 4 deletions src/OpenSimCreator/ComponentRegistry/ComponentRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace osc
ComponentRegistryEntry<T>& emplace_back(
std::string_view name,
std::string_view description,
std::shared_ptr<T const> prototype)
std::shared_ptr<const T> prototype)
{
auto& erased = push_back_erased(ComponentRegistryEntry<T>
{
Expand All @@ -58,7 +58,7 @@ namespace osc
};

template<typename T>
ComponentRegistryEntry<T> const& At(ComponentRegistry<T> const& registry, size_t i)
const ComponentRegistryEntry<T>& At(const ComponentRegistry<T>& registry, size_t i)
{
if (i >= registry.size()) {
throw std::out_of_range{"attempted to access an out-of-bounds registry entry"};
Expand All @@ -67,7 +67,7 @@ namespace osc
}

template<typename T>
ComponentRegistryEntry<T> const& Get(ComponentRegistry<T> const& registry, T const& el)
const ComponentRegistryEntry<T>& Get(ComponentRegistry<T> const& registry, const T& el)
{
if (auto i = IndexOf(registry, el)) {
return registry[*i];
Expand All @@ -78,7 +78,7 @@ namespace osc
}

template<typename T>
ComponentRegistryEntry<T> const& Get(ComponentRegistry<T> const& registry, std::string_view componentClassName)
const ComponentRegistryEntry<T>& Get(const ComponentRegistry<T>& registry, std::string_view componentClassName)
{
if (auto i = IndexOf(registry, componentClassName)) {
return registry[*i];
Expand Down
6 changes: 3 additions & 3 deletions src/OpenSimCreator/ComponentRegistry/ComponentRegistryEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ namespace osc
ComponentRegistryEntry(
std::string_view name_,
std::string_view description_,
std::shared_ptr<T const> prototype_) :
std::shared_ptr<const T> prototype_) :

ComponentRegistryEntryBase{name_, description_, std::move(prototype_)}
{}

T const& prototype() const
const T& prototype() const
{
const auto& base = static_cast<const ComponentRegistryEntryBase&>(*this);
return static_cast<T const&>(base.prototype());
return static_cast<const T&>(base.prototype());
}

std::unique_ptr<T> instantiate() const
Expand Down
56 changes: 28 additions & 28 deletions src/OpenSimCreator/ComponentRegistry/StaticComponentRegistries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ namespace
}

// returns a cached version of the custom component lookup
std::vector<std::shared_ptr<const OpenSim::Component>> const& GetCustomComponentList()
const std::vector<std::shared_ptr<const OpenSim::Component>>& GetCustomComponentList()
{
static std::vector<std::shared_ptr<const OpenSim::Component>> const s_CustomComponentLUT = CreateCustomComponentList();
static const std::vector<std::shared_ptr<const OpenSim::Component>> s_CustomComponentLUT = CreateCustomComponentList();
return s_CustomComponentLUT;
}

Expand Down Expand Up @@ -313,9 +313,9 @@ namespace
}

// returns a cached version of the description lookup
std::unordered_map<CStringView, CStringView> const& GetComponentDescriptionLookup()
const std::unordered_map<CStringView, CStringView>& GetComponentDescriptionLookup()
{
static std::unordered_map<CStringView, CStringView> const s_Lut = CreateComponentDescriptionLookup();
static const std::unordered_map<CStringView, CStringView> s_Lut = CreateComponentDescriptionLookup();
return s_Lut;
}

Expand Down Expand Up @@ -390,9 +390,9 @@ namespace
}

// cached version of the above
std::unordered_set<std::string> const& GetComponentBlacklist()
const std::unordered_set<std::string>& GetComponentBlacklist()
{
static std::unordered_set<std::string> const s_Blacklist = CreateComponentBlacklist();
static const std::unordered_set<std::string> s_Blacklist = CreateComponentBlacklist();
return s_Blacklist;
}

Expand Down Expand Up @@ -424,9 +424,9 @@ namespace
}

// cached version of the above
std::unordered_set<std::string> const& GetSetOfAllGroupedElements()
const std::unordered_set<std::string>& GetSetOfAllGroupedElements()
{
static std::unordered_set<std::string> const s_GroupedEls = CreateSetOfAllGroupedElements();
static const std::unordered_set<std::string> s_GroupedEls = CreateSetOfAllGroupedElements();
return s_GroupedEls;
}

Expand Down Expand Up @@ -617,27 +617,27 @@ namespace
};
}

std::unordered_map<CStringView, std::shared_ptr<const OpenSim::Component>> const& GetPrototypeLut()
const std::unordered_map<CStringView, std::shared_ptr<const OpenSim::Component>>& GetPrototypeLut()
{
static std::unordered_map<CStringView, std::shared_ptr<const OpenSim::Component>> const s_Lut = CreatePrototypeLut();
static const std::unordered_map<CStringView, std::shared_ptr<const OpenSim::Component>> s_Lut = CreatePrototypeLut();
return s_Lut;
}

template<std::derived_from<OpenSim::Component> T>
std::vector<std::shared_ptr<T const>> CreatePrototypeLutT(bool useBlacklist = true)
std::vector<std::shared_ptr<const T>> CreatePrototypeLutT(bool useBlacklist = true)
{
OpenSim::ArrayPtrs<T> ptrs;
OpenSim::Object::getRegisteredObjectsOfGivenType<T>(ptrs);

std::vector<std::shared_ptr<T const>> rv;
std::vector<std::shared_ptr<const T>> rv;
rv.reserve(ptrs.size());

const auto& protoLut = GetPrototypeLut();
const auto& blacklistLut = GetComponentBlacklist();

for (int i = 0; i < ptrs.size(); ++i)
{
T const& v = *ptrs[i];
const T& v = *ptrs[i];
const std::string& name = v.getConcreteClassName();
if (useBlacklist && blacklistLut.contains(name))
{
Expand All @@ -647,7 +647,7 @@ namespace
if (auto it = protoLut.find(name); it != protoLut.end())
{
// it has already been manually created in the prototype LUT - use that
std::shared_ptr<T const> p = std::dynamic_pointer_cast<T const>(it->second);
std::shared_ptr<const T> p = std::dynamic_pointer_cast<const T>(it->second);
if (p)
{
rv.push_back(p);
Expand All @@ -671,8 +671,8 @@ namespace

std::vector<std::shared_ptr<const OpenSim::Component>> CreateOtherComponentLut()
{
std::unordered_set<std::string> const& grouped = GetSetOfAllGroupedElements();
std::unordered_set<std::string> const& blacklisted = GetComponentBlacklist();
const std::unordered_set<std::string>& grouped = GetSetOfAllGroupedElements();
const std::unordered_set<std::string>& blacklisted = GetComponentBlacklist();

OpenSim::ArrayPtrs<OpenSim::ModelComponent> ptrs;
OpenSim::Object::getRegisteredObjectsOfGivenType<OpenSim::ModelComponent>(ptrs);
Expand Down Expand Up @@ -708,13 +708,13 @@ namespace
ComponentRegistry<T> CreateRegistryFromLUT(
std::string_view name,
std::string_view description,
std::vector<std::shared_ptr<T const>> const& protoLut)
const std::vector<std::shared_ptr<const T>>& protoLut)
{
ComponentRegistry<T> rv{name, description};

// populate entries
const auto& lut = GetComponentDescriptionLookup();
for (std::shared_ptr<T const> const& el : protoLut)
for (const std::shared_ptr<const T>& el : protoLut)
{
std::string elName = el->getConcreteClassName();
std::string elDescription;
Expand Down Expand Up @@ -754,7 +754,7 @@ namespace
}

template<>
ComponentRegistry<OpenSim::Joint> const& osc::GetComponentRegistry()
const ComponentRegistry<OpenSim::Joint>& osc::GetComponentRegistry()
{
static const auto s_StaticReg = CreateRegistry<OpenSim::Joint>(
"Joint",
Expand All @@ -764,7 +764,7 @@ ComponentRegistry<OpenSim::Joint> const& osc::GetComponentRegistry()
}

template<>
ComponentRegistry<OpenSim::ContactGeometry> const& osc::GetComponentRegistry()
const ComponentRegistry<OpenSim::ContactGeometry>& osc::GetComponentRegistry()
{
static const auto s_StaticReg = CreateRegistry<OpenSim::ContactGeometry>(
"Contact Geometry",
Expand All @@ -774,7 +774,7 @@ ComponentRegistry<OpenSim::ContactGeometry> const& osc::GetComponentRegistry()
}

template<>
ComponentRegistry<OpenSim::Constraint> const& osc::GetComponentRegistry()
const ComponentRegistry<OpenSim::Constraint>& osc::GetComponentRegistry()
{
static const auto s_StaticReg = CreateRegistry<OpenSim::Constraint>(
"Constraint",
Expand All @@ -784,7 +784,7 @@ ComponentRegistry<OpenSim::Constraint> const& osc::GetComponentRegistry()
}

template<>
ComponentRegistry<OpenSim::Force> const& osc::GetComponentRegistry()
const ComponentRegistry<OpenSim::Force>& osc::GetComponentRegistry()
{
static const auto s_StaticReg = CreateRegistry<OpenSim::Force>(
"Force",
Expand All @@ -794,7 +794,7 @@ ComponentRegistry<OpenSim::Force> const& osc::GetComponentRegistry()
}

template<>
ComponentRegistry<OpenSim::Controller> const& osc::GetComponentRegistry()
const ComponentRegistry<OpenSim::Controller>& osc::GetComponentRegistry()
{
static const auto s_StaticReg = CreateRegistry<OpenSim::Controller>(
"Controller",
Expand All @@ -804,7 +804,7 @@ ComponentRegistry<OpenSim::Controller> const& osc::GetComponentRegistry()
}

template<>
ComponentRegistry<OpenSim::Probe> const& osc::GetComponentRegistry()
const ComponentRegistry<OpenSim::Probe>& osc::GetComponentRegistry()
{
static const auto s_StaticReg = CreateRegistry<OpenSim::Probe>(
"Probe",
Expand All @@ -814,7 +814,7 @@ ComponentRegistry<OpenSim::Probe> const& osc::GetComponentRegistry()
}

template<>
ComponentRegistry<OpenSim::WrapObject> const& osc::GetComponentRegistry()
const ComponentRegistry<OpenSim::WrapObject>& osc::GetComponentRegistry()
{
static const auto s_StaticReg = CreateRegistry<OpenSim::WrapObject>(
"WrapObject",
Expand All @@ -825,7 +825,7 @@ ComponentRegistry<OpenSim::WrapObject> const& osc::GetComponentRegistry()
}

template<>
ComponentRegistry<OpenSim::Component> const& osc::GetComponentRegistry()
const ComponentRegistry<OpenSim::Component>& osc::GetComponentRegistry()
{
static const auto s_StaticReg = CreateOtherComponentRegistry(
"Component",
Expand All @@ -834,7 +834,7 @@ ComponentRegistry<OpenSim::Component> const& osc::GetComponentRegistry()
return s_StaticReg;
}

ComponentRegistry<OpenSim::Component> const& osc::GetCustomComponentRegistry()
const ComponentRegistry<OpenSim::Component>& osc::GetCustomComponentRegistry()
{
static const auto s_StaticReg = CreateCustomComponentRegistry(
"Experimental Components",
Expand All @@ -843,7 +843,7 @@ ComponentRegistry<OpenSim::Component> const& osc::GetCustomComponentRegistry()
return s_StaticReg;
}

ComponentRegistry<OpenSim::Component> const& osc::GetAllRegisteredComponents()
const ComponentRegistry<OpenSim::Component>& osc::GetAllRegisteredComponents()
{
static const auto s_StaticReg = CreateRegistry<OpenSim::Component>(
"All Components",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace osc { template<typename> class ComponentRegistry; }
namespace osc
{
template<typename T>
ComponentRegistry<T> const& GetComponentRegistry();
const ComponentRegistry<T>& GetComponentRegistry();

ComponentRegistry<OpenSim::Component> const& GetCustomComponentRegistry();
const ComponentRegistry<OpenSim::Component>& GetCustomComponentRegistry();

ComponentRegistry<OpenSim::Component> const& GetAllRegisteredComponents();
const ComponentRegistry<OpenSim::Component>& GetAllRegisteredComponents();
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ namespace osc

void generateCustomDecorations(
const SimTK::State& state,
std::function<void(SceneDecoration&&)> const& callback) const
const std::function<void(SceneDecoration&&)>& callback) const
{
implGenerateCustomDecorations(state, callback);
}
private:
virtual void implGenerateCustomDecorations(
const SimTK::State&,
std::function<void(SceneDecoration&&)> const&
const std::function<void(SceneDecoration&&)>&
) const = 0;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

void osc::mow::InMemoryMesh::implGenerateCustomDecorations(
const SimTK::State& state,
std::function<void(SceneDecoration&&)> const& out) const
const std::function<void(SceneDecoration&&)>& out) const
{
out({
.mesh = m_OscMesh,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace osc::mow
// do nothing: OpenSim Creator will detect `ICustomDecorationDecorator` and use that
}
private:
void implGenerateCustomDecorations(const SimTK::State&, std::function<void(SceneDecoration&&)> const&) const override;
void implGenerateCustomDecorations(const SimTK::State&, const std::function<void(SceneDecoration&&)>&) const override;

Mesh m_OscMesh;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
void osc::fd::ActionAddSphereInMeshFrame(
UndoableModelStatePair& model,
const OpenSim::Mesh& mesh,
std::optional<Vec3> const& maybeClickPosInGround)
const std::optional<Vec3>& maybeClickPosInGround)
{
// if the caller requests a location via a click, set the position accordingly
const SimTK::Vec3 locationInMeshFrame = maybeClickPosInGround ?
Expand Down Expand Up @@ -63,7 +63,7 @@ void osc::fd::ActionAddSphereInMeshFrame(
void osc::fd::ActionAddOffsetFrameInMeshFrame(
UndoableModelStatePair& model,
const OpenSim::Mesh& mesh,
std::optional<Vec3> const& maybeClickPosInGround)
const std::optional<Vec3>& maybeClickPosInGround)
{
// if the caller requests a location via a click, set the position accordingly
const SimTK::Vec3 locationInMeshFrame = maybeClickPosInGround ?
Expand Down Expand Up @@ -237,7 +237,7 @@ void osc::fd::ActionSwapCrossProductEdgeOperands(
}

void osc::fd::ActionAddFrame(
std::shared_ptr<UndoableModelStatePair> const& model,
const std::shared_ptr<UndoableModelStatePair>& model,
const Edge& firstEdge,
CoordinateDirection firstEdgeAxis,
const Edge& otherEdge,
Expand Down Expand Up @@ -268,7 +268,7 @@ void osc::fd::ActionAddFrame(
}

void osc::fd::ActionCreateBodyFromFrame(
std::shared_ptr<UndoableModelStatePair> const& model,
const std::shared_ptr<UndoableModelStatePair>& model,
const OpenSim::ComponentPath& frameAbsPath,
const OpenSim::ComponentPath& meshAbsPath,
const OpenSim::ComponentPath& jointFrameAbsPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ namespace osc::fd
void ActionAddSphereInMeshFrame(
UndoableModelStatePair&,
const OpenSim::Mesh&,
std::optional<Vec3> const& maybeClickPosInGround
const std::optional<Vec3>& maybeClickPosInGround
);

void ActionAddOffsetFrameInMeshFrame(
UndoableModelStatePair&,
const OpenSim::Mesh&,
std::optional<Vec3> const& maybeClickPosInGround
const std::optional<Vec3>& maybeClickPosInGround
);

void ActionAddPointToPointEdge(
Expand Down Expand Up @@ -67,15 +67,15 @@ namespace osc::fd
);

void ActionAddFrame(
std::shared_ptr<UndoableModelStatePair> const&,
const std::shared_ptr<UndoableModelStatePair>&,
const Edge& firstEdge,
CoordinateDirection firstEdgeAxis,
const Edge& otherEdge,
const OpenSim::Point& origin
);

void ActionCreateBodyFromFrame(
std::shared_ptr<UndoableModelStatePair> const&,
const std::shared_ptr<UndoableModelStatePair>&,
const OpenSim::ComponentPath& frameAbsPath,
const OpenSim::ComponentPath& meshAbsPath,
const OpenSim::ComponentPath& jointFrameAbsPath,
Expand Down
Loading

0 comments on commit 8dd3e98

Please sign in to comment.