gtpc2mc7C/C++ Language Support User's Guide

TO2_atWithBuffer-Retrieve an Element from a Collection

This function returns the data at the specified index in the specified collection in the supplied buffer. If the collection is an array and the position is marked as empty, this method returns a data length of 0 and an update sequence counter of 0.

Note:
This function does not support all collections. See Table 47 for collections that are supported for this function.

Format

#include <c$to2.h>
TO2_BUF_PTR TO2_atWithBuffer (const TO2_PID_PTR  pid_ptr,
                                    TO2_ENV_PTR  env_ptr,
                              const long        *index,
                              const long        *bufferLength,
                                    TO2_BUF_PTR  buffer);

pid_ptr
The pointer to the persistent identifier (PID) assigned to the collection.

env_ptr
The pointer to the environment as returned by the TO2_createEnv function.

index
The pointer to the index of the entry that has contents that will be returned.

bufferLength
The pointer to a field that contains the length of the supplied buffer. The buffer should be large enough to hold the data to be returned plus 16 additional bytes for a header. The minimum buffer length is 20 bytes.

buffer
The pointer to the supplied buffer.

Normal Return

The normal return value is the address of the same buffer that the you specified when calling the function. The normal return is a pointer (TO2_BUF_PTR) to a structure (buffer) of type TO2_BUF_HDR (see Type Definitions).

If the length of the data is greater than the length of the buffer, only the amount of data that will fit is placed in the buffer. The length is returned in the buffer and is the actual length of the data element. It is the responsibility of the caller to check the returned length against the length of the supplied buffer to determine if the entire element has been returned.

Error Return

An error return is indicated by a NULL pointer. When a NULL pointer is returned, use the TO2_getErrorCode function to determine the specific error code. For more information, see Error Handling.

The following error codes are common for this function:

TO2_ERROR_BUFFER_SIZE

TO2_ERROR_DATA_LGH

TO2_ERROR_EMPTY

TO2_ERROR_ENV

TO2_ERROR_EODAD

TO2_ERROR_INDEX

TO2_ERROR_METHOD

TO2_ERROR_NOT_INIT

TO2_ERROR_PID

TO2_ERROR_ZERO_PID

Programming Considerations

This function does not use TPF transaction services on behalf of the caller.

Examples

The following example copies the third element of a specified collection into the specified buffer.

#include <c$to2.h>                  /* Needed for TO2 API functions    */
#include <stdio.h>                  /* APIs for standard I/O functions */
 
char                [100];
long                my_bufL;
TO2_PID             collect;
TO2_ENV_PTR         env_ptr;       /* Pointer to the TO2 environment   */
long                position=3;    /* We will try to get third element */
TO2_ERROR_CODE      err_code;

  ·
  ·
  ·
/***********************************************************************/ /* Copy the element at the specified position. */ /***********************************************************************/ my_bufL = sizeof(my_buf); if (TO2_atWithBuffer == NULL (&collect, env_ptr &position, &my_bufL, my_buf)); if (my_buf == NULL) { err_code = TO2_getErrorCode(env_ptr); if (err_code != TO2_ERROR_EODAD) { printf("TO2_atWithBuffer failed!\n"); process_error(env_ptr); } } else { printf("TO2_atWithBuffer successful!\n"); }

Related Information