File: vvp_darray.cc

package info (click to toggle)
iverilog 12.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 30,148 kB
  • sloc: cpp: 109,972; ansic: 62,713; yacc: 10,216; sh: 3,470; vhdl: 3,246; perl: 1,814; makefile: 1,774; python: 78; csh: 2
file content (890 lines) | stat: -rw-r--r-- 25,768 bytes parent folder | download | duplicates (2)
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
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
/*
 * Copyright (c) 2012-2020 Stephen Williams (steve@icarus.com)
 *
 *    This source code is free software; you can redistribute it
 *    and/or modify it in source code form under the terms of the GNU
 *    General Public License as published by the Free Software
 *    Foundation; either version 2 of the License, or (at your option)
 *    any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

# include  "vvp_darray.h"
# include  <iostream>
# include  <typeinfo>

using namespace std;

vvp_darray::~vvp_darray()
{
}

void vvp_darray::set_word(unsigned, const vvp_vector4_t&)
{
      cerr << "XXXX set_word(vvp_vector4_t) not implemented for " << typeid(*this).name() << endl;
}

void vvp_darray::set_word(unsigned, double)
{
      cerr << "XXXX set_word(double) not implemented for " << typeid(*this).name() << endl;
}

void vvp_darray::set_word(unsigned, const string&)
{
      cerr << "XXXX set_word(string) not implemented for " << typeid(*this).name() << endl;
}

void vvp_darray::set_word(unsigned, const vvp_object_t&)
{
      cerr << "XXXX set_word(vvp_object_t) not implemented for " << typeid(*this).name() << endl;
}

void vvp_darray::get_word(unsigned, vvp_vector4_t&)
{
      cerr << "XXXX get_word(vvp_vector4_t) not implemented for " << typeid(*this).name() << endl;
}

void vvp_darray::get_word(unsigned, double&)
{
      cerr << "XXXX get_word(double) not implemented for " << typeid(*this).name() << endl;
}

void vvp_darray::get_word(unsigned, string&)
{
      cerr << "XXXX get_word(string) not implemented for " << typeid(*this).name() << endl;
}

void vvp_darray::get_word(unsigned, vvp_object_t&)
{
      cerr << "XXXX get_word(vvp_object_t) not implemented for " << typeid(*this).name() << endl;
}

vvp_vector4_t vvp_darray::get_bitstream(bool)
{
      cerr << "XXXX get_bitstream() not implemented for " << typeid(*this).name() << endl;
      return vvp_vector4_t();
}

template <class TYPE> vvp_darray_atom<TYPE>::~vvp_darray_atom()
{
}

template <class TYPE> size_t vvp_darray_atom<TYPE>::get_size() const
{
      return array_.size();
}

template <class TYPE> void vvp_darray_atom<TYPE>::set_word(unsigned adr, const vvp_vector4_t&value)
{
      if (adr >= array_.size())
	    return;
      TYPE tmp;
      vector4_to_value(value, tmp, true, false);
      array_[adr] = tmp;
}

template <class TYPE> void vvp_darray_atom<TYPE>::get_word(unsigned adr, vvp_vector4_t&value)
{
      if (adr >= array_.size()) {
	    value = vvp_vector4_t(8*sizeof(TYPE), BIT4_X);
	    return;
      }

      TYPE word = array_[adr];
      vvp_vector4_t tmp (8*sizeof(TYPE), BIT4_0);
      for (unsigned idx = 0 ; idx < tmp.size() ; idx += 1) {
	    if (word&1) tmp.set_bit(idx, BIT4_1);
	    word >>= 1;
      }
      value = tmp;
}

template <class TYPE> void vvp_darray_atom<TYPE>::shallow_copy(const vvp_object*obj)
{
      const vvp_darray_atom<TYPE>*that = dynamic_cast<const vvp_darray_atom<TYPE>*>(obj);
      assert(that);

      unsigned num_items = min(array_.size(), that->array_.size());
      for (unsigned idx = 0 ; idx < num_items ; idx += 1)
	    array_[idx] = that->array_[idx];
}

template <class TYPE> vvp_object* vvp_darray_atom<TYPE>::duplicate(void) const
{
      vvp_darray_atom<TYPE>*that = new vvp_darray_atom<TYPE>(array_.size());
      for (size_t idx = 0 ; idx < array_.size() ; idx += 1)
	    that->array_[idx] = array_[idx];

      return that;
}

template <class TYPE> vvp_vector4_t vvp_darray_atom<TYPE>::get_bitstream(bool)
{
      const unsigned word_wid = sizeof(TYPE) * 8;

      vvp_vector4_t vec(array_.size() * word_wid, BIT4_0);

      unsigned adx = 0;
      unsigned vdx = vec.size();
      while (vdx > 0) {
            TYPE word = array_[adx++];
            vdx -= word_wid;
            for (unsigned bdx = 0; bdx < word_wid; bdx += 1) {
                  if (word & 1)
                        vec.set_bit(vdx+bdx, BIT4_1);
                  word >>= 1;
            }
      }

      return vec;
}

template class vvp_darray_atom<uint8_t>;
template class vvp_darray_atom<uint16_t>;
template class vvp_darray_atom<uint32_t>;
template class vvp_darray_atom<uint64_t>;
template class vvp_darray_atom<int8_t>;
template class vvp_darray_atom<int16_t>;
template class vvp_darray_atom<int32_t>;
template class vvp_darray_atom<int64_t>;

vvp_darray_vec4::~vvp_darray_vec4()
{
}

size_t vvp_darray_vec4::get_size(void) const
{
      return array_.size();
}

void vvp_darray_vec4::set_word(unsigned adr, const vvp_vector4_t&value)
{
      if (adr >= array_.size()) return;
      assert(value.size() == word_wid_);
      array_[adr] = value;
}

void vvp_darray_vec4::get_word(unsigned adr, vvp_vector4_t&value)
{
	/*
	 * Return an undefined value for an out of range address or if the
	 * value has not been written yet (has a size of zero).
	 */
      if ((adr >= array_.size()) || (array_[adr].size() == 0)) {
	    value = vvp_vector4_t(word_wid_, BIT4_X);
	    return;
      }
      value = array_[adr];
      assert(value.size() == word_wid_);
}

