1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
//**************************************************************************
//
//                            Copyright 2002
//                              Sybase Inc.
//
//								Copyright ?2002
//						Sybase, Inc. and its subsidiaries.
//	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
//	Sybase, Inc.("Sybase") claims copyright in this program and documentation
//	as an unpublished work, versions of which were first licensed on the date
//	indicated in the foregoing notice. This claim of copyright does not imply
//	waiver of Sybase's other rights.
// ------------------------------------------------------------------------
//
//    Filename :        pbarray.h
//
//    Author   :        PB kernel team
//
//    Purpose  :        Definition of PBArrayAccessor
//
//***************************************************************************

#ifndef _PBARRAY_H_
#define _PBARRAY_H_


#include "pbtraits.h"

//****************************************************************************
//	PBUnboundedArrayCreator template
//
//	PBUnboundedArrayCreator is for creating unbounded array of standard data
//	types.
//****************************************************************************
template <pbvalue_type T>
class PBUnboundedArrayCreator
{
	typedef typename PBNI_NAMESPACE::PBValueTraits<T>::ValueType ValueType;

	IPB_Session*	d_session;
	pbarray			d_array;

public:
	explicit PBUnboundedArrayCreator(IPB_Session* session, pblong initialSize=0);
	~PBUnboundedArrayCreator();

	void	SetAt(pblong pos, ValueType v);
	pbarray	GetArray();

private:	// prevention
	PBUnboundedArrayCreator(const PBUnboundedArrayCreator&);
	PBUnboundedArrayCreator operator=(const PBUnboundedArrayCreator&);
};

//***************************************************************************
//	template <typename T> PBUnboundedArrayCreator
//***************************************************************************
template <pbvalue_type T>
PBUnboundedArrayCreator<T>::PBUnboundedArrayCreator
(
	IPB_Session* session,
	pblong initialSize
)
:	d_session(session),
	d_array(0)
{
	d_array = session->NewUnboundedSimpleArray(PBValueTraits<T>::GetValueType());
	if (initialSize > 0)
	{
	}
}

template <pbvalue_type T>
PBUnboundedArrayCreator<T>::~PBUnboundedArrayCreator()
{
}

template <pbvalue_type T>
void	PBUnboundedArrayCreator<T>::SetAt(pblong pos, ValueType v)
{
	pblong dim[1];
	dim[0] = pos;
	PBValueTraits<T>::SetAt(d_session, d_array, &dim[0], v);
}

template <pbvalue_type T>
pbarray	PBUnboundedArrayCreator<T>::GetArray()
{
	return d_array;
}


//****************************************************************************
//	PBUnboundedArrayCreator<pbstring>
//
//	PBUnboundedArrayCreator is for creating unbounded array of pbstring
//	types.
//****************************************************************************
template <>
class PBUnboundedArrayCreator<pbvalue_string>
{
	IPB_Session*	d_session;
	pbarray			d_array;

public:
	explicit PBUnboundedArrayCreator(IPB_Session* session, pblong initialSize=0);
	~PBUnboundedArrayCreator();

	void	SetAt(pblong pos, pbstring v);
	void	SetAt(pblong pos, LPCTSTR v);
	pbarray	GetArray();

private:	// prevention
	PBUnboundedArrayCreator(const PBUnboundedArrayCreator&);
	PBUnboundedArrayCreator operator=(const PBUnboundedArrayCreator&);
};

