Handling of variable length records
Let's revisit our employee_record. Assume that we wish to keep a record of the of the man-hour spent on each project assigned to the staff. Let's assume also, that different staff may be involved in different number of projects, some may have one project, some may have many projects and some may be just hanging around drinking coffee.
class manhour_record : public complex_var
}
public:
COMPLEXCONST(manhour_record)
string_var<24> project_name;
generic_var<unsigned int> manhour;
array_var<unsigned int> daily_breakdown;
};
class employee_record : public complex_var
{
public:
COMPLEXCONST(employee_record)
generic_var<int> staff_id;
string_var<32> first_name;
string_var<32> last_name;
address_record address;
generic_var<double> salary;
flex_var<manhour_record> timecharge;
};
The class flex_var allows variable number of manhour_record objects to be instantiated. As flex_var is-a complex_var, it uses the complex_var 's implementation of managing its children. In extract, it will check the message to determine the number of children it needs to have and adjust its number children -if the message has more elements, it will instantiate additional children and vice versa. Applications attach themselves to the flex_var to check for the number of elements and the logic will handle accordingly.
This is unlikely to be suitable for the Data Monitor as our widgets need to attach to the elements themselves, and this is not possible if the flex_var may resize on each message received. Going back to our example, if we wish to configure Data Monitor to display the first four projects for an employee.
.tmp)
This would mean that Data Monitor will need to instantiate all 4 children for timecharge regardless of the number of elements in the received message. If an employee record with more than 4 projects are received, then the remaining elements will not be unpacked by the Composite pattern since there are only 4 fixed children. The Composite will need to have the intelligence to silently discard the remainder. Unpacking only 4 is not a problem since we only display the first 4 projects. When there are less than 4 elements, the library provides a setInvalid method which can be called to invalidate the field. The library typically sets all bits to 1 for all generic_var and clears string_var to an empty string. In the example above, we only receive 3 fields.
This idea may be extended to other fields that are not displayed, for example address and salary. So the idea of instantiating children on demand may extend to all complex_vars. We don't need "instantiation-on-demand" in our applications, so this will be unique to Data Monitor.
This would not affect the recording, since the message protocol object would be responsible to write the entire received message to the sinks.
Array_var is the other variable length field. A similar method can be used.
All dynamic and control widgets will present a field selection dialog to allow the user to select the message field to display.

The spin box for street_name will only allow 0-1, since street_name is a static array of 2 elements.
The spin box for timecharge will be from 0 to 16384, since flex_var is a variable length array, but we don't expect anything really large.
The spin box for daily_breakdown will be from 0 to 16384, since array_var is also a variable length array.
By default, the spin boxes will always show zero when the dialog is first displayed.
The selection of street_name[idx] will display the value of the idx-th element of street_name.
The selection of timecharge[idx] will display the number of elements in timecharge. The index, idx, will be ignored.
The selection of manhour of timecharge[idx], will display the manhour of the idx-th timecharge.
The selection of daily_breakdown[idx2] of timecharge[idx] will display the number of elements in daily_breakdown regardless of the value of idx2.
The selection of <<string>> which is a special value for array_var, will display the array contents of daily_breakdown of the idx-th timecharge as text. The to_const_char_ptr will be used on the array_var itself. The idx2 of daily breakdown will be ignored.
The selection of <<value>> which is a special value for array_var will display the value of the idx2-th element of daily_breakdown of the idx-th timecharge.
The possible interaction between the various software components is shown:

The factories are provided by the message protocol plugins.
The widget property pages are provided by the widget plugins.