void vvp_darray_vec4::shallow_copy(const vvp_object*obj)
{
      const vvp_darray_vec4*that = dynamic_cast<const vvp_darray_vec4*>(obj);
      assert(that);

      unsigned num_items = min(array_.size(), that->array_.size());
      for (unsigned idx = 0 ; idx < num_items ; idx += 1)
	    array_[idx] = that->array_[idx];
}

vvp_object* vvp_darray_vec4::duplicate(void) const
{
      vvp_darray_vec4*that = new vvp_darray_vec4(array_.size(), word_wid_);

      for (size_t idx = 0 ; idx < array_.size() ; idx += 1)
	    that->array_[idx] = array_[idx];

      return that;
}

vvp_vector4_t vvp_darray_vec4::get_bitstream(bool as_vec4)
{
      vvp_vector4_t vec(array_.size() * word_wid_, BIT4_0);

      unsigned adx = 0;
      unsigned vdx = vec.size();
      while (vdx > 0) {
            vdx -= word_wid_;
            for (unsigned bdx = 0; bdx < word_wid_; bdx += 1) {
                  vvp_bit4_t bit = array_[adx].value(bdx);
                  if (as_vec4 || (bit == BIT4_1))
                        vec.set_bit(vdx+bdx, bit);
            }
            adx++;
      }

      return vec;
}

vvp_darray_vec2::~vvp_darray_vec2()
{
}

size_t vvp_darray_vec2::get_size(void) const
{
      return array_.size();
}

void vvp_darray_vec2::set_word(unsigned adr, const vvp_vector4_t&value)
{
      if (adr >= array_.size()) return;
      assert(value.size() == word_wid_);
      array_[adr] = value;
}