typedef PBUnboundedArrayCreator<pbvalue_int>		PBUnboundedIntArrayCreator;
typedef PBUnboundedArrayCreator<pbvalue_long>		PBUnboundedLongArrayCreator;
typedef PBUnboundedArrayCreator<pbvalue_real>		PBUnboundedRealArrayCreator;
typedef PBUnboundedArrayCreator<pbvalue_double>		PBUnboundedDoubleArrayCreator;
typedef PBUnboundedArrayCreator<pbvalue_dec>		PBUnboundedDecArrayCreator;
typedef PBUnboundedArrayCreator<pbvalue_string>		PBUnboundedStringArrayCreator;
typedef PBUnboundedArrayCreator<pbvalue_boolean>	PBUnboundedBooleanArrayCreator;
typedef PBUnboundedArrayCreator<pbvalue_uint>		PBUnboundedUintArrayCreator;
typedef PBUnboundedArrayCreator<pbvalue_ulong>		PBUnboundedUlongArrayCreator;
typedef PBUnboundedArrayCreator<pbvalue_blob>		PBUnboundedBlobArrayCreator;
typedef PBUnboundedArrayCreator<pbvalue_date>		PBUnboundedDateArrayCreator;
typedef PBUnboundedArrayCreator<pbvalue_time>		PBUnboundedTimeArrayCreator;
typedef PBUnboundedArrayCreator<pbvalue_datetime>	PBUnboundedDateTimeArrayCreator;
typedef PBUnboundedArrayCreator<pbvalue_char>		PBUnboundedCharArrayCreator;
typedef PBUnboundedArrayCreator<pbvalue_longlong>	PBUnboundedLongLongArrayCreator;
typedef PBUnboundedArrayCreator<pbvalue_byte>	       PBUnboundedByteArrayCreator;


//****************************************************************************
//	PBUnboundedObjectArrayCreator
//
//	PBUnboundedObjectArrayCreator is for creating unbounded array of pbobjects
//	types.
//****************************************************************************
class PBUnboundedObjectArrayCreator
{
	IPB_Session*	d_session;
	pbarray			d_array;
	pbclass			d_class;

public:
	explicit PBUnboundedObjectArrayCreator
		(
		IPB_Session* session,
		pbclass cls,
		pblong initialSize=0
		);
	~PBUnboundedObjectArrayCreator();

	void	SetAt(pblong pos, pbobject obj);
	pbarray	GetArray();

private:	// prevention
	PBUnboundedObjectArrayCreator(const PBUnboundedObjectArrayCreator&);
	PBUnboundedObjectArrayCreator operator=(const PBUnboundedObjectArrayCreator&);
};

//****************************************************************************
//	PBBoundedArrayCreator template
//
//	PBBoundedArrayCreator is for creating bounded array of standard data
//	types.
//****************************************************************************
template <pbvalue_type T>
class PBBoundedArrayCreator
{
	typedef typename PBNI_NAMESPACE::PBValueTraits<T>::ValueType ValueType;

	IPB_Session*	d_session;
	pbarray			d_array;

public:
	explicit PBBoundedArrayCreator
		(
		IPB_Session* session,
		pbuint dimensions,
		PBArrayInfo::ArrayBound* bounds
		);

	~PBBoundedArrayCreator();

	void	SetAt(pblong dim[], ValueType v);
	pbarray	GetArray();

private:	// prevention
	PBBoundedArrayCreator(const PBBoundedArrayCreator&);
	PBBoundedArrayCreator operator=(const PBBoundedArrayCreator&);
};

template <pbvalue_type T>
PBBoundedArrayCreator<T>::PBBoundedArrayCreator
(
	IPB_Session* session,
	pbuint dimensions,
	PBArrayInfo::ArrayBound* bounds
)
:	d_session(session),
	d_array(0)
{
	d_array = session->NewBoundedSimpleArray(PBValueTraits<T>::GetValueType(),
		dimensions, bounds);
}

template <pbvalue_type T>
PBBoundedArrayCreator<T>::~PBBoundedArrayCreator()
{
}

template <pbvalue_type T>
void	PBBoundedArrayCreator<T>::SetAt(pblong dim[], ValueType v)
{
	PBValueTraits<T>::SetAt(d_session, d_array, dim, v);
}

template <pbvalue_type T>
pbarray	PBBoundedArrayCreator<T>::GetArray()
{
	return d_array;
}

//****************************************************************************
//	PBBoundedArrayCreator<pbstring>
//
//	PBBoundedArrayCreator is for creating bounded array of pbstring
//	types.
//****************************************************************************
template <>
class PBBoundedArrayCreator<pbvalue_string>
{
	IPB_Session*	d_session;
	pbarray			d_array;

public:
	explicit PBBoundedArrayCreator
		(
		IPB_Session* session,
		pbuint dimensions,
		PBArrayInfo::ArrayBound* bounds
		);

