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