void vvp_darray_vec2::get_word(unsigned adr, vvp_vector4_t&value)
{
	/*
	 * Return a zero value for an out of range address or if the
	 * value has not been written yet (has a size of zero).
	 */
      if ((adr >= array_.size()) || (array_[adr].size() == 0)) {
	    value = vvp_vector4_t(word_wid_, BIT4_0);
	    return;
      }
      assert(array_[adr].size() == word_wid_);
      value.resize(word_wid_);
      for (unsigned idx = 0; idx < word_wid_; idx += 1) {
	    value.set_bit(idx, array_[adr].value4(idx));
      }
}

void vvp_darray_vec2::shallow_copy(const vvp_object*obj)
{
      const vvp_darray_vec2*that = dynamic_cast<const vvp_darray_vec2*>(obj);
      assert(that);

      unsigned num_items = min(array_.size(), that->array_.size());
      for (unsigned idx = 0 ; idx < num_items ; idx += 1)
	    array_[idx] = that->array_[idx];
}

vvp_vector4_t vvp_darray_vec2::get_bitstream(bool)
{
      vvp_vector4_t vec(array_.size() * word_wid_, BIT4_0);

      unsigned adx = 0;
      unsigned vdx = vec.size();
      while (vdx > 0) {
            vdx -= word_wid_;
            for (unsigned bdx = 0; bdx < word_wid_; bdx += 1) {
                  if (array_[adx].value(bdx))
                        vec.set_bit(vdx+bdx, BIT4_1);
            }
            adx++;
      }

      return vec;
}

vvp_darray_object::~vvp_darray_object()
{
}

size_t vvp_darray_object::get_size() const
{
      return array_.size();
}

void vvp_darray_object::set_word(unsigned adr, const vvp_object_t&value)
{
      if (adr >= array_.size())
	    return;
      array_[adr] = value;
}

void vvp_darray_object::get_word(unsigned adr, vvp_object_t&value)
{
      if (adr >= array_.size()) {
	    value = vvp_object_t();
	    return;
      }

      value = array_[adr];
}

void vvp_darray_object::shallow_copy(const vvp_object*obj)
{
      const vvp_darray_object*that = dynamic_cast<const vvp_darray_object*>(obj);
      assert(that);

      unsigned num_items = min(array_.size(), that->array_.size());
      for (unsigned idx = 0 ; idx < num_items ; idx += 1)
	    array_[idx] = that->array_[idx];
}

vvp_darray_real::~vvp_darray_real()
{
}

size_t vvp_darray_real::get_size() const
{
      return array_.size();
}

void vvp_darray_real::set_word(unsigned adr, double value)
{
      if (adr >= array_.size())
	    return;
      array_[adr] = value;
}

void vvp_darray_real::get_word(unsigned adr, double&value)
{
      if (adr >= array_.size()) {
	    value = 0.0;
	    return;
      }

      value = array_[adr];
}

void vvp_darray_real::shallow_copy(const vvp_object*obj)
{
      const vvp_darray_real*that = dynamic_cast<const vvp_darray_real*>(obj);
      assert(that);

      unsigned num_items = min(array_.size(), that->array_.size());
      for (unsigned idx = 0 ; idx < num_items ; idx += 1)
	    array_[idx] = that->array_[idx];
}

vvp_object* vvp_darray_real::duplicate(void) const
{
      vvp_darray_real*that = new vvp_darray_real(array_.size());

      for (size_t idx = 0 ; idx < array_.size() ; idx += 1)
	    that->array_[idx] = array_[idx];

      return that;
}

vvp_vector4_t vvp_darray_real::get_bitstream(bool)
{
      const unsigned word_wid = sizeof(double) * 8;
      assert(word_wid == 64);

      vvp_vector4_t vec(array_.size() * word_wid, BIT4_0);

      unsigned adx = 0;
      unsigned vdx = vec.size();
      while (vdx > 0) {
            union {
                double   value;
                uint64_t bits;
            } word;
            word.value = array_[adx++];
            vdx -= word_wid;
            for (unsigned bdx = 0; bdx < word_wid; bdx += 1) {
                  if (word.bits & 1)
                        vec.set_bit(vdx+bdx, BIT4_1);
                  word.bits >>= 1;
            }
      }

      return vec;
}

vvp_darray_string::~vvp_darray_string()
{
}