	~PBBoundedArrayCreator();

	void	SetAt(pblong dim[], pbstring v);
	void	SetAt(pblong dim[], LPCTSTR v);
	pbarray	GetArray();

private:	// prevention
	PBBoundedArrayCreator(const PBBoundedArrayCreator&);
	PBBoundedArrayCreator operator=(const PBBoundedArrayCreator&);
};

typedef PBBoundedArrayCreator<pbvalue_int>		PBBoundedIntArrayCreator;
typedef PBBoundedArrayCreator<pbvalue_long>		PBBoundedLongArrayCreator;
typedef PBBoundedArrayCreator<pbvalue_real>		PBBoundedRealArrayCreator;
typedef PBBoundedArrayCreator<pbvalue_double>	PBBoundedDoubleArrayCreator;
typedef PBBoundedArrayCreator<pbvalue_dec>		PBBoundedDecArrayCreator;
typedef PBBoundedArrayCreator<pbvalue_string>	PBBoundedStringArrayCreator;
typedef PBBoundedArrayCreator<pbvalue_boolean>	PBBoundedBooleanArrayCreator;
typedef PBBoundedArrayCreator<pbvalue_uint>		PBBoundedUintArrayCreator;
typedef PBBoundedArrayCreator<pbvalue_ulong>	PBBoundedUlongArrayCreator;
typedef PBBoundedArrayCreator<pbvalue_blob>		PBBoundedBlobArrayCreator;
typedef PBBoundedArrayCreator<pbvalue_date>		PBBoundedDateArrayCreator;
typedef PBBoundedArrayCreator<pbvalue_time>		PBBoundedTimeArrayCreator;
typedef PBBoundedArrayCreator<pbvalue_datetime>	PBBoundedDateTimeArrayCreator;
typedef PBBoundedArrayCreator<pbvalue_char>		PBBoundedCharArrayCreator;
typedef PBBoundedArrayCreator<pbvalue_longlong>	PBBoundedLongLongArrayCreator;
typedef PBBoundedArrayCreator<pbvalue_byte>	       PBBoundedByteArrayCreator;

//****************************************************************************
//	PBBoundedObjectArrayCreator
//
//	PBBoundedObjectArrayCreator is for creating bounded array of pbobjects
//	types.
//****************************************************************************
class PBBoundedObjectArrayCreator
{
	IPB_Session*	d_session;
	pbarray			d_array;
	pbclass			d_class;

public:
	explicit PBBoundedObjectArrayCreator
		(
		IPB_Session* session,
		pbclass cls,
		pbuint dimensions,
		PBArrayInfo::ArrayBound* bounds
		);

	~PBBoundedObjectArrayCreator();

	void	SetAt(pblong dim[], pbobject obj);
	pbarray	GetArray();

private:	// prevention
	PBBoundedObjectArrayCreator(const PBBoundedObjectArrayCreator&);
	PBBoundedObjectArrayCreator operator=(const PBBoundedObjectArrayCreator&);
};

//****************************************************************************
//	template <pbvalue_type T> PBArrayAccessor
//
//	PBArrayAccessor template is for accessing the items of an array
//****************************************************************************
template <pbvalue_type T>
class PBArrayAccessor
{
	IPB_Session*	d_session;
	pbarray			d_array;

public:
	typedef typename PBNI_NAMESPACE::PBValueTraits<T>::ValueType ValueType;

	explicit PBArrayAccessor
		(
		IPB_Session* session,
		pbarray	array
		);

	~PBArrayAccessor();

	void	SetAt(pblong dim[], ValueType v);
	ValueType	GetAt(pblong dim[], pbboolean& isNull);

	pbboolean	IsNull(pblong dim[]);
	void	SetToNull(pblong dim[]);


private:	// prevention
	PBArrayAccessor(const PBArrayAccessor&);
	PBArrayAccessor operator=(const PBArrayAccessor&);
};

