Skip to content

Commit

Permalink
Refactor template args to west-const
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkewley committed Jun 18, 2024
1 parent 8dae5de commit bdc9004
Show file tree
Hide file tree
Showing 73 changed files with 158 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
osc::ComponentRegistryEntryBase::ComponentRegistryEntryBase(
std::string_view name_,
std::string_view description_,
std::shared_ptr<OpenSim::Component const> prototype_) :
std::shared_ptr<const OpenSim::Component> prototype_) :

m_Name{name_},
m_Description{description_},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace osc
ComponentRegistryEntryBase(
std::string_view name_,
std::string_view description_,
std::shared_ptr<OpenSim::Component const>
std::shared_ptr<const OpenSim::Component>
);

CStringView name() const { return m_Name; }
Expand All @@ -25,6 +25,6 @@ namespace osc
private:
std::string m_Name;
std::string m_Description;
std::shared_ptr<OpenSim::Component const> m_Prototype;
std::shared_ptr<const OpenSim::Component> m_Prototype;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ namespace
// these are components that are only available in OpenSim Creator: either because they're
// custom (as in, they are in OSC's source tree), or because OpenSim hasn't released a
// version that includes the component
std::vector<std::shared_ptr<OpenSim::Component const>> CreateCustomComponentList()
std::vector<std::shared_ptr<const OpenSim::Component>> CreateCustomComponentList()
{
return {
std::make_shared<CrossProductEdge>(),
Expand All @@ -96,9 +96,9 @@ namespace
}

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

Expand Down Expand Up @@ -431,7 +431,7 @@ namespace
}

// create a lookup of pre-initialized prototype components
std::unordered_map<CStringView, std::shared_ptr<OpenSim::Component const>> CreatePrototypeLut()
std::unordered_map<CStringView, std::shared_ptr<const OpenSim::Component>> CreatePrototypeLut()
{
return
{
Expand Down Expand Up @@ -617,9 +617,9 @@ namespace
};
}

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

Expand Down Expand Up @@ -669,15 +669,15 @@ namespace
return rv;
}

std::vector<std::shared_ptr<OpenSim::Component const>> CreateOtherComponentLut()
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();

OpenSim::ArrayPtrs<OpenSim::ModelComponent> ptrs;
OpenSim::Object::getRegisteredObjectsOfGivenType<OpenSim::ModelComponent>(ptrs);

std::vector<std::shared_ptr<OpenSim::Component const>> rv;
std::vector<std::shared_ptr<const OpenSim::Component>> rv;

for (int i = 0; i < ptrs.size(); ++i)
{
Expand Down
6 changes: 3 additions & 3 deletions src/OpenSimCreator/Documents/Landmarks/LandmarkHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace

using ParseResult = std::variant<Landmark, CSVParseWarning, SkipRow>;

ParseResult ParseRow(size_t lineNum, std::span<std::string const> cols)
ParseResult ParseRow(size_t lineNum, std::span<const std::string> cols)
{
if (cols.empty() || (cols.size() == 1 && strip_whitespace(cols.front()).empty()))
{
Expand All @@ -38,7 +38,7 @@ namespace

// >=4 columns implies that the first column is a label column
std::optional<std::string> maybeName;
std::span<std::string const> data = cols;
std::span<const std::string> data = cols;
if (cols.size() >= 4)
{
maybeName = cols.front();
Expand Down Expand Up @@ -149,7 +149,7 @@ void osc::lm::WriteLandmarksToCSV(
}

std::vector<NamedLandmark> osc::lm::GenerateNames(
std::span<Landmark const> lms,
std::span<const Landmark> lms,
std::string_view prefix)
{
// collect up all already-named landmarks
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSimCreator/Documents/Landmarks/LandmarkHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace osc::lm
// generates names for any unnamed landmarks and ensures that the names are
// unique amongst all supplied landmarks (both named and unnamed)
std::vector<NamedLandmark> GenerateNames(
std::span<Landmark const>,
std::span<const Landmark>,
std::string_view prefix = "unnamed_"
);
}
4 changes: 2 additions & 2 deletions src/OpenSimCreator/Documents/MeshImporter/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ namespace osc::mi
}

// conversion to a const version of the iterator
explicit operator Iterator<value_type const>() const
explicit operator Iterator<const value_type>() const
{
return Iterator<value_type const>{m_Pos, m_End};
return Iterator<const value_type>{m_Pos, m_End};
}

// LegacyIterator
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSimCreator/Documents/MeshImporter/MIClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,6 @@ namespace osc::mi
mutable std::atomic<int32_t> uniqueCounter = 0;
};

std::shared_ptr<Data const> m_Data;
std::shared_ptr<const Data> m_Data;
};
}
10 changes: 5 additions & 5 deletions src/OpenSimCreator/Documents/MeshImporter/MIVariant.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ namespace osc::mi