size_t vvp_darray_string::get_size() const
{
      return array_.size();
}

void vvp_darray_string::set_word(unsigned adr, const string&value)
{
      if (adr >= array_.size())
	    return;
      array_[adr] = value;
}

void vvp_darray_string::get_word(unsigned adr, string&value)
{
      if (adr >= array_.size()) {
	    value = "";
	    return;
      }

      value = array_[adr];
}

void vvp_darray_string::shallow_copy(const vvp_object*obj)
{
      const vvp_darray_string*that = dynamic_cast<const vvp_darray_string*>(obj);
      assert(that);

      unsigned num_items = min(array_.size(), that->array_.size());
      for (unsigned idx = 0 ; idx < num_items ; idx += 1)
	    array_[idx] = that->array_[idx];
}

vvp_object* vvp_darray_string::duplicate(void) const
{
      vvp_darray_string*that = new vvp_darray_string(array_.size());

      for (size_t idx = 0 ; idx < array_.size() ; idx += 1)
	    that->array_[idx] = array_[idx];

      return that;
}

vvp_queue::~vvp_queue()
{
}

void vvp_queue::copy_elems(vvp_object_t, unsigned)
{
      cerr << "Sorry: copy_elems() not implemented for " << typeid(*this).name() << endl;
}

void vvp_queue::set_word_max(unsigned, const vvp_vector4_t&, unsigned)
{
      cerr << "XXXX set_word_max(vvp_vector4_t) not implemented for " << typeid(*this).name() << endl;
}

void vvp_queue::insert(unsigned, const vvp_vector4_t&, unsigned)
{
      cerr << "XXXX insert(vvp_vector4_t) not implemented for " << typeid(*this).name() << endl;
}

void vvp_queue::push_back(const vvp_vector4_t&, unsigned)
{
      cerr << "XXXX push_back(vvp_vector4_t) not implemented for " << typeid(*this).name() << endl;
}

void vvp_queue::push_front(const vvp_vector4_t&, unsigned)
{
      cerr << "XXXX push_front(vvp_vector4_t) not implemented for " << typeid(*this).name() << endl;
}

void vvp_queue::set_word_max(unsigned, double, unsigned)
{
      cerr << "XXXX set_word_max(double) not implemented for " << typeid(*this).name() << endl;
}

void vvp_queue::insert(unsigned, double, unsigned)
{
      cerr << "XXXX set_word_max(double) not implemented for " << typeid(*this).name() << endl;
}

void vvp_queue::push_back(double, unsigned)
{
      cerr << "XXXX push_back(double) not implemented for " << typeid(*this).name() << endl;
}

void vvp_queue::push_front(double, unsigned)
{
      cerr << "XXXX push_front(double) not implemented for " << typeid(*this).name() << endl;
}

void vvp_queue::set_word_max(unsigned, const string&, unsigned)
{
      cerr << "XXXX set_word_max(string) not implemented for " << typeid(*this).name() << endl;
}

void vvp_queue::insert(unsigned, const string&, unsigned)
{
      cerr << "XXXX set_word_max(string) not implemented for " << typeid(*this).name() << endl;
}

void vvp_queue::push_back(const string&, unsigned)
{
      cerr << "XXXX push_back(string) not implemented for " << typeid(*this).name() << endl;
}

void vvp_queue::push_front(const string&, unsigned)
{
      cerr << "XXXX push_front(string) not implemented for " << typeid(*this).name() << endl;
}

vvp_queue_real::~vvp_queue_real()
{
}

/*
 * Helper functions used while copying multiple elements into a queue.
 */
static void print_copy_is_too_big(size_t src_size, unsigned max_size, const string&qtype)
{
      cerr << get_fileline()
           << "Warning: queue<" << qtype << "> is bounded to have at most "
           << max_size << " elements, source has " << src_size << " elements." << endl;
}

static void print_copy_is_too_big(double&, size_t src_size, unsigned max_size)
{
      print_copy_is_too_big(src_size, max_size, "real");
}

static void print_copy_is_too_big(string&, size_t src_size, unsigned max_size)
{
      print_copy_is_too_big(src_size, max_size, "string");
}

