PBArrayAccessor template class

Description

There are two versions of the PBArrayAccessor template class. The first version is used to access the items in an array of a standard type. The second version is used to access items in a string array. The standard types are defined as ValueTypes in pbtraits.h and are pbint, pbuint, pbbyte, pblong, pblonglong, pbulong, pbboolean, pbreal, pbdouble, pbdec, pbdate, pbtime, pbdatetime, pbchar, pbblob, and pbstring.

PBArrayAccessor has four methods:

GetAt

IsNull

SetAt

SetToNull

GetAt

Description

Obtains the array item at the specified dimension.

Syntax

GetAt(pblong dim[])

Return value

ValueType (defined in pbtraits.h).

Argument

Description

dim

The dimension of the array item to be obtained


Examples

See SetAt.

See also

SetAt

IsNull

Description

Returns true if the array item contains a null value, otherwise returns false.

Syntax

IsNull(pblong dim[ ])

Argument

Description

dim

The dimension of the array item to be tested


Return value

pbboolean.

See also

GetAt

SetAt

SetToNull

SetAt

Description

Sets the array item at the specified dimension.

Syntax

For arrays of a specified ValueType:

SetAt(pblong dim[ ], ValueType v)

For string arrays:

SetAt(pblong dim[ ], LPCTSTR string)
SetAt(pblong dim[ ], pbstring string)

Argument

Description

dim

The dimension of the array item to be set

v

A ValueType defined in pbtraits.h

string

A string of type pbstring or LPCTSTR


Return value

None.

Examples

This example shows the use of GetAt and SetAt in arrays of a type specified by a ValueType:

template < typename T, pbvalue_type I>
void ArrayCreator<T, I>::f_unbounded_simple_array(
IPB_Session* session,
ifstream in,
fstream out,
LPCSTR data_type)
{
pbarray out_array;
int i;
pblong dim[4], itemcount1, itemcount2;

T *iarg, oarg;

in >> itemcount1;
iarg = new T[itemcount1];
// Create unbounded integer array 
{
PBUnboundedArrayCreator<I> ac(session);
out_array = ac.GetArray();
PBArrayAccessor<I> aa(session, out_array);
for(i=0; i<itemcount1; i++)
in >> iarg[i];
for (i=0; i<itemcount1; i++)
{
dim[0]=i+1;
aa.SetAt(dim, iarg[i]);
}
itemcount2 = session->GetArrayItemCount(out_array); 
out <<"The array item count is "<< itemcount2 <<
endl; 
for (i=0; i<itemcount2; i++)
{
dim[0]=i+1;
oarg=aa.GetAt(dim);
if (oarg != iarg[i])
out << "*** ERROR"<< endl;
else
out << oarg << " ";
}
}
delete []iarg;
out << endl; 
return;
}

See also

GetAt

SetToNull

Description

Sets the value of the specified array item to null.

Syntax

SetToNull(pblong dim[ ])

Argument

Description

dim

The dimension of the array item to be set


Return value

None.

See also

GetAt

IsNull

SetAt