samedi 8 avril 2017

A generic storrage system

I'm working on a small library for learning purpose. And I was thinking about using policy design. But my use case is not really the same as Andrei Alexandrescu described in his book.

In the book, policy design is used like this :

template < typename Policie >
class Base : public Policie {

  void func() {
    policieFunc();
  }
}

But sometime you can need to add others function with policies:

template < typename Policie >
class Base : public Policie {

  void func() {
    policieFunc();
  }
}

Base test;
test.otherPolicieFunc();

But in my case I will only need to add others function, and they will need information about the "Base" class.

Let's think about a generic storage. With different bases which can have a memory contiguous or not, dynamic or static... Well it could be some kind of memory policy. And after this, you have to choose if this storage will have a view to filter elements, if the changes will be instant or not.... And things I will never be able to imagine.

But a view need to get memory access, same for the "changes" policy... So the only way I see to do that is to pass a ref of the "base" class to every policies.

Is there any other way (maybe some constructor design)? Will performances get hurt by that? Do you know what problems I'll have to solve?

Aucun commentaire:

Enregistrer un commentaire