Skip to content
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

Using KhalimskyPreSpaceND and pre-cells when possible. #1190

Open
rolanddenis opened this issue Jun 18, 2016 · 0 comments
Open

Using KhalimskyPreSpaceND and pre-cells when possible. #1190

rolanddenis opened this issue Jun 18, 2016 · 0 comments

Comments

@rolanddenis
Copy link
Member

Since #1086, there are two cellular grid space models:

  • an unbounded space model KhalimskyPreSpaceND that allow unrestricted access to cell coordinates,
  • and a bounded space model KhalimskySpaceND that is shipped with many sanity checks and safeguards in order to guarantee cell's coordinates validity (ie that they lie inside the domain).

The second model implies that a (Signed)KhalimskyCellis meant to be given with the associated KhalimskySpaceND in order to allow safe manipulation. Conversely, if a function/method/class needs a cell without the associated bounded cellular grid space, this function/method/class might as well use a pre-cell from KhalimskyPreSpaceND.

Therefore, we should ideally respect the following guidelines:

  1. if a function/method/class needs a (Signed)KhalimskyCell, always pass the associated KhalimskySpaceND,
  2. otherwise, if a function/method/class doesn't need the associated KhalimskySpaceND (eg, the display related functions), then it should only accept a (Signed)KhalimskyPreCell.
  3. If a function/method/class doesn't depend on the cellular grid bounds, it should use a KhalismkyPreSpaceND and the associated pre-cells.

To ease the code update, there is two facilities:

  • (Signed)KhalimskyCell are implicitly convertible to (Signed)KhalimskyPreCell, or an explicit conversion is available through the preCell() method.
  • KhalimskySpaceND features an alias to the associated KhalimskyPreSpaceND (named PreCellularGridSpace).

However, there is a little snag: C++ sees the implicit conversion only if it doesn't depend on template deduction. For example, in the following code:

template <Dimension dim, typename TInteger >
class Dummy
{
 ...
 void doSomething( KhalimskyPreCell<dim, TInteger> const & aCell )
   {
     ...
   }
  ...
};

the method doSomething can also accept a KhalimskyCell<dim,TInteger> and the implicit conversion will be used. But in:

template < Dimension dim, typename TInteger >
void doSomething( KhalimskyPreCell<dim, TInteger> const & aCell )
  {
    ...
  }

C++ must be firstly able to deduce the template parameters and it is not allowed if a KhalimskyCell is given.

So, sometimes, two versions must be available (for cell and pre-cell) or the user must think to convert it before.

That's it, just a short reminder for what remains to be done after #1086.

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

No branches or pull requests

1 participant