template <pbvalue_type T>
PBArrayAccessor<T>::PBArrayAccessor
(
	IPB_Session* session,
	pbarray array
)
:	d_session(session),
	d_array(array)
{
}

template <pbvalue_type T>
PBArrayAccessor<T>::~PBArrayAccessor()
{
}

template <pbvalue_type T>
void	PBArrayAccessor<T>::SetAt(pblong dim[], ValueType v)
{
	PBValueTraits<T>::SetAt(d_session, d_array, dim, v);
}

template <pbvalue_type T>
typename PBArrayAccessor<T>::ValueType	PBArrayAccessor<T>::GetAt(pblong dim[], pbboolean& isNull)
{
	return PBValueTraits<T>::GetAt(d_session, d_array, dim, isNull);
}

template <pbvalue_type T>
pbboolean	PBArrayAccessor<T>::IsNull(pblong dim[])
{
	return d_session->IsArrayItemNull(d_array, dim);
}

template <pbvalue_type T>
void	PBArrayAccessor<T>::SetToNull(pblong dim[])
{
	d_session->SetArrayItemToNull(d_array, dim);
}


//****************************************************************************
//	template <> PBArrayAccessor<pbvalue_string>
//
//	PBArrayAccessor template is for accessing the items of a string array
//****************************************************************************
template <>
class PBArrayAccessor<pbvalue_string>
{
	IPB_Session*	d_session;
	pbarray			d_array;

public:
	explicit PBArrayAccessor
		(
		IPB_Session* session,
		pbarray	array
		);

	~PBArrayAccessor();

	void	SetAt(pblong dim[], LPCTSTR str);
	void	SetAt(pblong dim[], pbstring str);
	pbstring	GetAt(pblong dim[], pbboolean& isNull);

private:	// prevention
	PBArrayAccessor(const PBArrayAccessor&);
	PBArrayAccessor operator=(const PBArrayAccessor&);
};

typedef PBArrayAccessor<pbvalue_int>		PBIntArrayAccessor;
typedef PBArrayAccessor<pbvalue_long>		PBLongArrayAccessor;
typedef PBArrayAccessor<pbvalue_real>		PBRealArrayAccessor;
typedef PBArrayAccessor<pbvalue_double>		PBDoubleArrayAccessor;
typedef PBArrayAccessor<pbvalue_dec>		PBDecArrayAccessor;
typedef PBArrayAccessor<pbvalue_string>		PBStringArrayAccessor;
typedef PBArrayAccessor<pbvalue_boolean>	PBBooleanArrayAccessor;
typedef PBArrayAccessor<pbvalue_uint>		PBUintArrayAccessor;
typedef PBArrayAccessor<pbvalue_ulong>		PBUlongArrayAccessor;
typedef PBArrayAccessor<pbvalue_blob>		PBBlobArrayAccessor;
typedef PBArrayAccessor<pbvalue_date>		PBDateArrayAccessor;
typedef PBArrayAccessor<pbvalue_time>		PBTimeArrayAccessor;
typedef PBArrayAccessor<pbvalue_datetime>	PBDateTimeArrayAccessor;
typedef PBArrayAccessor<pbvalue_char>		PBCharArrayAccessor;
typedef PBArrayAccessor<pbvalue_longlong>	PBLongLongArrayAccessor;
typedef PBArrayAccessor<pbvalue_byte>	       PBByteArrayAccessor;

//****************************************************************************
//	PBObjectArrayAccessor
//
//	PBObjectArrayAccessor is for accessing the elements of an object array
//****************************************************************************
class PBObjectArrayAccessor
{
	IPB_Session*	d_session;
	pbarray			d_array;

public:
	explicit PBObjectArrayAccessor
		(
		IPB_Session* session,
		pbarray		array
		);

	~PBObjectArrayAccessor();

	void	SetAt(pblong dim[], pbobject obj);
	pbobject	GetAt(pblong dim[], pbboolean& isNull);

private:	// prevention
	PBObjectArrayAccessor(const PBObjectArrayAccessor&);
	PBObjectArrayAccessor operator=(const PBObjectArrayAccessor&);
};

#endif