BrewPi / firmware

Brewing temperature control firmware for the BrewPi Spark (Particle Photon inside)
http://www.brewpi.com
GNU Affero General Public License v3.0
97 stars 55 forks source link

Feature/references #70

Closed elcojacobs closed 7 years ago

elcojacobs commented 7 years ago

This PR adds a virtual base interface to all control objects. This interface is used for visitor patterns to get runtime type info. 3 visitors are already defined:

Control objects that drive other classes now use references instead of pointers. If the application needs a configurable target, it can use the new delegate classes defined for each interface type and then instantiate the control object pointing to that delegate. These delegate classes hold a generic std::function<Interface* ()> lookup functor and use the VisitorCast visitor to attempt to upcast the result of the lookup to the required reference type. This lookup can for example take an array index or controlbox ID. When the lookup fails or the object is the wrong type, they return the default object for that interface (eg ActuatorInvalid or TempSensorDisconnected). This ensures that the control objects always have a valid target and do not have to worry about pointers being null.

Renamed in this commit: