Skip to content

Add clone method#70

Merged
chengcli merged 2 commits intomainfrom
cli/add_clone
Feb 2, 2026
Merged

Add clone method#70
chengcli merged 2 commits intomainfrom
cli/add_clone

Conversation

@chengcli
Copy link
Owner

No description provided.

Copilot AI review requested due to automatic review settings January 28, 2026 18:51
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds clone methods to seven option implementation classes across the thermo and kinetics modules to enable deep copying of configuration objects.

Changes:

  • Added clone() methods to base classes: NucleationOptionsImpl, ArrheniusOptionsImpl, and RateConstantOptionsImpl
  • Added clone() methods to derived classes: EvaporationOptionsImpl and CoagulationOptionsImpl
  • Added clone() methods to container classes: ThermoOptionsImpl and KineticsOptionsImpl that recursively clone nested option objects

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/thermo/thermo.hpp Adds clone method to ThermoOptionsImpl that performs deep copy including nested nucleation options
src/thermo/nucleation.hpp Adds clone method to NucleationOptionsImpl base class using copy constructor
src/kinetics/rate_constant.hpp Adds clone method to RateConstantOptionsImpl using copy constructor
src/kinetics/kinetics.hpp Adds clone method to KineticsOptionsImpl that performs deep copy including nested arrhenius, coagulation, and evaporation options
src/kinetics/evaporation.hpp Adds clone method to EvaporationOptionsImpl derived class
src/kinetics/coagulation.hpp Adds clone method to CoagulationOptionsImpl derived class
src/kinetics/arrhenius.hpp Adds clone method to ArrheniusOptionsImpl base class using copy constructor

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

EvaporationOptionsImpl(const NucleationOptionsImpl& nucleation)
: NucleationOptionsImpl(nucleation) {}

std::shared_ptr<EvaporationOptionsImpl> clone() const {
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clone method should override the virtual clone method from the base class and be marked with 'override'. This ensures proper polymorphic behavior and makes the inheritance relationship explicit. Without virtual clone in the base class and override here, cloning through a base class pointer will cause object slicing.

Suggested change
std::shared_ptr<EvaporationOptionsImpl> clone() const {
std::shared_ptr<NucleationOptionsImpl> clone() const override {

Copilot uses AI. Check for mistakes.
virtual std::string name() const { return "arrhenius"; }
virtual ~ArrheniusOptionsImpl() = default;

std::shared_ptr<ArrheniusOptionsImpl> clone() const {
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clone method should be virtual to support polymorphic cloning. Since ArrheniusOptionsImpl is a polymorphic base class (it has virtual methods like name() and a virtual destructor) and has derived classes like CoagulationOptionsImpl, calling clone() through a base class pointer will cause object slicing if clone() is not virtual.

Suggested change
std::shared_ptr<ArrheniusOptionsImpl> clone() const {
virtual std::shared_ptr<ArrheniusOptionsImpl> clone() const {

Copilot uses AI. Check for mistakes.
CoagulationOptionsImpl(const ArrheniusOptionsImpl& arrhenius)
: ArrheniusOptionsImpl(arrhenius) {}

std::shared_ptr<CoagulationOptionsImpl> clone() const {
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clone method should override the virtual clone method from the base class and be marked with 'override'. This ensures proper polymorphic behavior and makes the inheritance relationship explicit. Without virtual clone in the base class and override here, cloning through a base class pointer will cause object slicing.

Suggested change
std::shared_ptr<CoagulationOptionsImpl> clone() const {
std::shared_ptr<CoagulationOptionsImpl> clone() const override {

Copilot uses AI. Check for mistakes.
Comment on lines +58 to +64
std::shared_ptr<ThermoOptionsImpl> clone() const {
auto op = std::make_shared<ThermoOptionsImpl>(*this);
if (nucleation() != nullptr) {
op->nucleation() = nucleation()->clone();
}
return op;
}
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new clone method lacks test coverage. Given that this is a critical functionality that involves deep copying of nested objects and the codebase has comprehensive test coverage for other features (as seen in the tests directory), tests should be added to verify that cloning works correctly, especially when nucleation contains derived class instances like EvaporationOptionsImpl.

Copilot uses AI. Check for mistakes.
Comment on lines +36 to +42
std::shared_ptr<KineticsOptionsImpl> clone() const {
auto op = std::make_shared<KineticsOptionsImpl>(*this);
if (arrhenius()) op->arrhenius() = arrhenius()->clone();
if (coagulation()) op->coagulation() = coagulation()->clone();
if (evaporation()) op->evaporation() = evaporation()->clone();
return op;
}
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new clone method lacks test coverage. Given that this is a critical functionality that involves deep copying of nested objects (arrhenius, coagulation, evaporation) and the codebase has comprehensive test coverage for other features, tests should be added to verify that cloning works correctly, especially when these fields contain derived class instances.

Copilot uses AI. Check for mistakes.
virtual std::string name() const { return "nucleation"; }
virtual ~NucleationOptionsImpl() = default;

std::shared_ptr<NucleationOptionsImpl> clone() const {
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clone method should be virtual to support polymorphic cloning. Since NucleationOptionsImpl is a polymorphic base class (it has virtual methods like name() and a virtual destructor) and has derived classes like EvaporationOptionsImpl, calling clone() through a base class pointer will cause object slicing if clone() is not virtual. This means that if a NucleationOptions pointer actually points to an EvaporationOptionsImpl object, calling clone() will only copy the NucleationOptionsImpl portion, losing all EvaporationOptionsImpl-specific data.

Suggested change
std::shared_ptr<NucleationOptionsImpl> clone() const {
virtual std::shared_ptr<NucleationOptionsImpl> clone() const {

Copilot uses AI. Check for mistakes.
@chengcli chengcli merged commit cd4523e into main Feb 2, 2026
9 checks passed
@chengcli chengcli deleted the cli/add_clone branch February 2, 2026 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant