The ITContainCvt interface

The ITContainCvt interface combines the features of the ITContainer and ITConversions interfaces.

The ITContainCvt interface can be exposed by objects that are containers of base type instances, such as data types that include an array of values like a polygon or path. Unlike the ITContainer interface, the constituent values are converted by the container object directly into C++ host types, instead of into other value objects.

The contain.cpp example uses a sample array value object, and extracts an ITContainCvt interface from the array object to load values from the array into application variables. (The contain.cpp example uses a distinct data type, and so it is only supported with Informix®.) The following excerpts point out use of the ITContainCvt interface:
  1. Execute a query that returns an array.
    ITRow *row =
        q.ExecOneRow("select * from bitarraytab;");
  2. Extract the array value from the result row.
    ITValue *arrayval = row->Column(0);
  3. Extract an ITContainCvt interface from the object and release the interfaces that are no longer required.
    ITContainCvt *arraycont;
    arrayval->QueryInterface(ITContainCvtIID, (void **) &arraycont);
    row->Release();
    arrayval->Release();
  4. Iterate over the ITContainCvt interface and extract the array values into application variables.
    // The iterator class iterates over every member
    // of an object
    // exposing an ITContainer or ITContainerCvt interface.
    ITContainerIter iter(arraycont); 
    
    // Add all the items to the stream
    char buf[8192];
    ostrstream  cstream(buf, sizeof buf);
    
    for (int i = 0; i < arraycont->NumItems(); i++)
    {
       int value;
        iter >> value; 
        cstream << ’[’ << i << ’]’ << " = " << value << endl; 
    }
  5. Release the ITContainCvt interface.
    arraycont->Release();