static void print_copy_is_too_big(vvp_vector4_t&, size_t src_size, unsigned max_size)
{
      print_copy_is_too_big(src_size, max_size, "vector");
}

template <typename ELEM, class QTYPE, class SRC_TYPE>
static void copy_elements(QTYPE*queue, SRC_TYPE*src, unsigned max_size)
{
      size_t src_size = src->get_size();
      if ((max_size != 0) && (src_size > max_size)) {
	    ELEM tmp;
	    print_copy_is_too_big(tmp, src_size, max_size);
      }
      unsigned copy_size = ((src_size < max_size) ||
                            (max_size == 0)) ? src_size : max_size;
      if (copy_size < queue->get_size())
	    queue->erase_tail(copy_size);
      for (unsigned idx=0; idx < copy_size; ++idx) {
	    ELEM value;
	    src->get_word(idx, value);
	    queue->set_word_max(idx, value, max_size);
      }
}

void vvp_queue_real::copy_elems(vvp_object_t src, unsigned max_size)
{
      if (vvp_queue*src_queue = src.peek<vvp_queue>())
	    copy_elements<double, vvp_queue_real, vvp_queue>(this, src_queue, max_size);
      else if (vvp_darray*src_darray = src.peek<vvp_darray>())
	    copy_elements<double, vvp_queue_real, vvp_darray>(this, src_darray, max_size);
      else
	    cerr << get_fileline() << "Sorry: cannot copy object to real queue." << endl;
}

void vvp_queue_real::set_word_max(unsigned adr, double value, unsigned max_size)
{
      if (adr == queue.size())
	    if (!max_size || (queue.size() < max_size))
		  queue.push_back(value);
	    else
		  cerr << get_fileline()
		       << "Warning: assigning to queue<real>[" << adr << "] is"
		          " outside bound (" << max_size << "). " << value
		       << " was not added." << endl;
      else
	    set_word(adr, value);
}

void vvp_queue_real::set_word(unsigned adr, double value)
{
      if (adr < queue.size())
	    queue[adr] = value;
      else
	    cerr << get_fileline()
	         << "Warning: assigning to queue<real>[" << adr << "] is outside "
	            "of size (" << queue.size() << "). " << value
	         << " was not added." << endl;
}

void vvp_queue_real::get_word(unsigned adr, double&value)
{
      if (adr >= queue.size())
	    value = 0.0;
      else
	    value = queue[adr];
}

void vvp_queue_real::insert(unsigned idx, double value, unsigned max_size)
{
	// Inserting past the end of the queue
      if (idx > queue.size())
	    cerr << get_fileline()
	         << "Warning: inserting to queue<real>[" << idx << "] is "
	            "outside of size (" << queue.size() << "). " << value
	         << " was not added." << endl;
	// Inserting at the end
      else if (idx == queue.size())
	    if (!max_size || (queue.size() < max_size))
		  queue.push_back(value);
	    else
		  cerr << get_fileline()
		       << "Warning: inserting to queue<real>[" << idx << "] is"
		          " outside bound (" << max_size << "). " << value
		       << " was not added." << endl;
      else  {
	    if (max_size && (queue.size() == max_size)) {
		  cerr << get_fileline()
		       << "Warning: insert("<< idx << ", " << value << ") removed "
		       << queue.back() << " from already full bounded queue<real> ["
		       << max_size << "]." << endl;
		  queue.pop_back();
	    }
	    queue.insert(queue.begin()+idx, value);
      }
}

void vvp_queue_real::push_back(double value, unsigned max_size)
{
      if (!max_size || (queue.size() < max_size))
	    queue.push_back(value);
      else
	    cerr << get_fileline()
	         << "Warning: push_back(" << value
	         << ") skipped for already full bounded queue<real> ["
	         << max_size << "]." << endl;
}

void vvp_queue_real::push_front(double value, unsigned max_size)
{
      if (max_size && (queue.size() == max_size)) {
	    cerr << get_fileline()
	         << "Warning: push_front(" << value << ") removed "
	         << queue.back() << " from already full bounded queue<real> ["
	         << max_size << "]." << endl;
	    queue.pop_back();
      }
      queue.push_front(value);
}

