deepClone function

Grid deepClone(
  1. Grid source
)

Performs a DEEP clone of a grid When talking about cloning, it (mostly) boils down to two types; Shallow: Constructs new object in new member space, but inserts references for as many of that objects fields as possible. Deep: Constructs a new object in new memory space, along with new objects for all fields within that object.

Implementation

Grid deepClone(Grid source) {
  Grid _target = new Grid();

  for (int r = 0; r < 9; r++) {
    for (int c = 0; c < 9; c++) {
      _target.matrix()[r][c].setValidity(source.matrix()[r][c].valid());
      _target.matrix()[r][c].setPristine(source.matrix()[r][c].pristine());
      _target.matrix()[r][c].addMarkupSet(source.matrix()[r][c].getMarkup());
      _target.matrix()[r][c].setValue(source.matrix()[r][c].getValue());
      _target.matrix()[r][c].setPrefill(source.matrix()[r][c].prefill());
    }
  }
  return _target;
}