Skip to content

Implement deep cloning for opacities map in RadiationBandOptionsImpl#82

Merged
chengcli merged 5 commits intocli/add_toonfrom
copilot/sub-pr-81
Jan 27, 2026
Merged

Implement deep cloning for opacities map in RadiationBandOptionsImpl#82
chengcli merged 5 commits intocli/add_toonfrom
copilot/sub-pr-81

Conversation

Copy link
Contributor

Copilot AI commented Jan 27, 2026

The clone() method in RadiationBandOptionsImpl performs shallow copy of the opacities map, causing the cloned object to share OpacityOptionsImpl instances with the original. Modifications to opacity options in either object affect both.

Changes

  • Deep clone opacities map: Clear the shallow-copied map and clone each OpacityOptions entry individually using its clone() method
  • Ensures true independence between cloned and original RadiationBandOptionsImpl instances
std::shared_ptr<RadiationBandOptionsImpl> clone() const {
  auto op = std::make_shared<RadiationBandOptionsImpl>(*this);
  if (op->disort() != nullptr) {
    op->disort() = op->disort()->clone();
  }
  if (op->toon() != nullptr) {
    op->toon() = op->toon()->clone();
  }
  if (op->opacities().size() > 0) {
    auto& opacities_ref = op->opacities();
    opacities_ref.clear();
    for (auto const& [k, v] : opacities()) {
      opacities_ref[k] = v->clone();
    }
  }
  return op;
}

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits January 27, 2026 13:57
Co-authored-by: chengcli <69489965+chengcli@users.noreply.github.com>
Co-authored-by: chengcli <69489965+chengcli@users.noreply.github.com>
Co-authored-by: chengcli <69489965+chengcli@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issues based on feedback for clone method PR Implement deep cloning for opacities map in RadiationBandOptionsImpl Jan 27, 2026
Copilot AI requested a review from chengcli January 27, 2026 14:03
@chengcli chengcli marked this pull request as ready for review January 27, 2026 14:08
@chengcli chengcli requested a review from luminoctum as a code owner January 27, 2026 14:08
Copilot AI review requested due to automatic review settings January 27, 2026 14:08
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 fixes a shallow copy issue in the RadiationBandOptionsImpl::clone() method by implementing deep cloning for the opacities map. Previously, cloned objects shared OpacityOptionsImpl instances with the original, causing unintended modifications to affect both objects.

Changes:

  • Added deep cloning logic for the opacities map that iterates through each entry and clones it using the OpacityOptions::clone() method
  • Maintains consistency with existing clone patterns for disort() and toon() members

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

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@chengcli chengcli merged commit 1894a18 into cli/add_toon Jan 27, 2026
@chengcli chengcli deleted the copilot/sub-pr-81 branch January 27, 2026 16:29
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.

2 participants