Description
There are two versions of the PBBoundedArrayCreator template class. The first version is used to create a bounded array of a standard type. 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.The second version is used to create a bounded array of strings.
Methods
PBBoundedArrayCreator has two methods:
Description
Obtains an array that has been created.
Syntax
GetArray()
Return value
pbarray.
Examples
This example sets up an array, reads in values, and then obtains the values in the array:
LPCTSTR *ostr_a; char **sp; int i; pbarray out_array; arrayBounds* bounds; pbuint dim1, dim2, current_dim; pblong itemcount1, itemcount2; PBXRESULT ret; PBArrayInfo* ai; pbstring *iarg, *oarg; typedef PBBoundedArrayCreator<pbvalue_string> BoundedStringArrayCreator; in >> dim1; // allocate memory for pointer bounds bounds = (arrayBounds*)malloc(dim1*sizeof (PBArrayInfo::ArrayBound)); bounds = new arrayBounds[dim1]; // read in lowerbound and upperbound for each dimension // and calculate the array item count itemcount1 = 1; for (i=0;i<dim1;i++) { in >>bounds[i].lowerBound >> bounds[i].upperBound; itemcount1 = itemcount1* (bounds[i].upperBound - bounds[i].lowerBound +1); } sp = new char*[itemcount1]; ostr_a = new LPCTSTR[itemcount1]; iarg = new pbstring[itemcount1]; // Read in array items for (i=0; i<itemcount1; i++) { sp[i] = new char[20]; in >> sp[i]; iarg[i]= session->NewString(sp[i]); } // create bounded simple array and set iarg[i] to it { BoundedStringArrayCreator ac(session, dim1, bounds); current_dim = 1; BoundedArrayItem<pbstring, pbvalue_string, BoundedStringArrayCreator>::f_set_arrayitem (session, ac, dim1, bounds, iarg, current_dim); BoundedArrayItem<pbstring, pbvalue_string, BoundedStringArrayCreator>::array_itemcount = 0; out_array = ac.GetArray(); }
See also
Description
Sets a value or string to 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 SetAt in arrays of a type specified by a ValueType:
// arguments: // ac: class object of PBBoundedArrayCreator or // PBBoundedObjectArrayCreator to set items into // dimensions: array dimension, can be 1,2,3,...,n // bounds: upper and lower bound for each dimension // iarg: T type array to store the data value set // into array creator ac // current_dim: remember which dimension is looped into template < typename T, pbvalue_type I,class C> void BoundedArrayItem<T,I,C>::f_set_arrayitem (IPB_Session* session, C& ac, pblong dimensions, arrayBounds* bounds, T* iarg, int current_dim) { int i; if (current_dim > dimensions) return; for(i= bounds[current_dim-1].lowerBound; i<= bounds[current_dim-1].upperBound; i++) { if (current_dim == dimensions) { dim[current_dim-1]= i; ac.SetAt(dim,iarg[array_itemcount]); array_itemcount++; } else { dim[current_dim-1]= i; BoundedArrayItem<T,I,C>::f_set_arrayitem (session, ac, dimensions, bounds, iarg, current_dim+1); } } }
See also