I have the following situation and I don't know if my approach is right. I am working on a project that has the following structure:
class Filesystem {
public:
Filesystem(Profile* profile);
OpenFile(const std::string& file,OpenFileCallback);
ReadFile(int file_handle,Buffer* buffer,ulong offset,ulong length);
protected:
DiskRouter* disk_router_;
...
}
// --- implementation ---
Filesystem::Filesystem(Profile* profile)
:disk_router_(Disk_Router::Get(profile)){
}
This class uses an Operation abstraction to run OpenFile operations, ReadFile operations and so on. The operations are sent to a router that is responsible with the type of file system in question.
class Operation {
public:
Operation(Disk_Router* router) {
}
}
I want to use a non-type parameter that chooses the destination router and a destination Policy to choose between the routers. Basically the code is reusable and I don't want to change a good implementation and if something ever changes to be available for all logic. Something like:
template <int DESTINATION>
class Filesystem{
...
protected:
Destination_Policy<DESTINATION>::DestinationType router_type;
}
// ----- implementation
template <int DESTINATION>
Filesystem<DESTINATION>::Filesystem(Profile* profile)
:disk_router_(Destination_Policy<DESTINATION>::Get(profile)) {
}
The Operation will become:
template <class Destination>
class Operation{..}
What I am trying to achieve:
-
I don't need to describe a general interface for the routers. They can vary independely
-
I can specialize certain methods if needed based on the non-type
Is this logic correct? Thank you!
Aucun commentaire:
Enregistrer un commentaire