forked from jeog/TOSDataBridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_stream.tpp
714 lines (592 loc) · 22.6 KB
/
data_stream.tpp
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
#include "data_stream.hpp"
DATASTREAM_INTERFACE_TEMPLATE
template<typename InTy, typename OutTy>
size_t
DATASTREAM_INTERFACE_CLASS::_copy(OutTy* dest,
size_t sz,
int end,
int beg,
typename DATASTREAM_INTERFACE_CLASS::secondary_ty* sec) const
{
size_t ret;
if(!dest)
throw DataStreamInvalidArgument("NULL dest argument");
std::unique_ptr<InTy,void(*)(InTy*)>
tmp( new InTy[sz], [](InTy* p){ delete[] p; } );
ret = this->copy(tmp.get(), sz, end, beg, sec);
for(size_t i = 0; i < sz; ++i)
dest[i] = (OutTy)tmp.get()[i];
return ret;
}
DATASTREAM_INTERFACE_TEMPLATE
template<typename InTy, typename OutTy>
long long
DATASTREAM_INTERFACE_CLASS::_copy_using_atomic_marker(OutTy* dest,
size_t sz,
int beg,
typename DATASTREAM_INTERFACE_CLASS::secondary_ty* sec) const
{
long long ret;
if(!dest)
throw DataStreamInvalidArgument("NULL dest argument");
std::unique_ptr<InTy,void(*)(InTy*)>
tmp( new InTy[sz], [](InTy* p){ delete[] p; } );
ret = this->copy_from_marker(tmp.get(), sz, beg, sec);
for(size_t i = 0; i < sz; ++i)
dest[i] = (OutTy)tmp.get()[i];
return ret;
}
DATASTREAM_INTERFACE_TEMPLATE
size_t
DATASTREAM_INTERFACE_CLASS::copy(char** dest,
size_t dest_sz,
size_t str_sz,
int end = -1,
int beg = 0 ,
typename DATASTREAM_INTERFACE_CLASS::secondary_ty* sec = nullptr) const
{
BuildThrowTypeError<std::string*,false>("copy()");
return 0;
}
DATASTREAM_INTERFACE_TEMPLATE
size_t
DATASTREAM_INTERFACE_CLASS::copy(std::string* dest,
size_t sz,
int end = -1,
int beg = 0,
typename DATASTREAM_INTERFACE_CLASS::secondary_ty* sec = nullptr) const
{
size_t ret;
if(!dest)
throw DataStreamInvalidArgument("NULL dest argument");
auto dstr = [sz](char** p){ DeleteStrings(p, sz); };
std::unique_ptr<char*,decltype(dstr)> sptr(NewStrings(sz,STR_DATA_SZ), dstr);
ret = this->copy(sptr.get(), sz, STR_DATA_SZ , end, beg, sec);
std::copy_n(sptr.get(), sz, dest);
return ret;
}
DATASTREAM_INTERFACE_TEMPLATE
long long
DATASTREAM_INTERFACE_CLASS::copy_from_marker(char** dest,
size_t dest_sz,
size_t str_sz,
int beg = 0,
typename DATASTREAM_INTERFACE_CLASS::secondary_ty* sec = nullptr) const
{
BuildThrowTypeError<std::string*,false>("copy_from_marker()");
return 0;
}
DATASTREAM_INTERFACE_TEMPLATE
long long
DATASTREAM_INTERFACE_CLASS::copy_from_marker(std::string* dest,
size_t sz,
int beg = 0,
typename DATASTREAM_INTERFACE_CLASS::secondary_ty* sec = nullptr) const
{
long long ret;
if(!dest)
throw DataStreamInvalidArgument("NULL dest argument");
auto dstr = [sz](char** pptr){ DeleteStrings(pptr, sz); };
std::unique_ptr<char*,decltype(dstr)>
sptr( NewStrings(sz,STR_DATA_SZ), dstr );
ret = this->copy_from_marker(sptr.get(), sz, STR_DATA_SZ, beg, sec);
std::copy_n(sptr.get(), sz, dest);
return ret;
}
DATASTREAM_PRIMARY_TEMPLATE
void
DATASTREAM_PRIMARY_CLASS::_push(const Ty _item)
{ /*
* if can't obtain lock indicate other threads should yield to us
*/
this->_push_has_priority = this->_mtx->try_lock(); /*O.K. push/pop doesn't throw*/
if( !(this->_push_has_priority) )
this->_mtx->lock(); /* block regardless */
/* --- CRITICAL SECTION --- */
this->_my_impl_obj.push_front(_item);
this->_my_impl_obj.pop_back();
this->_incr_internal_counts();
/* --- CRITICAL SECTION --- */
this->_mtx->unlock();
}
DATASTREAM_PRIMARY_TEMPLATE
template<typename T>
bool
DATASTREAM_PRIMARY_CLASS::_check_adj(int& end,
int& beg,
const std::deque<T,Allocator>& impl) const
{
int sz = (int)impl.size(); /* O.K. sz can't be > INT_MAX */
if (this->_q_bound != sz)
throw DataStreamSizeViolation("internal size/bounds violation", this->_q_bound, sz);
if (end < 0)
end += sz;
if (beg < 0)
beg += sz;
if (beg >= sz || end >= sz || beg < 0 || end < 0)
throw DataStreamOutOfRange("adj index value out of range", sz, beg, end);
else if (beg > end)
throw DataStreamInvalidArgument("adjusted beging index > end index");
return true;
}
DATASTREAM_PRIMARY_TEMPLATE
void
DATASTREAM_PRIMARY_CLASS::_incr_internal_counts()
{
long long penult = (long long)(this->_q_bound) -1;
if(this->_q_count < this->_q_bound)
++(this->_q_count);
if(*(this->_mark_count) == penult)
*(this->_mark_is_dirty) = true;
else if(*(this->_mark_count) < penult)
++(*(this->_mark_count));
else{/*
* WE CANT THROW so attempt to get _mark_count back in line;
* also set dirty flag to alert caller of possible data issue
*/
--(*(this->_mark_count));
*(this->_mark_is_dirty) = true;
}
}
DATASTREAM_PRIMARY_TEMPLATE
template<typename ImplTy, typename DestTy>
size_t
DATASTREAM_PRIMARY_CLASS::_copy_to_ptr(ImplTy& impl,
DestTy* dest,
size_t sz,
unsigned int end,
unsigned int beg) const
{
ImplTy::const_iterator b_iter = impl.cbegin() + beg;
ImplTy::const_iterator e_iter =
impl.cbegin() +
std::min<size_t>(sz+beg, std::min<size_t>(++end, this->_q_count));
return (b_iter < e_iter) ? (std::copy(b_iter, e_iter, dest) - dest) : 0;
}
DATASTREAM_PRIMARY_TEMPLATE
DATASTREAM_PRIMARY_CLASS::DataStream(size_t sz)
:
_my_impl_obj(std::max<size_t>(std::min<size_t>(sz,MAX_BOUND_SIZE),1)),
_q_bound(std::max<size_t>(std::min<size_t>(sz,MAX_BOUND_SIZE),1)),
_q_count(0),
_mark_count(new long long(-1)),
_mark_is_dirty(new bool(false)),
_push_has_priority(true),
_mtx(new std::recursive_mutex)
{
}
DATASTREAM_PRIMARY_TEMPLATE
DATASTREAM_PRIMARY_CLASS::DataStream(const typename DATASTREAM_PRIMARY_CLASS::_my_ty & stream)
:
_my_impl_obj(stream._my_impl_obj),
_q_bound(stream._q_bound),
_q_count(stream._q_count),
_mark_count(new long long(*(stream._mark_count))),
_mark_is_dirty(new bool(*(stream._mark_is_dirty))),
_push_has_priority(true),
_mtx(new std::recursive_mutex)
{
}
DATASTREAM_PRIMARY_TEMPLATE
DATASTREAM_PRIMARY_CLASS::DataStream(typename DATASTREAM_PRIMARY_CLASS::_my_ty && stream)
:
_my_impl_obj(std::move(stream._my_impl_obj)),
_q_bound(stream._q_bound),
_q_count(stream._q_count),
_mark_count(stream._mark_count),
_mark_is_dirty(stream._mark_is_dirty),
_push_has_priority(true),
_mtx(stream._mtx) // ??
{
stream._mark_count = nullptr;
stream._mark_is_dirty = nullptr;
stream._mtx = nullptr;
}
DATASTREAM_PRIMARY_TEMPLATE
DATASTREAM_PRIMARY_CLASS::~DataStream()
{
if(this->_mtx)
delete this->_mtx;
if(this->_mark_count)
delete this->_mark_count;
if(this->_mark_is_dirty)
delete this->_mark_is_dirty;
}
DATASTREAM_PRIMARY_TEMPLATE
size_t
DATASTREAM_PRIMARY_CLASS::bound_size(size_t sz)
{
sz = std::max<size_t>(std::min<size_t>(sz,MAX_BOUND_SIZE),1);
_my_lock_guard_type lock(*(this->_mtx));
/* --- CRITICAL SECTION --- */
this->_my_impl_obj.resize(sz);
if(sz < this->_q_bound){
/* IF bound is 'clipped' from the left(end) */
this->_my_impl_obj.shrink_to_fit();
if( (long long)sz <= *(this->_mark_count) ){
/* IF marker is 'clipped' from the left(end) */
*(this->_mark_count) = (long long)sz -1;
*(this->_mark_is_dirty) = true;
}
}
this->_q_bound = sz;
if(sz < this->_q_count) /* IF count is 'clipped' from the left(end) */
this->_q_count = sz;
return this->_q_bound;
/* --- CRITICAL SECTION --- */
}
DATASTREAM_PRIMARY_TEMPLATE
long long
DATASTREAM_PRIMARY_CLASS::copy_from_marker(Ty* dest,
size_t sz,
int beg = 0,
typename DATASTREAM_PRIMARY_CLASS::secondary_ty* sec = nullptr) const
{ /*
* 1) we need to cache mark vals before copy changes state
* 2) adjust beg here; _check_adj requires a ref that we can't pass
* 3) casts to long long O.K as long as MAX_BOUND_SIZE == INT_MAX
*/
long long copy_sz, req_sz;
this->_yld_to_push();
_my_lock_guard_type lock(*(this->_mtx));
/* --- CRITICAL SECTION --- */
bool was_dirty = *(this->_mark_is_dirty);
if(beg < 0)
beg += (int)size();
req_sz = *(this->_mark_count) - (long long)beg + 1;
if(beg < 0 || req_sz < 1)
/*
* if beg is still invalid or > marker ... CALLER'S PROBLEM
* req_sz needs to account for inclusive range by adding 1
*/
return 0;
/* CAREFUL: we cant have a negative *_mark_count past this point */
copy_sz = (long long)(this->copy(dest, sz, (int)(*(this->_mark_count)), beg, sec));
if(was_dirty || copy_sz < req_sz)
/*
* IF mark is dirty (i.e hits back of stream) or we
* don't copy enough(sz is too small) return negative size
*/
copy_sz *= -1;
return copy_sz;
/* --- CRITICAL SECTION --- */
}
DATASTREAM_PRIMARY_TEMPLATE
long long
DATASTREAM_PRIMARY_CLASS::copy_from_marker(char** dest,
size_t dest_sz,
size_t str_sz,
int beg = 0,
typename DATASTREAM_PRIMARY_CLASS::secondary_ty* sec = nullptr) const
{ /*
* 1) we need to cache mark vals before copy changes state
* 2) adjust beg here; _check_adj requires a ref that we can't pass
* 3) casts to long long O.K as long as MAX_BOUND_SIZE == INT_MAX
*/
long long copy_sz, req_sz;
this->_yld_to_push();
_my_lock_guard_type lock(*(this->_mtx));
/* --- CRITICAL SECTION --- */
bool was_dirty = *(this->_mark_is_dirty);
if(beg < 0)
beg += (int)size();
req_sz = *(this->_mark_count) - (long long)beg + 1;
if(beg < 0 || req_sz < 1)
/*
* if beg is still invalid or > marker ... CALLER'S PROBLEM
* req_sz needs to account for inclusive range by adding 1
*/
return 0;
/* CAREFUL: we cant have a negative *_mark_count past this point */
copy_sz = (long long)(this->copy(dest, dest_sz, str_sz, (int)(*(this->_mark_count)), beg, sec));
if(was_dirty || copy_sz < req_sz)
/*
* IF mark is dirty (i.e hits back of stream) or we
* don't copy enough(sz is too small) return negative size
*/
copy_sz *= -1;
return copy_sz;
/* --- CRITICAL SECTION --- */
}
DATASTREAM_PRIMARY_TEMPLATE
size_t
DATASTREAM_PRIMARY_CLASS::copy(Ty* dest,
size_t sz,
int end = -1,
int beg = 0,
typename DATASTREAM_PRIMARY_CLASS::secondary_ty* sec = nullptr) const
{
size_t ret;
static_assert(!std::is_same<Ty,char>::value, "copy doesn't accept char*");
if(!dest)
throw DataStreamInvalidArgument("NULL dest argument");
this->_yld_to_push();
_my_lock_guard_type lock(*(this->_mtx));
/* --- CRITICAL SECTION --- */
this->_check_adj(end, beg, this->_my_impl_obj);
if(end == beg){
*dest = beg ? this->_my_impl_obj.at(beg) : this->_my_impl_obj.front();
ret = 1;
}else
ret = this->_copy_to_ptr(this->_my_impl_obj,dest,sz,end,beg);
*(this->_mark_count) = beg - 1;
*(this->_mark_is_dirty) = false;
return ret;
/* --- CRITICAL SECTION --- */
}
DATASTREAM_PRIMARY_TEMPLATE
size_t
DATASTREAM_PRIMARY_CLASS::copy(char** dest,
size_t dest_sz,
size_t str_sz,
int end = -1,
int beg = 0,
typename DATASTREAM_PRIMARY_CLASS::secondary_ty* sec = nullptr) const
{ /*
* slow(er), has to go thru generic_ty to get strings
* note: if sz <= genS.length() the string is truncated
*/
_my_impl_ty::const_iterator b_iter, e_iter;
size_t i;
if(!dest)
throw DataStreamInvalidArgument("NULL dest argument");
this->_yld_to_push();
_my_lock_guard_type lock(*(this->_mtx));
/* --- CRITICAL SECTION --- */
this->_check_adj(end, beg, this->_my_impl_obj);
b_iter = this->_my_impl_obj.cbegin() + beg;
e_iter = this->_my_impl_obj.cbegin()
+ std::min< size_t >(++end, this->_q_count);
for(i = 0; (i < dest_sz) && (b_iter < e_iter); ++b_iter, ++i)
{
std::string genS = generic_ty(*b_iter).as_string();
strncpy_s(dest[i], str_sz, genS.c_str(),
std::min<size_t>(str_sz-1, genS.length()));
}
*(this->_mark_count) = beg - 1;
*(this->_mark_is_dirty) = false;
return i;
/* --- CRITICAL SECTION --- */
}
DATASTREAM_PRIMARY_TEMPLATE
typename DATASTREAM_PRIMARY_CLASS::generic_ty
DATASTREAM_PRIMARY_CLASS::operator[](int indx) const
{
int dummy = 0;
_my_lock_guard_type lock(*(this->_mtx));
/* --- CRITICAL SECTION --- */
if (!indx){
/* optimize for indx == 0 */
*(this->_mark_count) = -1;
*(this->_mark_is_dirty) = false;
return generic_ty(this->_my_impl_obj.front());
}
this->_check_adj(indx, dummy, this->_my_impl_obj);
*(this->_mark_count) = indx - 1;
*(this->_mark_is_dirty) = false;
return generic_ty(this->_my_impl_obj.at(indx));
/* --- CRITICAL SECTION --- */
}
DATASTREAM_PRIMARY_TEMPLATE
typename DATASTREAM_PRIMARY_CLASS::both_ty
DATASTREAM_PRIMARY_CLASS::both(int indx) const
{
_my_lock_guard_type lock(*(this->_mtx));
/* --- CRITICAL SECTION --- */
return both_ty(operator[](indx), secondary_ty());
/* --- CRITICAL SECTION --- */
}
DATASTREAM_PRIMARY_TEMPLATE
typename DATASTREAM_PRIMARY_CLASS::generic_vector_ty
DATASTREAM_PRIMARY_CLASS::vector(int end = -1, int beg = 0) const
{
_my_impl_ty::const_iterator b_iter, e_iter;
generic_vector_ty tmp;
this->_yld_to_push();
_my_lock_guard_type lock(*(this->_mtx));
/* --- CRITICAL SECTION --- */
this->_check_adj(end, beg, this->_my_impl_obj);
b_iter = this->_my_impl_obj.cbegin() + beg;
e_iter = this->_my_impl_obj.cbegin()
+ std::min< size_t >(++end, this->_q_count);
if(b_iter < e_iter){
std::transform(b_iter, e_iter,
/* have to use slower insert_iterator approach,
generic_ty doesn't allow default construction */
std::insert_iterator< generic_vector_ty >(tmp, tmp.begin()),
[](Ty x){ return generic_ty(x); });
}
*(this->_mark_count) = beg - 1;
*(this->_mark_is_dirty) = false;
return tmp;
/* --- CRITICAL SECTION --- */
}
DATASTREAM_PRIMARY_TEMPLATE
typename DATASTREAM_PRIMARY_CLASS::secondary_vector_ty
DATASTREAM_PRIMARY_CLASS::secondary_vector(int end = -1, int beg = 0) const
{
this->_check_adj(end, beg, this->_my_impl_obj);
return secondary_vector_ty(std::min< size_t >(++end - beg, this->_q_count));
}
DATASTREAM_SECONDARY_TEMPLATE
void
DATASTREAM_SECONDARY_CLASS::_push(const Ty _item,
const typename DATASTREAM_SECONDARY_CLASS::secondary_ty sec)
{
this->_push_has_priority = this->_mtx->try_lock();
if( !(this->_push_has_priority) )
this->_mtx->lock();
/* --- CRITICAL SECTION --- */
_my_base_ty::_my_impl_obj.push_front(_item);
_my_base_ty::_my_impl_obj.pop_back();
this->_my_sec_impl_obj.push_front(std::move(sec));
this->_my_sec_impl_obj.pop_back();
this->_incr_internal_counts();
/* --- CRITICAL SECTION --- */
this->_mtx->unlock();
}
DATASTREAM_SECONDARY_TEMPLATE
DATASTREAM_SECONDARY_CLASS::DataStream(size_t sz)
:
_my_sec_impl_obj(std::max<size_t>(std::min<size_t>(sz,MAX_BOUND_SIZE),1)),
_my_base_ty(std::max<size_t>(std::min<size_t>(sz,MAX_BOUND_SIZE),1))
{
}
DATASTREAM_SECONDARY_TEMPLATE
DATASTREAM_SECONDARY_CLASS::DataStream(const typename DATASTREAM_SECONDARY_CLASS::_my_ty & stream)
:
_my_sec_impl_obj(stream._my_sec_impl_obj),
_my_base_ty(stream)
{
}
DATASTREAM_SECONDARY_TEMPLATE
DATASTREAM_SECONDARY_CLASS::DataStream(typename DATASTREAM_SECONDARY_CLASS::_my_ty && stream)
:
_my_sec_impl_obj(std::move(stream._my_sec_impl_obj)),
_my_base_ty(std::move(stream))
{
}
DATASTREAM_SECONDARY_TEMPLATE
size_t
DATASTREAM_SECONDARY_CLASS::bound_size(size_t sz)
{
sz = std::max<size_t>(std::min<size_t>(sz,MAX_BOUND_SIZE),1);
_my_lock_guard_type lock(*(this->_mtx));
/* --- CRITICAL SECTION --- */
this->_my_sec_impl_obj.resize(sz);
if (sz < this->_q_count)
this->_my_sec_impl_obj.shrink_to_fit();
return _my_base_ty::bound_size(sz);
/* --- CRITICAL SECTION --- */
}
DATASTREAM_SECONDARY_TEMPLATE
size_t
DATASTREAM_SECONDARY_CLASS::copy(Ty* dest,
size_t sz,
int end = -1,
int beg = 0,
typename DATASTREAM_SECONDARY_CLASS::secondary_ty* sec = nullptr) const
{
size_t ret;
if(!dest)
throw DataStreamInvalidArgument("NULL dest argument");
_my_lock_guard_type lock(*(this->_mtx));
/* --- CRITICAL SECTION --- */
ret = _my_base_ty::copy(dest, sz, end, beg); /*_mark_count reset by _my_base_ty*/
if(!sec)
return ret;
this->_check_adj(end, beg, this->_my_sec_impl_obj); /*repeat to update index vals */
if(end == beg){
*sec = beg ? this->_my_sec_impl_obj.at(beg)
: this->_my_sec_impl_obj.front();
ret = 1;
}else
ret = this->_copy_to_ptr(this->_my_sec_impl_obj, sec, sz, end, beg);
/* check ret vs. the return value of _my_base_ty::copy for consistency ? */
return ret;
/* --- CRITICAL SECTION --- */
}
DATASTREAM_SECONDARY_TEMPLATE
size_t
DATASTREAM_SECONDARY_CLASS::copy(char** dest,
size_t dest_sz,
size_t str_sz,
int end = -1,
int beg = 0,
typename DATASTREAM_SECONDARY_CLASS::secondary_ty* sec = nullptr) const
{
size_t ret;
if(!dest)
throw DataStreamInvalidArgument("NULL dest argument");
_my_lock_guard_type lock(*(this->_mtx));
/* --- CRITICAL SECTION --- */
ret = _my_base_ty::copy(dest, dest_sz, str_sz, end, beg);
if(!sec)
return ret;
this->_check_adj(end, beg, this->_my_sec_impl_obj); /*repeat to update index vals*/
if(end == beg){
*sec = beg ? this->_my_sec_impl_obj.at(beg)
: this->_my_sec_impl_obj.front();
ret = 1;
}else
ret = this->_copy_to_ptr(this->_my_sec_impl_obj, sec, dest_sz, end, beg);
/* check ret vs. the return value of _my_base_ty::copy for consistency ? */
/* --- CRITICAL SECTION --- */
return ret;
}
DATASTREAM_SECONDARY_TEMPLATE
typename DATASTREAM_SECONDARY_CLASS::both_ty
DATASTREAM_SECONDARY_CLASS::both(int indx) const
{
int dummy = 0;
_my_lock_guard_type lock(*(this->_mtx));
/* --- CRITICAL SECTION --- */
generic_ty gen = this->operator[](indx); /* _mark_count reset by _my_base_ty */
if(!indx)
return both_ty(gen, this->_my_sec_impl_obj.front());
this->_check_adj(indx, dummy, this->_my_sec_impl_obj);
return both_ty(gen, this->_my_sec_impl_obj.at(indx));
/* --- CRITICAL SECTION --- */
}
DATASTREAM_SECONDARY_TEMPLATE
void
DATASTREAM_SECONDARY_CLASS::secondary(typename DATASTREAM_SECONDARY_CLASS::secondary_ty* dest,
int indx) const
{
int dummy = 0;
_my_lock_guard_type lock(*(this->_mtx));
/* --- CRITICAL SECTION --- */
this->_check_adj(indx, dummy, this->_my_sec_impl_obj);
if(!indx)
*dest = this->_my_sec_impl_obj.front();
else
*dest = this->_my_sec_impl_obj.at(indx);
*(this->_mark_count) = indx - 1; /* _mark_count NOT reset by _my_base_ty */
*(this->_mark_is_dirty) = false;
/* --- CRITICAL SECTION --- */
}
DATASTREAM_SECONDARY_TEMPLATE
typename DATASTREAM_SECONDARY_CLASS::secondary_vector_ty
DATASTREAM_SECONDARY_CLASS::secondary_vector(int end = -1, int beg = 0) const
{
_my_sec_impl_ty::const_iterator b_iter, e_iter;
_my_sec_impl_ty::const_iterator::difference_type ndiff;
secondary_vector_ty tmp;
this->_yld_to_push();
_my_lock_guard_type lock(*(this->_mtx));
/* --- CRITICAL SECTION --- */
this->_check_adj(end, beg, this->_my_sec_impl_obj);
b_iter = this->_my_sec_impl_obj.cbegin() + beg;
e_iter = this->_my_sec_impl_obj.cbegin()
+ std::min< size_t >(++end, this->_q_count);
ndiff = e_iter - b_iter;
if(ndiff > 0){
/* do this manually; insert iterators too slow */
tmp.resize(ndiff);
std::copy(b_iter, e_iter, tmp.begin());
}
*(this->_mark_count) = beg - 1; /* _mark_count NOT reset by _my_base_ty */
*(this->_mark_is_dirty) = false;
return tmp;
/* --- CRITICAL SECTION --- */
}