You might want to store more information about a device or format
than the IDeviceInfo
and IDeviceFormat
objects
allow. One way to do this is to define a new class that contains this
additional information. Then, in your adaptor, instantiate an object
of this class and store it in the adaptor data of the IDeviceInfo
or IDeviceFormat
objects.
Using adaptor data is a good way to pass important information around
inside your adaptor because the IDeviceInfo
and IDeviceFormat
objects
are passed to other adaptor functions.
Using adaptor data is a three-step process:
Define a class to hold the device or format information. See Defining a Device or Format Information Class for more information.
Instantiate an object of this class in your adaptor. Use the constructor you define for your class.
Store the object in the adaptor data
of the IDeviceInfo
or IDeviceFormat
object.
See Storing Adaptor Data for more information.
The class that you define to store additional device or format
information must be derived from the IMAQinterface
class.
Subclassing the IMAQInterface
class ensures that
all memory deallocations for these classes are routed through the
toolbox engine.
For an example of such a class, see the DemoDeviceFormat
class
in the demo adaptor, defined in the file DemoDeviceFormat.h
.
To store your device or format class in the adaptor data of
an IDeviceInfo
or IDeviceFormat
object,
use the setAdaptorData()
member function of the
object.
Note
The objects you store in adaptor data are automatically destroyed
when the IDeviceInfo
and IDeviceFormat
objects
are destroyed. Once you store an object in adaptor data, do not try
to destroy the objects yourself.
The demo adaptor provides an example, defining a class to hold
additional format information. This class, named DemoDeviceFormat
,
stores format information such as width, height, and color space.
The following example, taken from the demo adaptor, shows how to instantiate
an object of this derived class, assign values to the data members
of the class, and then store the object in the adaptor data of the IDeviceFormat
object.
DemoDeviceFormat* rgbFormatInfo = new DemoDeviceFormat(); rgbFormatInfo->setFormatWidth(demo::RGB_FORMAT_WIDTH); rgbFormatInfo->setFormatHeight(demo::RGB_FORMAT_HEIGHT); rgbFormatInfo->setFormatNumBands(demo::RGB_FORMAT_BANDS); rgbFormatInfo->setFormatColorSpace(imaqkit::colorspaces::RGB); deviceFormat->setAdaptorData(rgbFormatInfo);
To access the adaptor data stored in an IDeviceInfo
or IDeviceFormat
object,
use the getAdaptorData()
member function of the
object.
The following example, taken from the demo adaptor, shows how
to retrieve the adaptor data from the IDeviceFormat
object.
In the example, selectedFormat
is a DemoDeviceFormat
object.
Note that because the getAdaptorData()
member function
returns a handle to the IMAQInterface
class, you
must cast the returned object to your defined class.
dynamic_cast<DemoDeviceFormat*>(selectedFormat->getAdaptorData());