void vvp_queue_real::erase(unsigned idx)
{
      assert(queue.size() > idx);
      queue.erase(queue.begin()+idx);
}

void vvp_queue_real::erase_tail(unsigned idx)
{
      assert(queue.size() >= idx);
      if (queue.size() > idx)
	    queue.resize(idx);
}

vvp_queue_string::~vvp_queue_string()
{
}

void vvp_queue_string::copy_elems(vvp_object_t src, unsigned max_size)
{
      if (vvp_queue*src_queue = src.peek<vvp_queue>())
	    copy_elements<string, vvp_queue_string, vvp_queue>(this, src_queue, max_size);
      else if (vvp_darray*src_darray = src.peek<vvp_darray>())
	    copy_elements<string, vvp_queue_string, vvp_darray>(this, src_darray, max_size);
      else
	    cerr << get_fileline() << "Sorry: cannot copy object to string queue." << endl;
}

void vvp_queue_string::set_word_max(unsigned adr, const string&value, unsigned max_size)
{
      if (adr == queue.size())
	    if (!max_size || (queue.size() < max_size))
		  queue.push_back(value);
	    else
		  cerr << get_fileline()
		       << "Warning: assigning to queue<string>[" << adr << "] is"
		          " outside bound (" << max_size << "). \"" << value
		       << "\" was not added." << endl;
      else
	    set_word(adr, value);
}

void vvp_queue_string::set_word(unsigned adr, const string&value)
{
      if (adr < queue.size())
	    queue[adr] = value;
      else
	    cerr << get_fileline()
	         << "Warning: assigning to queue<string>[" << adr << "] is outside "
	            "of size (" << queue.size() << "). \"" << value
	         << "\" was not added." << endl;
}

void vvp_queue_string::get_word(unsigned adr, string&value)
{
      if (adr >= queue.size())
	    value = "";
      else
	    value = queue[adr];
}

void vvp_queue_string::insert(unsigned idx, const string&value, unsigned max_size)
{
	// Inserting past the end of the queue
      if (idx > queue.size())
	    cerr << get_fileline()
	         << "Warning: inserting to queue<string>[" << idx << "] is "
	            "outside of size (" << queue.size() << "). \"" << value
	         << "\" was not added." << endl;
	// Inserting at the end
      else if (idx == queue.size())
	    if (!max_size || (queue.size() < max_size))
		  queue.push_back(value);
	    else
		  cerr << get_fileline()
		       << "Warning: inserting to queue<string>[" << idx << "] is"
		          " outside bound (" << max_size << "). \"" << value
		       << "\" was not added." << endl;
      else  {
	    if (max_size && (queue.size() == max_size)) {
		  cerr << get_fileline()
		       << "Warning: insert("<< idx << ", \"" << value << "\") removed \""
		       << queue.back() << "\" from already full bounded queue<string> ["
		       << max_size << "]." << endl;
		  queue.pop_back();
	    }
	    queue.insert(queue.begin()+idx, value);
      }
}

void vvp_queue_string::push_back(const string&value, unsigned max_size)
{
      if (!max_size || (queue.size() < max_size))
	    queue.push_back(value);
      else
	    cerr << get_fileline()
	         << "Warning: push_back(\"" << value
	         << "\") skipped for already full bounded queue<string> ["
	         << max_size << "]." << endl;
}

void vvp_queue_string::push_front(const string&value, unsigned max_size)
{
      if (max_size && (queue.size() == max_size)) {
	    cerr << get_fileline()
	         << "Warning: push_front(\"" << value << "\") removed \""
	         << queue.back() << "\" from already full bounded queue<string> ["
	         << max_size << "]." << endl;
	    queue.pop_back();
      }
      queue.push_front(value);
}

void vvp_queue_string::erase(unsigned idx)
{
      assert(queue.size() > idx);
      queue.erase(queue.begin()+idx);
}

void vvp_queue_string::erase_tail(unsigned idx)
{
      assert(queue.size() >= idx);
      if (queue.size() > idx)
	    queue.resize(idx);
}