// a variant for storing a `const` reference to a `const` object
using ConstSceneElVariant = std::variant<
std::reference_wrapper<Ground const>,
std::reference_wrapper<Mesh const>,
std::reference_wrapper<Body const>,
std::reference_wrapper<Joint const>,
std::reference_wrapper<StationEl const>
std::reference_wrapper<const Ground>,
std::reference_wrapper<const Mesh>,
std::reference_wrapper<const Body>,
std::reference_wrapper<const Joint>,
std::reference_wrapper<const StationEl>
>;

// a variant for storing a non-`const` reference to a non-`const` object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ bool osc::mi::AddStationAtLocation(

void osc::mi::ActionImportLandmarks(
UndoableDocument& udoc,
std::span<lm::NamedLandmark const> landmarks,
std::span<const lm::NamedLandmark> landmarks,
std::optional<std::string> maybeName)
{
Document& doc = udoc.upd_scratch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ namespace osc::mi

void ActionImportLandmarks(
UndoableDocument&,
std::span<lm::NamedLandmark const>,
std::span<const lm::NamedLandmark>,
std::optional<std::string> maybeName = std::nullopt
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace osc
return m_CachedResultMesh;
}

std::span<Vec3 const> getWarpedNonParticipatingLandmarkLocations(const TPSDocument& doc)
std::span<const Vec3> getWarpedNonParticipatingLandmarkLocations(const TPSDocument& doc)
{
updateAll(doc);
return m_CachedResultNonParticipatingLandmarks;
Expand Down
4 changes: 2 additions & 2 deletions src/OpenSimCreator/Documents/Model/ModelStateCommit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class osc::ModelStateCommit::Impl final {
return m_CommitMessage;
}

SynchronizedValueGuard<OpenSim::Model const> getModel() const
SynchronizedValueGuard<const OpenSim::Model> getModel() const
{
return {m_AccessMutex, *m_Model};
}
Expand Down Expand Up @@ -118,7 +118,7 @@ CStringView osc::ModelStateCommit::getCommitMessage() const
return m_Impl->getCommitMessage();
}

SynchronizedValueGuard<OpenSim::Model const> osc::ModelStateCommit::getModel() const
SynchronizedValueGuard<const OpenSim::Model> osc::ModelStateCommit::getModel() const
{
return m_Impl->getModel();
}
Expand Down
4 changes: 2 additions & 2 deletions src/OpenSimCreator/Documents/Model/ModelStateCommit.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ namespace osc
UID getParentID() const;
std::chrono::system_clock::time_point getCommitTime() const;
CStringView getCommitMessage() const;
SynchronizedValueGuard<OpenSim::Model const> getModel() const;
SynchronizedValueGuard<const OpenSim::Model> getModel() const;
UID getModelVersion() const;
float getFixupScaleFactor() const;

friend bool operator==(const ModelStateCommit&, const ModelStateCommit&) = default;
private:
class Impl;
std::shared_ptr<Impl const> m_Impl;
std::shared_ptr<const Impl> m_Impl;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -2265,7 +2265,7 @@ bool osc::ActionFitPlaneToMesh(

bool osc::ActionImportLandmarks(
UndoableModelStatePair& model,
std::span<lm::NamedLandmark const> lms,
std::span<const lm::NamedLandmark> lms,
std::optional<std::string> maybeName)
{
try
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSimCreator/Documents/Model/UndoableModelActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ namespace osc

bool ActionImportLandmarks(
UndoableModelStatePair&,
std::span<lm::NamedLandmark const>,
std::span<const lm::NamedLandmark>,
std::optional<std::string> maybeName
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ namespace

class osc::mow::CachedModelWarper::Impl final {
public:
std::shared_ptr<IConstModelStatePair const> warp(const ModelWarpDocument& document)
std::shared_ptr<const IConstModelStatePair> warp(const ModelWarpDocument& document)
{
if (document != m_PreviousDocument) {
m_PreviousResult = createWarpedModel(document);
Expand All @@ -97,7 +97,7 @@ class osc::mow::CachedModelWarper::Impl final {
return m_PreviousResult;
}

std::shared_ptr<IConstModelStatePair const> createWarpedModel(const ModelWarpDocument& document)
std::shared_ptr<const IConstModelStatePair> createWarpedModel(const ModelWarpDocument& document)
{
// copy the model into an editable "warped" version
OpenSim::Model warpedModel{document.model()};
Expand Down Expand Up @@ -200,7 +200,7 @@ class osc::mow::CachedModelWarper::Impl final {
}
private:
std::optional<ModelWarpDocument> m_PreviousDocument;
std::shared_ptr<IConstModelStatePair const> m_PreviousResult;
std::shared_ptr<const IConstModelStatePair> m_PreviousResult;
};

osc::mow::CachedModelWarper::CachedModelWarper() :
Expand All @@ -210,7 +210,7 @@ osc::mow::CachedModelWarper::CachedModelWarper(CachedModelWarper&&) noexcept = d
CachedModelWarper& osc::mow::CachedModelWarper::operator=(CachedModelWarper&&) noexcept = default;
osc::mow::CachedModelWarper::~CachedModelWarper() noexcept = default;

std::shared_ptr<IConstModelStatePair const> osc::mow::CachedModelWarper::warp(const ModelWarpDocument& document)
std::shared_ptr<const IConstModelStatePair> osc::mow::CachedModelWarper::warp(const ModelWarpDocument& document)
{
return m_Impl->warp(document);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace osc::mow
CachedModelWarper& operator=(CachedModelWarper&&) noexcept;
~CachedModelWarper() noexcept;

std::shared_ptr<IConstModelStatePair const> warp(const ModelWarpDocument&);
std::shared_ptr<const IConstModelStatePair> warp(const ModelWarpDocument&);
private:
class Impl;
std::unique_ptr<Impl> m_Impl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ namespace
return PairLandmarks(std::move(src), std::move(dest));
}

TPSCoefficients3D TryCalcTPSCoefficients(std::span<MaybePairedLandmark const> maybePairs)
TPSCoefficients3D TryCalcTPSCoefficients(std::span<const MaybePairedLandmark> maybePairs)
{
TPSCoefficientSolverInputs3D rv;
for (const MaybePairedLandmark& maybePair: maybePairs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ std::optional<CStringView> osc::GetOutputSubfieldLabel(ComponentOutputSubfield s
}
}

std::span<ComponentOutputSubfield const> osc::GetAllSupportedOutputSubfields()
std::span<const ComponentOutputSubfield> osc::GetAllSupportedOutputSubfields()
{
return c_OutputSubfieldsLut;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace osc
}

std::optional<CStringView> GetOutputSubfieldLabel(ComponentOutputSubfield);
std::span<ComponentOutputSubfield const> GetAllSupportedOutputSubfields();
std::span<const ComponentOutputSubfield> GetAllSupportedOutputSubfields();

// tests if the output produces numeric values (e.g. float, Vec3, etc. - as opposed to std::string)
bool ProducesExtractableNumericValues(const OpenSim::AbstractOutput&);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ float osc::IOutputExtractor::getValueFloat(

void osc::IOutputExtractor::getValuesFloat(
const OpenSim::Component& component,
std::span<SimulationReport const> reports,
std::span<const SimulationReport> reports,
std::function<void(float)> const& consumer) const
{
const OutputValueExtractor extractor = getOutputValueExtractor(component);
Expand All @@ -34,7 +34,7 @@ void osc::IOutputExtractor::getValuesFloat(

std::vector<float> osc::IOutputExtractor::slurpValuesFloat(
const OpenSim::Component& component,
std::span<SimulationReport const> reports) const
std::span<const SimulationReport> reports) const
{
const OutputValueExtractor extractor = getOutputValueExtractor(component);

Expand All @@ -56,7 +56,7 @@ Vec2 osc::IOutputExtractor::getValueVec2(

void osc::IOutputExtractor::getValuesVec2(
const OpenSim::Component& component,
std::span<SimulationReport const> reports,
std::span<const SimulationReport> reports,
std::function<void(Vec2)> const& consumer) const
{
const OutputValueExtractor extractor = getOutputValueExtractor(component);
Expand All @@ -67,7 +67,7 @@ void osc::IOutputExtractor::getValuesVec2(

std::vector<Vec2> osc::IOutputExtractor::slurpValuesVec2(
const OpenSim::Component& component,
std::span<SimulationReport const> reports) const
std::span<const SimulationReport> reports) const
{
const OutputValueExtractor extractor = getOutputValueExtractor(component);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ namespace osc

void getValuesFloat(
const OpenSim::Component&,
std::span<SimulationReport const>,
std::span<const SimulationReport>,
std::function<void(float)> const& consumer
) const;

std::vector<float> slurpValuesFloat(
const OpenSim::Component&,
std::span<SimulationReport const>
std::span<const SimulationReport>
) const;

Vec2 getValueVec2(
Expand All @@ -66,13 +66,13 @@ namespace osc

void getValuesVec2(
const OpenSim::Component&,
std::span<SimulationReport const>,
std::span<const SimulationReport>,
std::function<void(Vec2)> const& consumer
) const;

std::vector<Vec2> slurpValuesVec2(
const OpenSim::Component&,
std::span<SimulationReport const>
std::span<const SimulationReport>
) const;

std::string getValueString(
Expand Down
Loading

0 comments on commit bdc9004

Please sign in to comment.