OpenThermal / libseek-thermal

SEEK thermal compact camera driver supporting the thermal Compact, thermal CompactXR and and thermal CompactPRO
MIT License
293 stars 100 forks source link

Runtime support for different camera types #8

Closed fnoop closed 7 years ago

fnoop commented 7 years ago

The difference between test and testpro is: LibSeek::SeekThermal seek(argc == 2 ? argv[1] : ""); and LibSeek::SeekThermalPro seek(argc == 2 ? argv[1] : "");

It would be nice to be able to declare seek something like: LibSeek::Seek seek("pro");

So we don't have to write different code for different models.

maartenvds commented 7 years ago

You have runtime support if you want using polymorphism. Example with smart pointers:

std::shared_ptr<LibSeek::SeekCam> seek;

if (camtype == "pro")
        seek = std::make_shared<LibSeek::SeekThermalPro>();
else
        seek = std::make_shared<LibSeek::SeekThermal>();

if (!seek->open())
...

Or just on the stack:

LibSeek::SeekCam* seek;
LibSeek::SeekThermalPro seekpro;
LibSeek::SeekThermal seekclassic;

if (camtype == "pro")
        seek = &seekpro;
else
        seek = &seekclassic;

if (!seek->open())

I could add a factory function that does this behind the scenes, but personally I think that would not add any real value, especially since the lib currently only supports two camera types.

fnoop commented 7 years ago

Aaaah! Thanks so much, I spent ages trying to get both of those approaches to work. My C++ sucks :)

fnoop commented 7 years ago

Works perfectly, thanks :)