-
Notifications
You must be signed in to change notification settings - Fork 0
Add clone method #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add clone method #70
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -27,6 +27,9 @@ struct CoagulationOptionsImpl final : public ArrheniusOptionsImpl { | |||||
| CoagulationOptionsImpl(const ArrheniusOptionsImpl& arrhenius) | ||||||
| : ArrheniusOptionsImpl(arrhenius) {} | ||||||
|
|
||||||
| std::shared_ptr<CoagulationOptionsImpl> clone() const { | ||||||
|
||||||
| std::shared_ptr<CoagulationOptionsImpl> clone() const { | |
| std::shared_ptr<CoagulationOptionsImpl> clone() const override { |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -37,6 +37,9 @@ struct EvaporationOptionsImpl final : public NucleationOptionsImpl { | |||||
| EvaporationOptionsImpl(const NucleationOptionsImpl& nucleation) | ||||||
| : NucleationOptionsImpl(nucleation) {} | ||||||
|
|
||||||
| std::shared_ptr<EvaporationOptionsImpl> clone() const { | ||||||
|
||||||
| std::shared_ptr<EvaporationOptionsImpl> clone() const { | |
| std::shared_ptr<NucleationOptionsImpl> clone() const override { |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,13 @@ struct KineticsOptionsImpl final : public SpeciesThermoImpl { | |
| static std::shared_ptr<KineticsOptionsImpl> from_yaml( | ||
| YAML::Node const& config, bool verbose = false); | ||
|
|
||
| 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; | ||
| } | ||
|
Comment on lines
+36
to
+42
|
||
| void report(std::ostream& os) const { | ||
| os << "-- kinetics options --\n"; | ||
| os << "* Tref = " << Tref() << " K\n" | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -31,6 +31,9 @@ struct NucleationOptionsImpl { | |||||
| virtual std::string name() const { return "nucleation"; } | ||||||
| virtual ~NucleationOptionsImpl() = default; | ||||||
|
|
||||||
| std::shared_ptr<NucleationOptionsImpl> clone() const { | ||||||
|
||||||
| std::shared_ptr<NucleationOptionsImpl> clone() const { | |
| virtual std::shared_ptr<NucleationOptionsImpl> clone() const { |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,6 +55,13 @@ struct ThermoOptionsImpl final : public SpeciesThermoImpl { | |
| static std::shared_ptr<ThermoOptionsImpl> from_yaml(YAML::Node const& config, | ||
| bool verbose = false); | ||
|
|
||
| std::shared_ptr<ThermoOptionsImpl> clone() const { | ||
| auto op = std::make_shared<ThermoOptionsImpl>(*this); | ||
| if (nucleation() != nullptr) { | ||
| op->nucleation() = nucleation()->clone(); | ||
| } | ||
| return op; | ||
| } | ||
|
Comment on lines
+58
to
+64
|
||
| void report(std::ostream& os) const { | ||
| os << "-- thermodynamics options --\n"; | ||
| os << "* Tref = " << Tref() << " K\n" | ||
|
|
||
There was a problem hiding this comment.
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.