-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathEtchNativeArray.h
More file actions
846 lines (740 loc) · 24 KB
/
EtchNativeArray.h
File metadata and controls
846 lines (740 loc) · 24 KB
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
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
/* $Id$
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version
* 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __ETCHNATIVEARRAY_H__
#define __ETCHNATIVEARRAY_H__
#include "capu/util/SmartPointer.h"
#include "common/EtchTypes.h"
class Pos {
public:
Pos(capu::int32_t i1, capu::int32_t i2 = -1, capu::int32_t i3 = -1, capu::int32_t i4 = -1, capu::int32_t i5 = -1, capu::int32_t i6 = -1, capu::int32_t i7 = -1, capu::int32_t i8 = -1, capu::int32_t i9 = -1) : size(0) {
if (i1 != -1) {
pos[0] = i1;
size = 1;
} else {
return;
}
if (i2 != -1) {
pos[1] = i2;
size = 2;
} else {
return;
}
if (i3 != -1) {
pos[2] = i3;
size = 3;
} else {
return;
}
if (i4 != -1) {
pos[3] = i4;
size = 4;
} else {
return;
}
if (i5 != -1) {
pos[4] = i5;
size = 5;
} else {
return;
}
if (i6 != -1) {
pos[5] = i6;
size = 6;
} else {
return;
}
if (i7 != -1) {
pos[6] = i7;
size = 7;
} else {
return;
}
if (i8 != -1) {
pos[7] = i8;
size = 8;
} else {
return;
}
if (i9 != -1) {
pos[8] = i9;
size = 9;
} else {
return;
}
}
capu::int32_t pos[9];
capu::int32_t size;
};
//internal helper classes
template <class T>
class EtchArray;
template <class T>
class EtchArrayBase {
public:
/**
* Creates a new instance of EtchArrayBase
*/
EtchArrayBase(capu::int32_t length, capu::int32_t dim = 1)
: mLength(length), mDim(dim) {
}
virtual ~EtchArrayBase() {
}
/**
* Returns the dimension
*/
virtual capu::int32_t getDim() {
return mDim;
}
/**
* Returns the length
*/
virtual capu::int32_t getLength() {
return mLength;
}
/**
* Sets an element at the given position
*/
virtual status_t set(Pos pos, capu::int32_t index, const T &data) = 0;
/**
* Sets an array at the given position
*/
virtual status_t set(Pos pos, capu::int32_t index, const T* data, capu::int32_t dataSize, capu::int32_t offset, capu::int32_t length, capu::int32_t *written) = 0;
/**
* Sets the sub array at the given position
*/
virtual status_t set(Pos pos, capu::int32_t index, const capu::SmartPointer<EtchArray<T> > &data) = 0;
/**
* Returns the element at the given position
*/
virtual status_t get(Pos pos, capu::int32_t index, T *result) = 0;
/**
* Returns the array at the given position
*/
virtual status_t get(Pos pos, capu::int32_t index, T* data, capu::int32_t dataSize, capu::int32_t offset, capu::int32_t length, capu::int32_t *read) = 0;
/**
* Returns the subarray at the given position
*/
virtual status_t get(Pos pos, capu::int32_t index, capu::SmartPointer<EtchArray<T> > *result) = 0;
/**
* creates a new nested array at the given position with the given length and dim
*/
virtual status_t createArray(Pos pos, capu::int32_t index, capu::int32_t length, capu::int32_t dim) = 0;
/**
* resizes the array to the given size
*/
virtual status_t resize(capu::int32_t newSize) = 0;
protected:
capu::int32_t mLength;
capu::int32_t mDim;
};
template <class T>
class EtchArrayData : public EtchArrayBase<T> {
public:
/**
* Create a new instance of EtchArrayData
*/
EtchArrayData(capu::int32_t length)
: EtchArrayBase<T>(length) {
mData = new T[EtchArrayBase<T>::mLength];
}
/**
* Destructure
*/
virtual ~EtchArrayData() {
delete[] mData;
}
/**
*@see EtchArrayBase
*/
status_t set(Pos pos, capu::int32_t index, const T &data) {
if(pos.size < index || pos.pos[index] > EtchArrayBase<T>::mLength || pos.size-1 != index) {
return ETCH_ERANGE;
}
mData[pos.pos[index]] = data;
return ETCH_OK;
}
/**
*@see EtchArrayBase
*/
status_t set(Pos pos, capu::int32_t index, const T* data, capu::int32_t dataSize, capu::int32_t offset, capu::int32_t length, capu::int32_t *written) {
if(pos.size < index || pos.pos[index] > EtchArrayBase<T>::mLength || pos.size-1 != index || dataSize < offset + length) {
return ETCH_ERANGE;
}
if(data != NULL) {
//TODO: replace with memcpy
capu::int32_t i;
for (i = 0; i < EtchArrayBase<T>::mLength && i < length; i++) {
mData[pos.pos[index]+i] = data[offset + i];
}
if (written != NULL) {
*written = i;
}
} else {
return ETCH_EINVAL;
}
return ETCH_OK;
}
/**
*@see EtchArrayBase
*/
status_t set(Pos pos, capu::int32_t index, const capu::SmartPointer<EtchArray<T> > &data) {
return ETCH_ERANGE;
}
/**
*@see EtchArrayBase
*/
status_t get(Pos pos, capu::int32_t index, T *result) {
if(pos.size < index || pos.size-1 != index || pos.pos[index] > EtchArrayBase<T>::mLength) {
return ETCH_ERANGE;
}
if(result != NULL) {
*result = mData[pos.pos[index]];
} else {
return ETCH_EINVAL;
}
return ETCH_OK;
}
/**
*@see EtchArrayBase
*/
status_t get(Pos pos, capu::int32_t index, T* data, capu::int32_t dataSize, capu::int32_t offset, capu::int32_t length, capu::int32_t *read) {
if(pos.size < index || pos.pos[index] > EtchArrayBase<T>::mLength || pos.size-1 != index || dataSize < offset + length) {
return ETCH_ERANGE;
}
if(data != NULL) {
//TODO: replace with memcpy
capu::int32_t i;
for (i = 0; i < EtchArrayBase<T>::mLength && i < length; i++) {
data[offset + i] = mData[pos.pos[index]+i];
}
if (read != NULL) {
*read = i;
}
} else {
return ETCH_EINVAL;
}
return ETCH_OK;
}
/**
*@see EtchArrayBase
*/
status_t get(Pos pos, capu::int32_t index, capu::SmartPointer<EtchArray<T> > *result) {
return ETCH_ERANGE;
}
/**
*@see EtchArrayBase
*/
status_t createArray(Pos pos, capu::int32_t index, capu::int32_t length, capu::int32_t dim) {
return ETCH_ERANGE;
}
/**
*@see EtchArrayBase
*/
status_t resize(capu::int32_t newSize) {
if (newSize <= EtchArrayBase<T>::mLength) {
return ETCH_ERANGE;
}
T *newData = new T[newSize];
for (capu::int32_t i = 0; i<EtchArrayBase<T>::mLength; i++) {
newData[i] = mData[i];
}
delete[] mData;
mData = newData;
EtchArrayBase<T>::mLength = newSize;
return ETCH_OK;
}
private:
T* mData;
};
template <class T>
class EtchArray : public EtchArrayBase<T> {
public:
/**
* Creats a new instance of the EtchArray class
*/
EtchArray(capu::int32_t length, capu::int32_t dim)
: EtchArrayBase<T>(length, dim) {
mData = new capu::SmartPointer<EtchArrayBase<T> >[EtchArrayBase<T>::mLength];
}
/**
* Destructure
*/
virtual ~EtchArray() {
delete[] mData;
}
/**
*@see EtchArrayBase
*/
status_t set(Pos pos, capu::int32_t index, const T &data) {
if(mData[pos.pos[index]].get() != NULL) {
return mData[pos.pos[index]]->set(pos, index+1, data);
}
return ETCH_ERANGE;
}
/**
*@see EtchArrayBase
*/
status_t set(Pos pos, capu::int32_t index, const T* data, capu::int32_t dataSize, capu::int32_t offset, capu::int32_t length, capu::int32_t *written) {
if(pos.size < index || pos.pos[index] > EtchArrayBase<T>::mLength) {
return ETCH_ERANGE;
}
if(mData[pos.pos[index]].get() != NULL) {
if ((pos.size -1) == index) {
//set subarray
//TODO: enhance performance avoiding for-loop-copy
for (capu::int8_t i = 0; i < length; i++) {
mData[pos.pos[index]]->set(i,0,data[i]);
}
} else {
//redirect to next sub array
return mData[pos.pos[index]]->set(pos, index+1, data, dataSize, offset, length, written);
}
} else {
return ETCH_EINVAL;
}
return ETCH_OK;
}
/**
*@see EtchArrayBase
*/
status_t set(Pos pos, capu::int32_t index, const capu::SmartPointer<EtchArray<T> > &data) {
if(pos.size < index || pos.pos[index] > EtchArrayBase<T>::mLength) {
return ETCH_ERANGE;
}
if (pos.size - index == 1) {
if (EtchArrayBase<T>::mDim -1 == data->getDim()) { //check if we set a subarray with correct dimension
mData[pos.pos[index]] = data;
} else {
return ETCH_ERANGE;
}
} else {
return mData[pos.pos[index]]->set(pos,index+1,data);
}
return ETCH_OK;
}
/**
*@see EtchArrayBase
*/
status_t get(Pos pos, capu::int32_t index, T *result) {
if(pos.size < index || pos.pos[index] > EtchArrayBase<T>::mLength) {
return ETCH_ERANGE;
}
if(mData[pos.pos[index]].get() != NULL) {
return mData[pos.pos[index]]->get(pos, index+1, result);
}
else {
return ETCH_EINVAL;
}
return ETCH_OK;
}
/**
*@see EtchArrayBase
*/
status_t get(Pos pos, capu::int32_t index, T* data, capu::int32_t dataSize, capu::int32_t offset, capu::int32_t length, capu::int32_t *read) {
if(pos.size < index || pos.pos[index] > EtchArrayBase<T>::mLength) {
return ETCH_ERANGE;
}
if(mData[pos.pos[index]].get() != NULL) {
return mData[pos.pos[index]]->get(pos, index+1, data, dataSize, offset, length, read);
} else {
return ETCH_EINVAL;
}
return ETCH_OK;
}
/**
*@see EtchArrayBase
*/
status_t get(Pos pos, capu::int32_t index, capu::SmartPointer<EtchArray<T> > *result) {
if(pos.size < index || pos.pos[index] > EtchArrayBase<T>::mLength || mData[pos.pos[index]].get() == NULL) {
return ETCH_ERANGE;
}
if (pos.size - index == 1) {
*result = capu::smartpointer_cast<EtchArray<T> >(mData[pos.pos[index]]);
} else {
return mData[pos.pos[index]]->get(pos,index+1,result);
}
return ETCH_OK;
}
/**
*@see EtchArrayBase
*/
status_t createArray(Pos pos, capu::int32_t index, capu::int32_t length, capu::int32_t dim) {
if(mData[pos.pos[index]].get() == NULL) {
if(dim == 1) {
mData[pos.pos[index]] = new EtchArrayData<T>(length);
} else {
if (pos.size - index == 1) {
mData[pos.pos[index]] = new EtchArray<T>(length, dim);
}
}
} else {
if (dim == 1 || pos.size - index == 1) {
return ETCH_ERANGE;
}
return mData[pos.pos[index]]->createArray(pos, index+1, length, dim-1);
}
return ETCH_OK;
}
/**
*@see EtchArrayBase
*/
status_t resize(capu::int32_t newSize) {
if (newSize <= EtchArrayBase<T>::mLength) {
return ETCH_ERANGE;
}
capu::SmartPointer<EtchArrayBase<T> > *newData = new capu::SmartPointer<EtchArrayBase<T> >[newSize];
for (capu::int32_t i = 0; i<EtchArrayBase<T>::mLength; i++) {
newData[i] = mData[i];
}
delete[] mData;
mData = newData;
EtchArrayBase<T>::mLength = newSize;
return ETCH_OK;
}
private:
capu::SmartPointer<EtchArrayBase<T> > *mData;
};
template<class T>
class EtchNativeArray;
class EtchNativeArrayBase :
public EtchObject {
public:
EtchNativeArrayBase() {
}
EtchNativeArrayBase(const EtchNativeArrayBase& other)
: EtchObject(other) {
}
/**
* gets the EtchObject at index i in result
* returns ETCH_ERANGE, if out of bounds.
* returns ETCH_OK otherwise
*/
status_t getBase(Pos pos, capu::SmartPointer<EtchObject> &result);
/**
* sets the EtchObject at index i
* returns ETCH_ERANGE, if out of bounds.
* returns ETCH_OK otherwise
*/
status_t setBase(Pos pos, capu::SmartPointer<EtchObject> data);
/**
* resize current array to newSize
* returns ETCH_ERANGE, if newSize is smaller then current size
* returns ETCH_OK otherwise
*/
virtual status_t resize(capu::int32_t newSize) = 0;
/**
* Returns the length of array
*/
virtual capu::int32_t getLength() = 0;
/**
* Returns the dim of array
*/
virtual capu::uint32_t getDim() = 0;
};
template<class T>
class EtchNativeArray :
public EtchNativeArrayBase {
public:
/**
* EtchObjectType for EtchNativeArray.
*/
static const EtchObjectType* TYPE();
/**
* Constructs a EtchNativeArray object.
*/
EtchNativeArray(capu::int32_t length, capu::int32_t dim = 1);
/**
* Constructs a EtchNativeArray object from native array.
*/
EtchNativeArray(capu::int32_t length, capu::int32_t dim, T* array);
/**
* Copy Constructor
*/
EtchNativeArray(const EtchNativeArray& other);
/**
* Destructor for Etch Nativearray.
* Frees array if content_owned was set.
*/
virtual ~EtchNativeArray();
/**
* gets the EtchObject at index i in result
* returns ETCH_ERANGE, if out of bounds.
* returns ETCH_OK otherwise
*/
status_t get(Pos pos, T *result);
status_t get(Pos pos, T* data, capu::int32_t dataSize, capu::int32_t offset, capu::int32_t length, capu::int32_t *read = NULL);
/**
* gets the array stored at the given position
* returns ETCH_ERANGE, if out of bounds.
* returns ETCH_OK otherwise
*/
status_t get(Pos pos, capu::SmartPointer<EtchNativeArray> &subarray);
/**
* sets the EtchObject at index i in result
* if content_owned, old value will be freed.
* returns ETCH_ERANGE, if out of bounds.
* returns ETCH_OK otherwise
*/
status_t set(Pos pos, const T &data);
status_t set(Pos pos, const T* data, capu::int32_t dataSize, capu::int32_t offset, capu::int32_t length, capu::int32_t *written = NULL);
/**
* sets the array at the given position
* returns ETCH_ERANGE, if out of bounds.
* returns ETCH_OK otherwise
*/
status_t set(Pos pos, EtchNativeArray *subarray);
//status_t set(Pos pos, capu::int32_t length, T* data, capu::int32_t offset);
/**
* Returns the length of array
*/
capu::int32_t getLength();
/**
* Returns the dim of array
*/
capu::uint32_t getDim();
/**
* Creates a new nested array
* @pos of the neseted array
* @length length of the nested array
*/
status_t createArray(Pos pos, capu::int32_t length);
/**
* @see EtchNativeArrayBase
*/
status_t resize(capu::int32_t newSize);
private:
capu::SmartPointer<EtchArrayBase<T> > mData;
/**
* private constructor
* creates a new native array from an existing subarray
*/
EtchNativeArray(capu::SmartPointer<EtchArray<T> > array);
};
template<class T>
const EtchObjectType* EtchNativeArray<T>::TYPE() {
const static EtchObjectType TYPE(EOTID_NATIVE_ARRAY, EtchObjectType::getType<T>(), EtchObjectType::getTypeTrait<T>());
return &TYPE;
}
template<class T>
EtchNativeArray<T>::EtchNativeArray(capu::int32_t length, capu::int32_t dim) {
addObjectType(EtchNativeArray<T>::TYPE());
if (dim == 1) {
mData = new EtchArrayData<T>(length);
} else {
mData = new EtchArray<T>(length, dim);
}
}
template<class T>
EtchNativeArray<T>::EtchNativeArray(capu::int32_t length, capu::int32_t dim, T* array) {
addObjectType(EtchNativeArray<T>::TYPE());
capu::int32_t bytesWritten;
if (dim == 1) {
mData = new EtchArrayData<T>(length);
mData->set(0, 0, array, length, 0, length, &bytesWritten);
} else if (dim == 2) {
mData = new EtchArray<T>(length, dim);
capu::int32_t offset = 0;
for (capu::int32_t i = 0; i < length; i++) {
mData->createArray(i, 0, 2,dim-1);
mData->set(i, 0, &array[offset], length, 0, length, &bytesWritten);
offset += length;
}
} else if (dim >= 3 || dim <= 9) {
//the construction of EtchNativeArrays of more than 2 dimensions is not supported
}
}
template<class T>
EtchNativeArray<T>::EtchNativeArray(capu::SmartPointer<EtchArray<T> > array) {
addObjectType(EtchNativeArray<T>::TYPE());
mData = capu::smartpointer_cast<EtchArrayBase<T> > (array);
}
template<class T>
EtchNativeArray<T>::EtchNativeArray(const EtchNativeArray& other)
: EtchNativeArrayBase(other), mData(other.mData) {
}
template<class T>
EtchNativeArray<T>::~EtchNativeArray() {
}
template<class T>
status_t EtchNativeArray<T>::get(Pos pos, T *result) {
return mData->get(pos, 0, result);
}
template<class T>
status_t EtchNativeArray<T>::get(Pos pos, T* data, capu::int32_t dataSize, capu::int32_t offset, capu::int32_t length, capu::int32_t *read) {
return mData->get(pos, 0, data, dataSize, offset, length, read);
}
template <class T>
status_t EtchNativeArray<T>::get(Pos pos, capu::SmartPointer<EtchNativeArray<T> > &subarray) {
capu::SmartPointer<EtchArray<T> > temp = NULL;
status_t res = mData->get(pos, 0, &temp);
if (res != ETCH_OK) {
return res;
}
subarray = new EtchNativeArray(temp);
return ETCH_OK;
}
template<class T>
status_t EtchNativeArray<T>::set(Pos pos, const T &data) {
return mData->set(pos, 0, data);
}
template<class T>
status_t EtchNativeArray<T>::set(Pos pos, const T* data, capu::int32_t dataSize, capu::int32_t offset, capu::int32_t length, capu::int32_t *written) {
return mData->set(pos, 0, data, dataSize, offset, length, written);
}
template<class T>
status_t EtchNativeArray<T>::set(Pos pos, EtchNativeArray<T> *subarray) {
if (subarray == NULL) {
return ETCH_ERANGE;
}
capu::SmartPointer<EtchArray<T> > temp = capu::smartpointer_cast<EtchArray<T> >(subarray->mData);
return mData->set(pos, 0, temp);
}
template<class T>
capu::int32_t EtchNativeArray<T>::getLength() {
return mData->getLength();
}
template<class T>
capu::uint32_t EtchNativeArray<T>::getDim() {
return mData->getDim();
}
template<class T>
status_t EtchNativeArray<T>::createArray(Pos pos, capu::int32_t length) {
return mData->createArray(pos, 0, length, mData->getDim()-1);
}
template<class T>
status_t EtchNativeArray<T>::resize(capu::int32_t newSize) {
return mData->resize(newSize);
}
//getBaseMacro used in NativeArrayBase::getBase()
#define GETBASE_CAST_OBJECT_TO_NA(type) { \
switch(trait) { \
case EtchObjectType::VALUE: { \
EtchNativeArray<type>* na = (EtchNativeArray<type>*)(this); \
if(dims == 1) { \
type value; \
ret = na->get(pos, &value); \
if (ret == ETCH_OK) { \
result = new type(value); \
} \
} else { \
capu::SmartPointer<EtchNativeArray<type> > subarray; \
ret = na->get(pos,subarray); \
if (ret == ETCH_OK) { \
result = subarray; \
} \
} \
break; \
} \
case EtchObjectType::POINTER: { \
EtchNativeArray<type*>* na = (EtchNativeArray<type*>*)(this); \
if(dims == 1) { \
type* value = NULL; \
ret = na->get(pos, &value); \
if(ret == ETCH_OK && value != NULL) { \
result = new type(*value); \
} \
} else { \
capu::SmartPointer<EtchNativeArray<type*> > subarray; \
ret = na->get(pos,subarray); \
if (ret == ETCH_OK) { \
result = subarray; \
} \
} \
break; \
} \
case EtchObjectType::SMART_POINTER: { \
EtchNativeArray<capu::SmartPointer<type> >* na = (EtchNativeArray<capu::SmartPointer<type> >*)(this); \
if(dims == 1) { \
capu::SmartPointer<type> value = NULL; \
ret = na->get(pos, &value); \
if (ret == ETCH_OK) { \
result = value; \
} \
} else { \
capu::SmartPointer<EtchNativeArray<capu::SmartPointer<type> > > subarray; \
ret = na->get(pos,subarray); \
if (ret == ETCH_OK) { \
result = subarray; \
} \
} \
break; \
} \
default: { \
return ETCH_ERROR; \
} \
} \
}
//setBaseMacro used in NativeArrayBase::setBase()
#define SETBASE_CAST_OBJECT_TO_NA(type) { \
switch(trait) { \
case EtchObjectType::VALUE: { \
EtchNativeArray<type>* na = (EtchNativeArray<type>*)(this); \
if(dims == 1) { \
capu::SmartPointer<type> value = capu::smartpointer_cast<type> (data); \
type *newValue = value.get(); \
if (newValue != NULL) { \
return na->set(pos, *newValue); \
} \
} else { \
capu::SmartPointer<EtchNativeArray<type> > subarray = capu::smartpointer_cast<EtchNativeArray<type> >(data); \
return na->set(pos,subarray.get()); \
} \
break; \
} \
case EtchObjectType::POINTER: { \
EtchNativeArray<type*>* na = (EtchNativeArray<type*>*)(this); \
if(dims == 1) { \
capu::SmartPointer<type> value = capu::smartpointer_cast<type> (data); \
type *newValue = value.get(); \
return na->set(pos, newValue); \
} else { \
capu::SmartPointer<EtchNativeArray<type*> > subarray = capu::smartpointer_cast<EtchNativeArray<type*> >(data); \
return na->set(pos,subarray.get()); \
} \
break; \
} \
case EtchObjectType::SMART_POINTER: { \
EtchNativeArray<capu::SmartPointer<type> >* na = (EtchNativeArray<capu::SmartPointer<type> >*)(this); \
if(dims == 1) { \
capu::SmartPointer<type> value = capu::smartpointer_cast<type> (data); \
return na->set(pos, value); \
} else { \
capu::SmartPointer<EtchNativeArray<capu::SmartPointer<type> > > subarray = capu::smartpointer_cast<EtchNativeArray<capu::SmartPointer<type> > >(data); \
return na->set(pos,subarray.get()); \
} \
break; \
} \
default: { \
break; \
} \
} \
break; \
}
typedef capu::SmartPointer<EtchNativeArray<EtchObjectPtr> > EtchNativeArrayObjectPtr;
typedef capu::SmartPointer<EtchNativeArray<EtchBoolPtr> > EtchNativeArrayBoolPtr;
typedef capu::SmartPointer<EtchNativeArray<EtchShortPtr> > EtchNativeArrayShortPtr;
typedef capu::SmartPointer<EtchNativeArray<capu::int8_t> > EtchNativeArrayBytePtr;
typedef capu::SmartPointer<EtchNativeArray<EtchInt32Ptr> > EtchNativeArrayIntPtr;
typedef capu::SmartPointer<EtchNativeArray<EtchLongPtr> > EtchNativeArrayLongPtr;
typedef capu::SmartPointer<EtchNativeArray<EtchFloatPtr> > EtchNativeArrayFloatPtr;
typedef capu::SmartPointer<EtchNativeArray<EtchDoublePtr> > EtchNativeArrayDoublePtr;
typedef capu::SmartPointer<EtchNativeArray<EtchStringPtr> > EtchNativeArrayStringPtr;
typedef capu::SmartPointer<EtchNativeArray<EtchHashSetPtr> > EtchNativeArrayHashSetPtr;
typedef capu::SmartPointer<EtchNativeArray<EtchListPtr> > EtchNativeArrayListPtr;
typedef capu::SmartPointer<EtchNativeArray<EtchHashTablePtr> > EtchNativeArrayHashTablePtr;
#endif //__ETCHNATIVEARRAY_H__