PackedListI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "error.H"
27 #include <climits>
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 template<unsigned nBits>
32 inline unsigned int Foam::PackedList<nBits>::max_bits()
33 {
34  return sizeof(StorageType)*CHAR_BIT - 1;
35 }
36 
37 
38 template<unsigned nBits>
40 {
41  return (1u << nBits) - 1;
42 }
43 
44 
45 template<unsigned nBits>
46 inline unsigned int Foam::PackedList<nBits>::packing()
47 {
48  return sizeof(StorageType)*CHAR_BIT / nBits;
49 }
50 
51 
52 template<unsigned nBits>
53 inline unsigned int Foam::PackedList<nBits>::maskLower(unsigned offset)
54 {
55  // return (1u << (nBits * offset)) - 1;
56  // The next one works more reliably with overflows
57  // eg, when compiled without optimization
58  return (~0u >> ( sizeof(StorageType)*CHAR_BIT - nBits * offset));
59 }
60 
61 
62 template<unsigned nBits>
64 {
65  return (nElem + packing() - 1) / packing();
66 }
67 
68 
69 namespace Foam
70 {
71  // Template specialization for bool entries
72  template<>
73  inline unsigned int Foam::PackedList<1>::readValue(Istream& is)
74  {
75  return readBool(is);
76  }
77 
78  // Template specialization for bool entries
79  template<>
81  {
82  set(readLabel(is), true);
83  }
84 
85  // Template specialization for bool entries
86  template<>
88  {
89  if (this->get())
90  {
91  os << index_;
92 
93  return true;
94  }
95  else
96  {
97  return false;
98  }
99  }
100 }
101 
102 
103 template<unsigned nBits>
105 {
106  const unsigned int val = readLabel(is);
107 
108  if (val > max_value())
109  {
111  (
112  "PackedList<nBits>::readValue(Istream&)",
113  is
114  )
115  << "Out-of-range value " << val << " for PackedList<" << nBits
116  << ">. Maximum permitted value is " << max_value() << "."
117  << exit(FatalIOError);
118  }
119 
120  return val;
121 }
122 
123 
124 template<unsigned nBits>
126 {
127  is.readBegin("Tuple2<label, unsigned int>");
128 
129  const label ind = readLabel(is);
130  const unsigned int val = readLabel(is);
131 
132  is.readEnd("Tuple2<label, unsigned int>");
133 
134  if (val > max_value())
135  {
137  (
138  "PackedList<nBits>::setPair(Istream&)",
139  is
140  )
141  << "Out-of-range value " << val << " for PackedList<" << nBits
142  << "> at index " << ind
143  << ". Maximum permitted value is " << max_value() << "."
144  << exit(FatalIOError);
145  }
146 
147  set(ind, val);
148 
149  // Check state of Istream
150  is.check("PackedList<nBits>::setPair(Istream&)");
151 }
152 
153 
154 template<unsigned nBits>
156 {
157  const label val = this->get();
158 
159  if (val)
160  {
161  os << token::BEGIN_LIST
162  << index_ << token::SPACE << val
163  << token::END_LIST;
164 
165  return true;
166  }
167  else
168  {
169  return false;
170  }
171 }
172 
173 
174 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
175 
176 template<unsigned nBits>
178 :
179  PackedListCore(),
180  StorageList(),
181  size_(0)
182 {}
183 
184 
185 template<unsigned nBits>
187 :
188  PackedListCore(),
189  StorageList(packedLength(size), 0u),
190  size_(size)
191 {}
192 
193 
194 template<unsigned nBits>
196 (
197  const label size,
198  const unsigned int val
199 )
200 :
201  PackedListCore(),
202  StorageList(packedLength(size), 0u),
203  size_(size)
204 {
205  if (val)
206  {
207  operator=(val);
208  }
209 }
210 
211 
212 template<unsigned nBits>
214 :
215  PackedListCore(),
216  StorageList(),
217  size_(0)
218 {
219  read(is);
220 }
221 
222 
223 template<unsigned nBits>
225 :
226  PackedListCore(),
227  StorageList(lst),
228  size_(lst.size_)
229 {}
230 
231 
232 template<unsigned nBits>
234 {
235  transfer(lst());
236 }
237 
238 
239 template<unsigned nBits>
241 :
242  PackedListCore(),
243  StorageList(packedLength(lst.size()), 0u),
244  size_(lst.size())
245 {
246  forAll(lst, i)
247  {
248  set(i, lst[i]);
249  }
250 }
251 
252 
253 template<unsigned nBits>
255 :
256  PackedListCore(),
257  StorageList(packedLength(lst.size()), 0u),
258  size_(lst.size())
259 {
260  forAll(lst, i)
261  {
262  set(i, lst[i]);
263  }
264 }
265 
266 
267 template<unsigned nBits>
270 {
271  return autoPtr<PackedList<nBits> >(new PackedList<nBits>(*this));
272 }
273 
274 
275 // * * * * * * * * * * * * * * * * Iterators * * * * * * * * * * * * * * * * //
276 
277 // iteratorBase
278 
279 template<unsigned nBits>
281 :
282  list_(0),
283  index_(0)
284 {}
285 
286 
287 template<unsigned nBits>
289 (
290  const PackedList<nBits>* lst,
291  const label i
292 )
293 :
294  list_(const_cast<PackedList<nBits>*>(lst)),
295  index_(i)
296 {}
297 
298 
299 template<unsigned nBits>
300 inline unsigned int
302 {
303  const unsigned int seg = index_ / packing();
304  const unsigned int off = index_ % packing();
305 
306  const unsigned int& stored = list_->StorageList::operator[](seg);
307  return (stored >> (nBits * off)) & max_value();
308 }
309 
310 
311 template<unsigned nBits>
312 inline bool
314 {
315  const unsigned int seg = index_ / packing();
316  const unsigned int off = index_ % packing();
317 
318  const unsigned int startBit = nBits * off;
319  const unsigned int mask = max_value() << startBit;
320 
321  unsigned int& stored = list_->StorageList::operator[](seg);
322  const unsigned int prev = stored;
323 
324  if (val >= max_value())
325  {
326  // overflow is max_value, fill everything
327  stored |= mask;
328  }
329  else
330  {
331  stored &= ~mask;
332  stored |= mask & (val << startBit);
333  }
334 
335  return prev != stored;
336 }
337 
338 
339 template<unsigned nBits>
341 {
342  return index_;
343 }
344 
345 
346 template<unsigned nBits>
348 (
349  const iteratorBase& iter
350 ) const
351 {
352  return this->get() == iter.get();
353 }
354 
355 
356 template<unsigned nBits>
357 inline bool Foam::PackedList<nBits>::iteratorBase::operator!=
358 (
359  const iteratorBase& iter
360 ) const
361 {
362  return this->get() != iter.get();
363 }
364 
365 
366 template<unsigned nBits>
367 inline unsigned int
369 {
370  const unsigned int val = iter.get();
371  this->set(val);
372  return val;
373 }
374 
375 
376 template<unsigned nBits>
377 inline unsigned int
379 {
380  // lazy evaluation - increase size on assigment
381  if (index_ >= list_->size_)
382  {
383  list_->resize(index_ + 1);
384  }
385 
386  this->set(val);
387  return val;
388 }
389 
390 
391 template<unsigned nBits>
392 inline Foam::PackedList<nBits>::iteratorBase::operator
393 unsigned int () const
394 {
395  // lazy evaluation - return 0 for out-of-range
396  if (index_ >= list_->size_)
397  {
398  return 0;
399  }
400 
401  return this->get();
402 }
403 
404 
405 // const_iterator, iterator
406 
407 template<unsigned nBits>
409 :
410  iteratorBase()
411 {}
412 
413 
414 template<unsigned nBits>
416 :
417  iteratorBase()
418 {}
419 
420 
421 template<unsigned nBits>
423 (
424  const iteratorBase& iter
425 )
426 :
427  iteratorBase(iter)
428 {
429  // avoid going past end()
430  // eg, iter = iterator(list, Inf)
431  if (this->index_ > this->list_->size_)
432  {
433  this->index_ = this->list_->size_;
434  }
435 }
436 
437 
438 template<unsigned nBits>
440 (
441  const iteratorBase& iter
442 )
443 :
444  iteratorBase(iter)
445 {
446  // avoid going past end()
447  // eg, iter = iterator(list, Inf)
448  if (this->index_ > this->list_->size_)
449  {
450  this->index_ = this->list_->size_;
451  }
452 }
453 
454 
455 template<unsigned nBits>
457 (
458  const PackedList<nBits>* lst,
459  const label i
460 )
461 :
462  iteratorBase(lst, i)
463 {}
464 
465 
466 template<unsigned nBits>
468 (
469  const PackedList<nBits>* lst,
470  const label i
471 )
472 :
473  iteratorBase(lst, i)
474 {}
475 
476 
477 template<unsigned nBits>
479 (
480  const iterator& iter
481 )
482 :
483  iteratorBase(static_cast<const iteratorBase&>(iter))
484 {}
485 
486 
487 template<unsigned nBits>
488 inline bool Foam::PackedList<nBits>::iterator::operator==
489 (
490  const iteratorBase& iter
491 ) const
492 {
493  return this->index_ == iter.index_;
494 }
495 
496 
497 template<unsigned nBits>
498 inline bool Foam::PackedList<nBits>::iterator::operator!=
499 (
500  const iteratorBase& iter
501 ) const
502 {
503  return this->index_ != iter.index_;
504 }
505 
506 
507 template<unsigned nBits>
508 inline bool Foam::PackedList<nBits>::const_iterator::operator==
509 (
510  const iteratorBase& iter
511 ) const
512 {
513  return this->index_ == iter.index_;
514 }
515 
516 
517 template<unsigned nBits>
518 inline bool Foam::PackedList<nBits>::const_iterator::operator!=
519 (
520  const iteratorBase& iter
521 ) const
522 {
523  return this->index_ != iter.index_;
524 }
525 
526 
527 template<unsigned nBits>
528 inline typename Foam::PackedList<nBits>::iterator&
530 {
531  this->list_ = iter.list_;
532  this->index_ = iter.index_;
533 
534  // avoid going past end()
535  // eg, iter = iterator(list, Inf)
536  if (this->index_ > this->list_->size_)
537  {
538  this->index_ = this->list_->size_;
539  }
540 
541  return *this;
542 }
543 
544 
545 template<unsigned nBits>
548 {
549  this->list_ = iter.list_;
550  this->index_ = iter.index_;
551 
552  // avoid going past end()
553  // eg, iter = iterator(list, Inf)
554  if (this->index_ > this->list_->size_)
555  {
556  this->index_ = this->list_->size_;
557  }
558 
559  return *this;
560 }
561 
562 
563 template<unsigned nBits>
564 inline typename Foam::PackedList<nBits>::iterator&
566 {
567  ++this->index_;
568  return *this;
569 }
570 
571 
572 template<unsigned nBits>
575 {
576  ++this->index_;
577  return *this;
578 }
579 
580 
581 template<unsigned nBits>
582 inline typename Foam::PackedList<nBits>::iterator
584 {
585  iterator old = *this;
586  ++this->index_;
587  return old;
588 }
589 
590 
591 template<unsigned nBits>
594 {
595  const_iterator old = *this;
596  ++this->index_;
597  return old;
598 }
599 
600 
601 template<unsigned nBits>
602 inline typename Foam::PackedList<nBits>::iterator&
604 {
605  --this->index_;
606  return *this;
607 }
608 
609 
610 template<unsigned nBits>
613 {
614  --this->index_;
615  return *this;
616 }
617 
618 
619 template<unsigned nBits>
620 inline typename Foam::PackedList<nBits>::iterator
622 {
623  iterator old = *this;
624  --this->index_;
625  return old;
626 }
627 
628 
629 template<unsigned nBits>
632 {
633  const_iterator old = *this;
634  --this->index_;
635  return old;
636 }
637 
638 
639 template<unsigned nBits>
642 {
643  return static_cast<iteratorBase&>(*this);
644 }
645 
646 
647 template<unsigned nBits>
650 {
651  return static_cast<iteratorBase&>(*this);
652 }
653 
654 
655 template<unsigned nBits>
656 inline unsigned int
658 {
659  return this->get();
660 }
661 
662 
663 template<unsigned nBits>
664 inline unsigned int
666 {
667  return this->get();
668 }
669 
670 
671 template<unsigned nBits>
672 inline typename Foam::PackedList<nBits>::iterator
674 {
675  return iterator(this, 0);
676 }
677 
678 
679 template<unsigned nBits>
682 {
683  return const_iterator(this, 0);
684 }
685 
686 
687 template<unsigned nBits>
690 {
691  return const_iterator(this, 0);
692 }
693 
694 
695 template<unsigned nBits>
696 inline typename Foam::PackedList<nBits>::iterator
698 {
699  return iterator(this, size_);
700 }
701 
702 
703 template<unsigned nBits>
706 {
707  return const_iterator(this, size_);
708 }
709 
710 
711 template<unsigned nBits>
714 {
715  return const_iterator(this, size_);
716 }
717 
718 
719 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
720 
721 template<unsigned nBits>
723 {
724  return size_;
725 }
726 
727 
728 template<unsigned nBits>
730 {
731  return !size_;
732 }
733 
734 
735 template<unsigned nBits>
737 (
738  const label newSize,
739  const unsigned int& val
740 )
741 {
742  reserve(newSize);
743 
744  const label oldSize = size_;
745  size_ = newSize;
746 
747  if (size_ > oldSize)
748  {
749  // fill new elements or newly exposed elements
750  if (val)
751  {
752  // fill value for complete segments
753  unsigned int fill = val;
754 
755  if (val >= max_value())
756  {
757  // fill everything
758  fill = maskLower(packing());
759  }
760  else
761  {
762  for (unsigned int i = 1; i < packing(); ++i)
763  {
764  fill |= (fill << nBits);
765  }
766  }
767 
768  // fill in complete segments
769  const label oldLen = packedLength(oldSize);
770  const label newLen = packedLength(size_);
771  for (label i=oldLen; i < newLen; ++i)
772  {
773  StorageList::operator[](i) = fill;
774  }
775 
776  // finish previous partial segment, preserve existing value
777  {
778  const unsigned int off = oldSize % packing();
779  if (off)
780  {
781  const unsigned int seg = oldSize / packing();
782  const unsigned int mask = maskLower(off);
783 
784  StorageList::operator[](seg) &= mask;
785  StorageList::operator[](seg) |= ~mask & fill;
786  }
787  }
788 
789 
790  // mask off the (new) final partial segment
791  {
792  const unsigned int off = size_ % packing();
793  if (off)
794  {
795  const unsigned int seg = size_ / packing();
796 
797  StorageList::operator[](seg) &= maskLower(off);
798  }
799  }
800  }
801  }
802  else if (size_ < oldSize)
803  {
804  // resize shrinking
805  // - clear newly exposed elements
806 
807  // fill in complete segments
808  const label oldLen = packedLength(oldSize);
809  const label newLen = packedLength(size_);
810  for (label i=newLen; i < oldLen; ++i)
811  {
812  StorageList::operator[](i) = 0u;
813  }
814 
815  // mask off the final partial segment
816  {
817  const unsigned int off = size_ % packing();
818  if (off)
819  {
820  const unsigned int seg = size_ / packing();
821 
822  StorageList::operator[](seg) &= maskLower(off);
823  }
824  }
825  }
826 }
827 
828 
829 template<unsigned nBits>
831 (
832  const label newSize,
833  const unsigned int& val
834 )
835 {
836  resize(newSize, val);
837 }
838 
839 
840 
841 template<unsigned nBits>
843 {
844  return packing() * StorageList::size();
845 }
846 
847 
848 template<unsigned nBits>
850 {
852 
853  // truncate addressed size too
854  if (size_ > nElem)
855  {
856  size_ = nElem;
857 
858  // mask off the final partial segment
859  const unsigned int off = size_ % packing();
860  if (off)
861  {
862  const unsigned int seg = size_ / packing();
863 
864  StorageList::operator[](seg) &= maskLower(off);
865  }
866  }
867 }
868 
869 
870 template<unsigned nBits>
871 inline void Foam::PackedList<nBits>::reserve(const label nElem)
872 {
873  const label len = packedLength(nElem);
874 
875  // need more capacity?
876  if (len > StorageList::size())
877  {
878  // Like DynamicList with SizeInc=0, SizeMult=2, SizeDiv=1
880  (
881  max
882  (
883  len,
885  ),
886  0u
887  );
888  }
889 }
890 
891 
892 template<unsigned nBits>
894 {
896 }
897 
898 
899 template<unsigned nBits>
901 {
902  reset();
903  size_ = 0;
904 }
905 
906 
907 template<unsigned nBits>
909 {
911  size_ = 0;
912 }
913 
914 
915 template<unsigned nBits>
917 {
918  // any uneed space allocated?
919  const label len = packedLength();
920  if (len < StorageList::size())
921  {
923  }
924 }
925 
926 template<unsigned nBits>
928 {
929  return static_cast<StorageList&>(*this);
930 }
931 
932 
933 template<unsigned nBits>
935 {
936  return static_cast<const StorageList&>(*this);
937 }
938 
939 
940 template<unsigned nBits>
942 {
943  return packedLength(size_);
944 }
945 
946 
947 template<unsigned nBits>
948 inline std::streamsize Foam::PackedList<nBits>::byteSize() const
949 {
950  return packedLength() * sizeof(StorageType);
951 }
952 
953 
954 template<unsigned nBits>
956 {
957  size_ = lst.size_;
958  lst.size_ = 0;
959 
961 }
962 
963 
964 template<unsigned nBits>
966 {
967  return xferMove(*this);
968 }
969 
970 
971 template<unsigned nBits>
972 inline unsigned int Foam::PackedList<nBits>::get(const label i) const
973 {
974  // lazy evaluation - return 0 for out-of-range
975  if (i < 0 || i >= size_)
976  {
977  return 0;
978  }
979  else
980  {
981  return iteratorBase(this, i).get();
982  }
983 }
984 
985 
986 template<unsigned nBits>
987 inline unsigned int Foam::PackedList<nBits>::operator[](const label i) const
988 {
989  // lazy evaluation - return 0 for out-of-range
990  if (i < 0 || i >= size_)
991  {
992  return 0;
993  }
994  else
995  {
996  return iteratorBase(this, i).get();
997  }
998 }
999 
1000 
1001 template<unsigned nBits>
1002 inline bool Foam::PackedList<nBits>::set
1004  const label i,
1005  const unsigned int val
1006 )
1007 {
1008  if (i < 0)
1009  {
1010  // lazy evaluation - ignore out-of-bounds
1011  return false;
1012  }
1013  else if (i >= size_)
1014  {
1015  // lazy evaluation - increase size on assigment
1016  resize(i + 1);
1017  }
1018 
1019  return iteratorBase(this, i).set(val);
1020 }
1021 
1022 
1023 template<unsigned nBits>
1025 {
1026  // lazy evaluation - ignore out-of-bounds
1027  if (i < 0 || i >= size_)
1028  {
1029  return false;
1030  }
1031  else
1032  {
1033  return iteratorBase(this, i).set(0u);
1034  }
1035 }
1036 
1037 
1038 template<unsigned nBits>
1040 Foam::PackedList<nBits>::append(const unsigned int val)
1041 {
1042  const label elemI = size_;
1043  reserve(elemI + 1);
1044  size_++;
1045 
1046  iteratorBase(this, elemI).set(val);
1047  return *this;
1048 }
1049 
1050 
1051 template<unsigned nBits>
1052 inline unsigned int Foam::PackedList<nBits>::remove()
1053 {
1054  if (!size_)
1055  {
1056  FatalErrorIn
1057  (
1058  "Foam::PackedList<nBits>::remove()"
1059  ) << "List is empty" << abort(FatalError);
1060  }
1061 
1062  label elemI = size_ - 1;
1063  const unsigned int val = iteratorBase(this, elemI).get();
1064  resize(elemI);
1065 
1066  return val;
1067 }
1068 
1069 
1070 template<unsigned nBits>
1073 {
1074  return iteratorBase(this, i);
1075 }
1076 
1077 
1078 template<unsigned nBits>
1080 Foam::PackedList<nBits>::operator=(const unsigned int val)
1081 {
1082  const label packLen = packedLength();
1083 
1084  if (val && size_)
1085  {
1086  unsigned int fill = val;
1087 
1088  if (val >= max_value())
1089  {
1090  // fill everything
1091  fill = maskLower(packing());
1092  }
1093  else
1094  {
1095  for (unsigned int i = 1; i < packing(); ++i)
1096  {
1097  fill |= (fill << nBits);
1098  }
1099  }
1100 
1101  for (label i=0; i < packLen; ++i)
1102  {
1103  StorageList::operator[](i) = fill;
1104  }
1105 
1106  // mask off the final partial segment
1107  {
1108  const unsigned int off = size_ % packing();
1109  if (off)
1110  {
1111  const unsigned int seg = size_ / packing();
1112 
1113  StorageList::operator[](seg) &= maskLower(off);
1114  }
1115  }
1116  }
1117  else
1118  {
1119  for (label i=0; i < packLen; ++i)
1120  {
1121  StorageList::operator[](i) = 0u;
1122  }
1123  }
1124 
1125  return *this;
1126 }
1127 
1128 
1129 // ************************************************************************* //
bool readBool(Istream &)
Definition: boolIO.C:60
The iterator base for PackedList.
Definition: PackedList.H:417
void transfer(PackedList< nBits > &)
Transfer the contents of the argument list into this list.
Definition: PackedListI.H:955
const_iterator & operator=(const iteratorBase &)
Assign from iteratorBase or derived.
Definition: PackedListI.H:547
static unsigned int max_value()
The max. value for an entry, which simultaneously the bit-mask.
Definition: PackedListI.H:39
const_iterator()
Construct null.
Definition: PackedListI.H:415
void setPair(Istream &)
Read an index/value pair and set accordingly.
Definition: PackedListI.H:125
const_iterator cend() const
const_iterator set to beyond the end of the PackedList
Definition: PackedListI.H:713
unsigned int operator[](const label) const
Get value at index I.
Definition: PackedListI.H:987
void reset()
Clear all bits.
Definition: PackedListI.H:893
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:390
iteratorBase()
Construct null.
Definition: PackedListI.H:280
void clearStorage()
Clear the list and delete storage.
Definition: PackedListI.H:908
unsigned int remove()
Remove and return the last element.
Definition: PackedListI.H:1052
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
static unsigned int maskLower(unsigned offset)
Masking for all bits below the offset.
Definition: PackedListI.H:53
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
Istream & read(Istream &)
Clear list and read from stream.
Definition: PackedList.C:254
T * iterator
Random access iterator for traversing UList.
Definition: UList.H:250
void shrink()
Shrink the allocated space to what is actually used.
Definition: PackedListI.H:916
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
bool set(const label, const unsigned int val=~0u)
Set value at index I. Return true if value changed.
Definition: PackedListI.H:1003
void setCapacity(const label)
Alter the size of the underlying storage.
Definition: PackedListI.H:849
List< unsigned int > & storage()
Return the underlying packed storage.
Definition: PackedListI.H:927
label size() const
Number of entries.
Definition: PackedListI.H:722
Xfer< T > xferMove(T &)
PackedListCore()
Construct null.
Definition: PackedList.H:133
label packedLength() const
The list length when packed.
Definition: PackedListI.H:941
PackedList< nBits > & append(const unsigned int val)
Append a value at the end of the list.
Definition: PackedListI.H:1040
PackedList< nBits > & operator=(const unsigned int val)
Assignment of all entries to the given value. Takes linear time.
Definition: PackedListI.H:1080
Namespace for OpenFOAM.
label readLabel(Istream &is)
Definition: label.H:64
Xfer< PackedList< nBits > > xfer()
Transfer contents to the Xfer container.
Definition: PackedListI.H:965
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
const_iterator & operator++()
Definition: PackedListI.H:574
unsigned int operator()() const
Return referenced value directly.
Definition: PackedListI.H:665
static unsigned int max_bits()
The max. number of bits that can be templated.
Definition: PackedListI.H:32
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
T & operator[](const label)
Return element of UList.
Definition: UListI.H:163
void clear()
Clear the list, i.e. set size to zero.
Definition: List.C:379
void setSize(const label)
Reset size of List.
Definition: List.C:318
void setSize(const label, const unsigned int &val=0u)
Alias for resize()
Definition: PackedListI.H:831
IOerror FatalIOError
label index_
Element index.
Definition: PackedList.H:430
bool set(unsigned int)
Set value, returning true if changed, no range-checking.
Definition: PackedListI.H:313
PackedList()
Null constructor.
Definition: PackedListI.H:177
A List with indirect addressing.
Definition: fvMatrix.H:106
List< StorageType > StorageList
Definition: PackedList.H:154
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
static unsigned int readValue(Istream &)
Read a list entry (allows for specialization)
Definition: PackedListI.H:104
#define forAll(list, i)
Definition: UList.H:421
bool writeIfSet(Ostream &) const
Write index/value for a non-zero entry.
Definition: PackedListI.H:155
label capacity() const
The number of elements that can be stored before reallocating.
Definition: PackedListI.H:842
const_iterator cbegin() const
const_iterator set to the beginning of the PackedList
Definition: PackedListI.H:689
unsigned int operator*() const
Return referenced value directly.
Definition: PackedListI.H:657
void reserve(const label)
Reserve allocation space for at least this size.
Definition: PackedListI.H:871
label key() const
Return the element index corresponding to the iterator.
Definition: PackedListI.H:340
errorManip< error > abort(error &err)
Definition: errorManip.H:131
The iterator class used for PackedList.
Definition: PackedList.H:486
autoPtr< PackedList< nBits > > clone() const
Clone.
Definition: PackedListI.H:269
Istream & readBegin(const char *funcName)
Definition: Istream.C:88
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
Template-invariant bits for PackedList.
Definition: PackedList.H:130
void clear()
Clear the list, i.e. set addressable size to zero.
Definition: PackedListI.H:900
error FatalError
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
label size() const
Return the number of elements in the UList.
Definition: ListI.H:83
std::streamsize byteSize() const
Return the binary size in number of characters.
Definition: PackedListI.H:948
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
unsigned int get() const
Get value as unsigned, no range-checking.
Definition: PackedListI.H:301
unsigned int operator=(const iteratorBase &)
Assign value, not position.
Definition: PackedListI.H:368
unsigned int operator()() const
Return value.
iterator begin()
Iterator set to the beginning of the PackedList.
Definition: PackedListI.H:673
iterator end()
Iterator set to beyond the end of the PackedList.
Definition: PackedListI.H:697
static unsigned int packing()
The number of entries per packed storage element.
Definition: PackedListI.H:46
iterator()
Construct null.
Definition: PackedListI.H:408
PackedList * list_
Pointer to original list.
Definition: PackedList.H:427
bool unset(const label)
Unset the entry at index I. Return true if value changed.
Definition: PackedListI.H:1024
A dynamically allocatable list of packed unsigned integers.
Definition: PackedList.H:117
const_iterator & operator--()
Definition: PackedListI.H:612
unsigned int StorageType
Definition: PackedList.H:153
bool empty() const
Return true if the list is empty (ie, size() is zero).
Definition: PackedListI.H:729
#define FatalIOErrorIn(functionName, ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:325
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
void resize(const label, const unsigned int &val=0u)
Reset addressable list size, does not shrink the allocated size.
Definition: PackedListI.H:737
The const_iterator for PackedList.
Definition: PackedList.H:554
unsigned int operator*() const
Return value.
unsigned int get(const label) const
Get value at index I.
Definition: PackedListI.H:972
Istream & readEnd(const char *funcName)
Definition: Istream.C:105
void operator=(const UList< T > &)
Assignment from UList operator. Takes linear time.
Definition: List.C:429