Skip to content
This repository has been archived by the owner on May 9, 2019. It is now read-only.

Commit

Permalink
[grid.provider] add copy()
Browse files Browse the repository at this point in the history
Does the const/non const thing make sense here, @renemilk? Or how do I
default implement the const variant using the non-const variant in this
case?
  • Loading branch information
ftschindler committed Jun 15, 2015
1 parent f651cb6 commit 0179341
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions dune/stuff/grid/provider/cube.hh
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ public:
return grid_ptr_;
}

virtual std::unique_ptr< BaseType > copy() override
{
return Common::make_unique< Cube< GridType > >(*this);
}

private:
static std::array< unsigned int, dimDomain > parse_array(const unsigned int in)
{
Expand Down
5 changes: 5 additions & 0 deletions dune/stuff/grid/provider/default.hh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public:
{
return this->storage_access();
}

virtual std::unique_ptr< Default< GridType > > copy() override
{
return Common::make_unique< Default< GridType > >(grid());
}
}; // class Default


Expand Down
9 changes: 9 additions & 0 deletions dune/stuff/grid/provider/interface.hh
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ public:
visualize_with_boundary(boundary_info_cfg, filename);
}

virtual std::unique_ptr< ConstProviderInterface< GridType > > copy() const = 0;

private:
virtual void visualize_plain(const std::string filename) const
{
Expand Down Expand Up @@ -285,6 +287,13 @@ public:

virtual GridType& grid() = 0;

virtual std::unique_ptr< ProviderInterface< GridType > > copy() = 0;

virtual std::unique_ptr< ConstProviderInterface< GridType > > copy() const override
{
return const_cast< ProviderInterface< GridType >* >(this)->copy();
}

using BaseType::layer;

template< ChooseLayer layer_type, ChoosePartView part_view_type >
Expand Down

3 comments on commit 0179341

@renefritze
Copy link
Contributor

Choose a reason for hiding this comment

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

TBH I see no reason at all to the GridProvider. It has no state besides the actual grid. The way that copy is implemented it just copies the shread_ptr to the grid, not the grid. I think it is not obvious what the right thing to do here is in general, since the interface does not prescribe grid storage. The derived classes are really all just factories anyway, right?

@ftalbrecht
Copy link
Member

Choose a reason for hiding this comment

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

We had the case where the grid got lost in the python bindings, and the first crude hack was to keep a copy of the grid provider. Unfortunately, the interface class does not store the grid_ptr, but each implementor does (e.g., Cube), since accessing the ptr is not part of the interface (only the reference is). By adding copy(), I could allow the one provider I was using to be copyable.

I am aware that this is not something we would want to have generally, and this is only inside the paper branch. My question was actually really concerned with the actual lines of code in interface.hh, where I am unsure if I can suitably default implement the const method using the other.

@renefritze
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, the way you've set this up should work for now. I wouldn't really want it outside the paper branch though.

Please sign in to comment.