Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

Array model

IArrayModel is derived from the IListModel interface and is used to model a collection of objects, which are all of an equal fixed size.

The data of an array model is stored as one contiguous block of memory, each item stored one after the other in equal sized blocks. When an application retrieves an item, the array model returns a pointer to the location within the array where the requested item is stored. The array model operates on whole array structures and lacks facilities for adding, inserting, deleting, or replacing individual items. Changes require that the entire existing array structure be replaced with a new array.

The array model is best suited for small lists of items, or lists that do not change. For more complex data collections, the vector model can be used.

The IArrayModel interface provides functions for:

  • manipulating the data stored in the array model
  • managing reference counting of the interface object
  • registering a listener

Using an array model

The following example shows how to use IArrayModel to model a collection of objects for a pick widget:

AECHAR awNumbers[] = { '0','1','2','3','4','5','6','7' };
 
nErr = ISHELL_CreateInstance(pMe->m_pIShell, AEECLSID_CArrayModel, (void**)& 
            pArrayMdl);
 
// Create PickList which will display the data represented by array model
if (AEE_SUCCESS == nErr) {
   nErr = ISHELL_CreateInstance(pMe->m_pIShell, AEECLSID_CPickWidget, 
               (void**)&pPickWgt);
}
 
// Set ArrayModel as Model for PickWidget
if (AEE_SUCCESS == nErr) {
   nErr = IWidget_SetModel(pPickWgt, (IModel*)pArrayMdl);
}
 
// Set data on array model
if (AEE_SUCCESS == nErr) {
   IArrayModel_SetItems(pArrayMdl, (void*)awNumbers, ARRAYSIZE(awNumbers), 
      sizeof(AECHAR));
}