Skip to content

Commit

Permalink
Mark Component::Clone as const (#1300)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <michael@openrobotics.org>

Co-authored-by: Addisu Z. Taddese <addisu@openrobotics.org>
  • Loading branch information
mjcarroll and azeey authored Jan 25, 2022
1 parent 892c296 commit a40d428
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions Migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ since pose information is being logged in the `changed_state` topic.
* The `gui.config` and `server.config` files are now located in a versioned
folder inside `$HOME/.ignition/gazebo`, i.e. `$HOME/.ignition/gazebo/6/gui.config`.

* The `Component::Clone` method has been marked `const` to reflect that it
should not mutate internal component state. Component implementations that
overrode the `Clone` method must also be marked `const`.

## Ignition Gazebo 5.2 to 5.3

* If no `<namespace>` is given to the `Thruster` plugin, the namespace now
Expand Down
10 changes: 5 additions & 5 deletions include/ignition/gazebo/components/Component.hh
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ namespace components

/// \brief Clone the component.
/// \return A pointer to the component.
public: virtual std::unique_ptr<BaseComponent> Clone() = 0;
public: virtual std::unique_ptr<BaseComponent> Clone() const = 0;
};

/// \brief A component type that wraps any data type. The intention is for
Expand Down Expand Up @@ -347,7 +347,7 @@ namespace components
public: bool operator!=(const Component &_component) const;

// Documentation inherited
public: std::unique_ptr<BaseComponent> Clone() override;
public: std::unique_ptr<BaseComponent> Clone() const override;

// Documentation inherited
public: ComponentTypeId TypeId() const override;
Expand Down Expand Up @@ -416,7 +416,7 @@ namespace components
Serializer> &_component) const;

// Documentation inherited
public: std::unique_ptr<BaseComponent> Clone() override;
public: std::unique_ptr<BaseComponent> Clone() const override;

// Documentation inherited
public: ComponentTypeId TypeId() const override;
Expand Down Expand Up @@ -503,7 +503,7 @@ namespace components
//////////////////////////////////////////////////
template <typename DataType, typename Identifier, typename Serializer>
std::unique_ptr<BaseComponent>
Component<DataType, Identifier, Serializer>::Clone()
Component<DataType, Identifier, Serializer>::Clone() const
{
Component<DataType, Identifier, Serializer> clonedComp(this->Data());
return std::make_unique<Component<DataType, Identifier, Serializer>>(
Expand Down Expand Up @@ -536,7 +536,7 @@ namespace components
//////////////////////////////////////////////////
template <typename Identifier, typename Serializer>
std::unique_ptr<BaseComponent>
Component<NoData, Identifier, Serializer>::Clone()
Component<NoData, Identifier, Serializer>::Clone() const
{
return std::make_unique<Component<NoData, Identifier, Serializer>>();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Component_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class NoSerialize : public components::BaseComponent
return 0;
}

public: std::unique_ptr<BaseComponent> Clone() override
public: std::unique_ptr<BaseComponent> Clone() const override
{
return nullptr;
}
Expand Down

0 comments on commit a40d428

Please sign in to comment.