Skip to content

Commit

Permalink
Merge branch 'reformat_west-const-via-scripts'
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkewley committed Jun 18, 2024
2 parents a5b67e4 + aaf1a65 commit 87fcb3c
Show file tree
Hide file tree
Showing 301 changed files with 4,158 additions and 4,301 deletions.
26 changes: 13 additions & 13 deletions src/OpenSimCreator/ComponentRegistry/ComponentRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,28 @@ namespace osc
ComponentRegistryBase{name_, description_}
{}

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

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

value_type const& operator[](size_t i) const
const value_type& operator[](size_t i) const
{
auto const& base = static_cast<ComponentRegistryBase const&>(*this);
return static_cast<value_type const&>(base[i]);
const auto& base = static_cast<const ComponentRegistryBase&>(*this);
return static_cast<const value_type&>(base[i]);
}

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
10 changes: 5 additions & 5 deletions src/OpenSimCreator/ComponentRegistry/ComponentRegistryBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
#include <typeinfo>

std::optional<size_t> osc::IndexOf(
ComponentRegistryBase const& registry,
const ComponentRegistryBase& registry,
std::string_view componentClassName)
{
for (size_t i = 0; i < registry.size(); ++i) {
OpenSim::Component const& prototype = registry[i].prototype();
const OpenSim::Component& prototype = registry[i].prototype();
if (prototype.getConcreteClassName() == componentClassName) {
return i;
}
Expand All @@ -20,11 +20,11 @@ std::optional<size_t> osc::IndexOf(
}

std::optional<size_t> osc::IndexOf(
ComponentRegistryBase const& registry,
OpenSim::Component const& component)
const ComponentRegistryBase& registry,
const OpenSim::Component& component)
{
for (size_t i = 0; i < registry.size(); ++i) {
OpenSim::Component const& prototype = registry[i].prototype();
const OpenSim::Component& prototype = registry[i].prototype();
if (typeid(prototype) == typeid(component)) {
return i;
}
Expand Down
14 changes: 7 additions & 7 deletions src/OpenSimCreator/ComponentRegistry/ComponentRegistryBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ 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(); }
value_type const& operator[](size_t i) const { return m_Entries[i]; }
const value_type& operator[](size_t i) const { return m_Entries[i]; }

protected:
ComponentRegistryBase(
Expand All @@ -47,14 +47,14 @@ namespace osc
std::vector<ComponentRegistryEntryBase> m_Entries;
};

std::optional<size_t> IndexOf(ComponentRegistryBase const&, std::string_view componentClassName);
std::optional<size_t> IndexOf(ComponentRegistryBase const&, OpenSim::Component const&);
std::optional<size_t> IndexOf(const ComponentRegistryBase&, std::string_view componentClassName);
std::optional<size_t> IndexOf(const ComponentRegistryBase&, const OpenSim::Component&);

template<typename T>
std::optional<size_t> IndexOf(ComponentRegistryBase const& registry)
std::optional<size_t> IndexOf(const ComponentRegistryBase& registry)
{
for (size_t i = 0; i < registry.size(); ++i) {
OpenSim::Component const& prototype = registry[i].prototype();
const OpenSim::Component& prototype = registry[i].prototype();
if (typeid(prototype) == typeid(T)) {
return i;
}
Expand Down
10 changes: 5 additions & 5 deletions src/OpenSimCreator/ComponentRegistry/ComponentRegistryEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ 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
{
auto const& base = static_cast<ComponentRegistryEntryBase const&>(*this);
return static_cast<T const&>(base.prototype());
const auto& base = static_cast<const ComponentRegistryEntryBase&>(*this);
return static_cast<const T&>(base.prototype());
}

std::unique_ptr<T> instantiate() const
{
auto const& base = static_cast<ComponentRegistryEntryBase const&>(*this);
const auto& base = static_cast<const ComponentRegistryEntryBase&>(*this);
return std::unique_ptr<T>{static_cast<T*>(base.instantiate().release())};
}
};
Expand Down
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,17 +14,17 @@ 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; }
CStringView description() const { return m_Description; }
OpenSim::Component const& prototype() const { return *m_Prototype; }
const OpenSim::Component& prototype() const { return *m_Prototype; }
std::unique_ptr<OpenSim::Component> instantiate() const;

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;
};
}
Loading

0 comments on commit 87fcb3c

Please sign in to comment.