ML Reference
ml::FieldSensor Class Reference

#include <mlFieldSensor.h>

Public Types

enum  Strength { NO_NOTIFICATION = 0 , NO_CHANGE = 1 , CHANGED = 2 }
 Enumeration type describing the strength of notifications. More...

Public Member Functions

 FieldSensor (MLSensorCB *callbackFunction, void *userData)
virtual ~FieldSensor ()
 Destructor: Disconnects field sensor from the connected field.
void callback (Strength notificationStrength=CHANGED)
void attachField (Field *field)
void detachField ()
FieldgetField () const
 Returns the field connected to the field sensor.
Strength getNotificationStrength () const

Friends

class Field

Detailed Description

Class to define and to manage field sensors.

A field sensor contains a reference to a callback function and a callback function argument.

Definition at line 38 of file mlFieldSensor.h.

Member Enumeration Documentation

◆ Strength

Enumeration type describing the strength of notifications.

Enumerator
NO_NOTIFICATION 

Default when sensor is asked outside a notification.

NO_CHANGE 

Subject (i.e., the field) is notified but not changed.

CHANGED 

Subject (i.e., the field) is notified and/or changed.

Definition at line 44 of file mlFieldSensor.h.

Constructor & Destructor Documentation

◆ FieldSensor()

ml::FieldSensor::FieldSensor ( MLSensorCB * callbackFunction,
void * userData )

Creates a field sensor with callback function callbackFunction and a parameter userData. The method callback executes the callback function. Note: userData is usually a pointer to the instance of a class and callbackFunction is a static function of that class.

◆ ~FieldSensor()

virtual ml::FieldSensor::~FieldSensor ( )
virtual

Destructor: Disconnects field sensor from the connected field.

Member Function Documentation

◆ attachField()

void ml::FieldSensor::attachField ( Field * field)

Attaches a field sensor to a the field field. If the field value changes, callback() of the sensor is called. A previously attached field will automatically be detached before attaching the new one.

References Field.

◆ callback()

void ml::FieldSensor::callback ( Strength notificationStrength = CHANGED)

Executes the callback function set by the constructor. While the callback is executed with getNotificationStrength(), the value passed to this callback can be retrieved. Outside of it, it always will be NO_NOTIFICATION.

References CHANGED.

◆ detachField()

void ml::FieldSensor::detachField ( )

Detaches the field sensor from the most recently attached field. The callback() method is not called anymore if the field is changed. After this call, getField() will return NULL.

◆ getField()

Field * ml::FieldSensor::getField ( ) const

Returns the field connected to the field sensor.

References Field.

◆ getNotificationStrength()

Strength ml::FieldSensor::getNotificationStrength ( ) const

Returns the notification level, i.e., how strong the current notification is. Level CHANGED or higher usually means 'changed object' and level NO_CHANGE usually means only notification. It is always returned as NO_NOTIFICATION if not called from within a callback.

◆ Field

friend class Field
friend

Definition at line 85 of file mlFieldSensor.h.

References Field.

Referenced by attachField(), Field, and getField().


The documentation for this class was generated from the following file: