Function _conArrayGet() Foundation
Assigns a copy of an array element to a container.
ContainerHandle _conArrayGet(ContainerHandle cha,
ContainerHandle ch, ...);
When successful, the function returns the handle of the passed container ch or of the newly created container. The function returns NULLCONTAINER when the container cha is not an array, the indexes are not correct or the assignment of the element value has failed. Checking of the exact cause of error is done with _conLastError().
_conArrayGet() allows access to elements of an array. The value of the element can either be copied into a passed container or a new container can be created if NULLCONTAINER is passed as the parameter ch. Since the value of the element is copied in both cases, later changes to this container do not alter the value of the original array element.
If a new container is created by _conArrayGet(), it must later be released with _conRelease().
#include "xpppar.h"
#include "xppcon.h"
#define TYPE_OPTNUM(x) (XPP_IS_UNDEF(x) || XPP_IS_NUM(x))
/*
FT_ASUM( <aArray> [, <nStartIndex> [, <nEndIndex> ] ] ) -> nSumme
For string elements is length will be added and for numeric elements
the value. All other types are ignored.
*/
XPPRET XPPENTRY FT_ASUM(XppParamList paramList )
{
ContainerHandle chArray;
ContainerHandle chElement;
ULONG lArrayLen;
LONG lStartIndex;
LONG lEndIndex;
LONG lSum = 0;
LONG lElement;
LONG lValue;
/*
check type of parameters
*/
if ( XPP_IS_ARRAY(_partype(paramList, 1) ) &&
TYPE_OPTNUM( _partype(paramList, 2) ) &&
TYPE_OPTNUM( _partype(paramList, 3) )
{
/*
get array parameter and retrieve the length of the array
*/
chArray = _conParam(paramList, 1, NULL);
if (chArray == NULLCONTAINER)
{
_retnl(paramList, 0);
return;
}
_conSizeA(chArray, &lArrayLen, 0);
/*
get the optional parameter for start and end index
and check if 0 < lStartIndex <= lEndIndex <= lArrayLen
*/
if ( XPP_IS_NUM(_partype(paramList, 2)) )
lStartIndex = _parnl(paramList, 2);
else
lStartIndex = 0;
if ( XPP_IS_NUM(_partype(paramList, 3) ) )
{
lEndIndex = _parnl(paramList, 3);
if (lEndIndex < 1) lEndIndex = 1;
else if (lEndIndex > lArrayLen) lEndIndex = lArrayLen;
}
else
lEndIndex = lArrayLen;
if (lStartIndex < 1) lStartIndex = 1;
else if (lStartIndex > lEndIndex) lStartIndex = lEndIndex;
chElement = NULLCONTAINER;
for (lElement = lStartIndex; lElement <= lEndIndex; lElement++)
{
/*
get next element of array
*/
chElement = _conArrayGet(chArray, chElement, lElement, 0);
/*
for numeric elements: add the value
*/
if (! _conGetNL(chElement, &lValue))
lSum += lValue;
/*
for string elements: add the length
*/
else if (! _conSizeC(chElement, (ULONG*)&lValue))
lSum += lValue;
}
/*
release the temporary element container and
the parameter container
*/
if (chElement != NULLCONTAINER)
_conRelease(chElement);
_conRelease(chArray);
}
_retnl( paramList, lSum );
}
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.