Function _conArrayPut() Foundation

Assigns a new value to an element of an array.

Syntax
XPPAPIRET _conArrayPut(ContainerHandle cha,
                       ContainerHandle chx, ...);
Parameters
ContainerHandle cha
Handle of a container of array type whose element is to have its value changed.
ContainerHandle chx
Handle of a container which has the new value.
. . .
The remaining arguments must be of ULONG type and identify the array element to be changed. One index should be included per dimension. Note: The end of the array index list must be indicated by incorporating a NULL as the last value in the list.
Return

The function returns an error code (XPP_ERR_...) when the container cha is not an array, the indexes are not valid or the value of the element could not be changed for some other reason. If the return value is NULL, the operation was successful.

Description

The function _conArrayPut() is used to change the values of array elements. Xbase++ arrays can contain elements of different types. The value of the passed container is merely copied into the array element.

Xbase++ has several internal threads which can execute code blocks. Since arrays are always passed by reference it is possible that two threads are simultaneously working on an array. Therefore if an array is not created locally within a function, it is possible that the size or the content of the array may change. Therefore, the return values should always be checked, even if the array structure has been determined via _conSizeA() and _conTypeA().

Examples
Spliting a character string into tokens.
#include "xpppar.h" 
#include "xppcon.h" 

static CHAR *strtoken(CHAR *psf, ULONG sfLen, CHAR *psi, ULONG siLen); 

/* 
TOKENIZE( <cString>, [ <cSeparator> ] ) -> aTokens 
*/ 
XPPRET XPPENTRY TOKENIZE(XppParamList paramList ) 
{ 
ContainerHandle  chString; 
CHAR            *pStr; 
LONG             lenStr; 
ContainerHandle  chSeparator; 
CHAR            *pSep; 
ULONG            lenSep; 
CHAR            *p; 
ULONG            i; 
ContainerHandle  chArray = NULLCONTAINER; 
ContainerHandle  chTmp = NULLCONTAINER; 
XPPAPIRET        xr; 

/* 
   get parameters 
*/ 
chString = _conParam( paramList, 1, NULL ); 
chSeparator = _conParam( paramList, 2, NULL ); 
/* 
   lock string to search 
*/ 
if (chString != NULLCONTAINER 
    &&  chSeparator != NULLCONTAINER 
    &&  ! _conRLockC( chString, &pStr, (ULONG*)&lenStr )) 
{ 
   /* 
      lock separator string 
      or set default separator ";" 
   */ 
   if (_conRLockC( chSeparator, &pSep, &lenSep ) != 0) 
   { 
      pSep = ";"; 
      lenSep = 1; 
      _conRelease(chSeparator); 
      chSeparator = NULLCONTAINER; 
   } 
   if (lenStr > 0  &&  lenSep != 0) 
   { 
      /* 
         count tokens for array size 
      */ 
      p = pStr, i = 0; 
      do { 
         p = strtoken(pSep, lenSep, p, lenStr-(p-pStr)) + lenSep; 
         i++; 
      } while (p < pStr + lenStr); 
      /* 
         create array and a temporary container 
      */ 
      chArray = _conNewArray(1, i); 
      chTmp = _conNew(NULLCONTAINER); 

      if (chArray != NULLCONTAINER  &&  chTmp != NULLCONTAINER) 
      { 
         /* 
            assign each token to a string container 
            and set array element with this container 
         */ 
         i = 1, p = pStr; 
         do { 
            p = strtoken(pSep, lenSep, p, lenStr); 
            if (_conPutCL(chTmp, pStr, p-pStr) != chTmp) 
               break; 
            if (_conArrayPut(chArray, chTmp, i, 0) != 0) 
               break; 
            i++; 
            p += lenSep; 
            lenStr -= p-pStr; 
            pStr = p; 
         } while (lenStr > 0); 
      } 
      /* 
         release temporary container 
      */ 
      if (chTmp != NULLCONTAINER) 
         _conRelease( chTmp ); 
      /* 
         unlock parameter containers 
      */ 
      if (chSeparator != NULLCONTAINER) 
         _conUnlockC( chSeparator ); 
   } 
   _conUnlockC( chString ); 
} 
/* 
   release parameter containers 
*/ 
if (chString != NULLCONTAINER) 
   _conRelease(chString); 
if (chSeparator != NULLCONTAINER) 
   _conRelease(chSeparator); 
/* 
   return array and release array container 
*/ 
if (chArray != NULLCONTAINER) 
{ 
   _conReturn( paramList, chArray ); 
   _conRelease( chArray ); 
} 
else 
   _ret(paramList); 
} 

/* 
return ^ to first char of first occurance of psf in psi 
*/ 
static CHAR *strtoken(CHAR *psf, ULONG sfLen, CHAR *psi, ULONG siLen) 
{ 
ULONG i; 

while (siLen >= sfLen) 
{ 
   if (*psf == *psi) 
   { 
      for( i=1; i<sfLen; i++ ) 
         if (psf[i] != psi[i]) 
            break; 
      if (i == sfLen) 
         return psi; 
   } 
   psi++; 
   siLen--; 
} 
return psi+siLen; 
} 
Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.