Resources | Resources |



Vector model

IVectorModel is derived from the IListModel interface and is used to model a collection of objects that may be of variable size.

Unlike an array model, the vector model provides the ability to add, insert, delete, and replace items stored in the model and allow each item to vary in size and structure.

The vector model data is stored as an array of pointers. Each item in a vector model is represented by a pointer, with all the item pointers collected together in one contiguous block of memory. The block of item pointers is accessed by the vector model through a second reference pointer. The content of each item in the vector can be of a different size and structure. When an application retrieves an item, the vector model returns a pointer to the location where that item's contents are stored.

The IVectorModel interface provides functions for:

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

Using a vector model

In the following example, the application creates a pick list widget that uses a vector model, sets the model on the pick widget, then adds items to the vector model.

   IWidget *piw = 0;
   IWidget *pisw = 0;
   IVectorModel *pivm = 0;
   const char *pCharImage = 0;
   ImageStaticInfo *pisi;
   IImage *pii = NULL;
   IController *pitc =0;

   ERR_TRY( ISHELL_CreateInstance(me->piShell, AEECLSID_CPickWidget,
               (void**)&piw) );

   ERR_TRY( ISHELL_CreateInstance(me->piShell, AEECLSID_CImageStaticWidget,
               (void**)&pisw) );

   ERR_TRY( ISHELL_CreateInstance(me->piShell, AEECLSID_CVectorModel,
               (void**)&pivm) );

   ERR_TRY( IWidget_SetModel(piw, IVectorModel_to_IModel(pivm)) );

   pCharImage = aCharImageFileList;

   do {
      pii = ISHELL_LoadImage(me->piShell, pCharImage);
      if (pii == NULL) {
      ERR_TRY( ImageStaticInfo_New(&pisi, pii, L"") );
      if ( pCharImage != NULL) {
         pCharImage += STRLEN(pCharImage) + 1;

      ERR_TRY( IVectorModel_Add(pivm, (void*)pisi) );
   } while(pCharImage != NULL);