mardi 1 mai 2018

Polymorphic map keys in C++

I am working on a computer vision API where I have various algorithms that all work on image data and attempt to classify some objects.

Some of the algorithms are simple which say classify objects simply based on their size ie. the algorithm might return the count of all objects based on their size like small, medium, big, for example

Some other algorithms are more fine tuned and may classify objects based on their true type for example like table, chair, bed.

So I have an interface for all such counting objects as:

class IFurnitureCounter
{
    virtual std::map<ObjectType, size_t> getCount() = 0;
};

The idea is that each of these algorithms will implement this getCount() method so that the caller can use them agnostically.

My issue is that the ObjectType key becomes a mish mash. So, I can define this ObjectType as an enum for example:

enum class ObjectType {SMALL, MEDIUM, BIG, TABLE, CHAIR, BED} 

However this feels bad as each algorithm now sees all the types even though a particular algorithm might only work on a subset of them. I was wondering if there is a better deisgn paradigm to have a better decoupling of these types between algorithms.

Aucun commentaire:

Enregistrer un commentaire