vvp_queue_vec4::~vvp_queue_vec4()
{
}

void vvp_queue_vec4::copy_elems(vvp_object_t src, unsigned max_size)
{
      if (vvp_queue*src_queue = src.peek<vvp_queue>())
	    copy_elements<vvp_vector4_t, vvp_queue_vec4, vvp_queue>(this, src_queue, max_size);
      else if (vvp_darray*src_darray = src.peek<vvp_darray>())
	    copy_elements<vvp_vector4_t, vvp_queue_vec4, vvp_darray>(this, src_darray, max_size);
      else
	    cerr << get_fileline() << "Sorry: cannot copy object to vector queue." << endl;
}

void vvp_queue_vec4::set_word_max(unsigned adr, const vvp_vector4_t&value, unsigned max_size)
{
      if (adr == queue.size())
	    if (!max_size || (queue.size() < max_size))
		  queue.push_back(value);
	    else
		  cerr << get_fileline()
		       << "Warning: assigning to queue<vector>[" << adr << "] is"
		          " outside bound (" << max_size << "). " << value
		       << " was not added." << endl;
      else
	    set_word(adr, value);
}

void vvp_queue_vec4::set_word(unsigned adr, const vvp_vector4_t&value)
{
      if (adr < queue.size())
	    queue[adr] = value;
      else
	    cerr << get_fileline()
	         << "Warning: assigning to queue<vector>[" << adr << "] is outside "
	            "of size (" << queue.size() << "). " << value
	         << " was not added." << endl;
}

void vvp_queue_vec4::get_word(unsigned adr, vvp_vector4_t&value)
{
      if (adr >= queue.size())
	    value = vvp_vector4_t(queue[0].size());
      else
	    value = queue[adr];
}

void vvp_queue_vec4::insert(unsigned idx, const vvp_vector4_t&value, unsigned max_size)
{
	// Inserting past the end of the queue
      if (idx > queue.size())
	    cerr << get_fileline()
	         << "Warning: inserting to queue<vector[" << value.size()
	         << "]>[" << idx << "] is outside of size (" << queue.size()
	         << "). " << value << " was not added." << endl;
	// Inserting at the end
      else if (idx == queue.size())
	    if (!max_size || (queue.size() < max_size))
		  queue.push_back(value);
	    else
		  cerr << get_fileline()
		       << "Warning: inserting to queue<vector[" << value.size()
		       << "]>[" << idx << "] is outside bound (" << max_size
		       << "). " << value << " was not added." << endl;
      else  {
	    if (max_size && (queue.size() == max_size)) {
		  cerr << get_fileline()
		       << "Warning: insert("<< idx << ", " << value << ") removed "
		       << queue.back() << " from already full bounded queue<vector["
		       << value.size() << "]> [" << max_size << "]." << endl;
		  queue.pop_back();
	    }
	    queue.insert(queue.begin()+idx, value);
      }
}

void vvp_queue_vec4::push_back(const vvp_vector4_t&value, unsigned max_size)
{
      if (!max_size || (queue.size() < max_size))
	    queue.push_back(value);
      else
	    cerr << get_fileline()
	         << "Warning: push_back(" << value
	         << ") skipped for already full bounded queue<vector["
	         << value.size() << "]> [" << max_size << "]." << endl;
}

void vvp_queue_vec4::push_front(const vvp_vector4_t&value, unsigned max_size)
{
      if (max_size && (queue.size() == max_size)) {
	    cerr << get_fileline()
	         << "Warning: push_front(" << value << ") removed "
	         << queue.back() << " from already full bounded queue<vector["
	         << value.size() << "]> [" << max_size << "]." << endl;
	    queue.pop_back();
      }
      queue.push_front(value);
}

void vvp_queue_vec4::erase(unsigned idx)
{
      assert(queue.size() > idx);
      queue.erase(queue.begin()+idx);
}

void vvp_queue_vec4::erase_tail(unsigned idx)
{
      assert(queue.size() >= idx);
      if (queue.size() > idx)
	    queue.resize(idx);
}