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-2016 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 assigment
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  return *this;
551 }
552 
553 
554 template<unsigned nBits>
555 inline typename Foam::PackedList<nBits>::iterator&
557 {
558  ++this->index_;
559  return *this;
560 }
561 
562 
563 template<unsigned nBits>
566 {
567  ++this->index_;
568  return *this;
569 }
570 
571 
572 template<unsigned nBits>
573 inline typename Foam::PackedList<nBits>::iterator
575 {
576  iterator old = *this;
577  ++this->index_;
578  return old;
579 }
580 
581 
582 template<unsigned nBits>
585 {
586  const_iterator old = *this;
587  ++this->index_;
588  return old;
589 }
590 
591 
592 template<unsigned nBits>
593 inline typename Foam::PackedList<nBits>::iterator&
595 {
596  --this->index_;
597  return *this;
598 }
599 
600 
601 template<unsigned nBits>
604 {
605  --this->index_;
606  return *this;
607 }
608 
609 
610 template<unsigned nBits>
611 inline typename Foam::PackedList<nBits>::iterator
613 {
614  iterator old = *this;
615  --this->index_;
616  return old;
617 }
618 
619 
620 template<unsigned nBits>
623 {
624  const_iterator old = *this;
625  --this->index_;
626  return old;
627 }
628 
629 
630 template<unsigned nBits>
633 {
634  return static_cast<iteratorBase&>(*this);
635 }
636 
637 
638 template<unsigned nBits>
641 {
642  return static_cast<iteratorBase&>(*this);
643 }
644 
645 
646 template<unsigned nBits>
647 inline unsigned int
649 {
650  return this->get();
651 }
652 
653 
654 template<unsigned nBits>
655 inline unsigned int
657 {
658  return this->get();
659 }
660 
661 
662 template<unsigned nBits>
663 inline typename Foam::PackedList<nBits>::iterator
665 {
666  return iterator(this, 0);
667 }
668 
669 
670 template<unsigned nBits>
673 {
674  return const_iterator(this, 0);
675 }
676 
677 
678 template<unsigned nBits>
681 {
682  return const_iterator(this, 0);
683 }
684 
685 
686 template<unsigned nBits>
687 inline typename Foam::PackedList<nBits>::iterator
689 {
690  return iterator(this, size_);
691 }
692 
693 
694 template<unsigned nBits>
697 {
698  return const_iterator(this, size_);
699 }
700 
701 
702 template<unsigned nBits>
705 {
706  return const_iterator(this, size_);
707 }
708 
709 
710 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
711 
712 template<unsigned nBits>
714 {
715  return size_;
716 }
717 
718 
719 template<unsigned nBits>
721 {
722  return !size_;
723 }
724 
725 
726 template<unsigned nBits>
728 (
729  const label newSize,
730  const unsigned int& val
731 )
732 {
733  reserve(newSize);
734 
735  const label oldSize = size_;
736  size_ = newSize;
737 
738  if (size_ > oldSize)
739  {
740  // Fill new elements or newly exposed elements
741  if (val)
742  {
743  // Fill value for complete segments
744  unsigned int fill = val;
745 
746  if (val >= max_value())
747  {
748  // Fill everything
749  fill = maskLower(packing());
750  }
751  else
752  {
753  for (unsigned int i = 1; i < packing(); ++i)
754  {
755  fill |= (fill << nBits);
756  }
757  }
758 
759  // Fill in complete segments
760  const label oldLen = packedLength(oldSize);
761  const label newLen = packedLength(size_);
762  for (label i=oldLen; i < newLen; ++i)
763  {
764  StorageList::operator[](i) = fill;
765  }
766 
767  // Finish previous partial segment, preserve existing value
768  {
769  const unsigned int off = oldSize % packing();
770  if (off)
771  {
772  const unsigned int seg = oldSize / packing();
773  const unsigned int mask = maskLower(off);
774 
775  StorageList::operator[](seg) &= mask;
776  StorageList::operator[](seg) |= ~mask & fill;
777  }
778  }
779 
780 
781  // Mask off the (new) final partial segment
782  {
783  const unsigned int off = size_ % packing();
784  if (off)
785  {
786  const unsigned int seg = size_ / packing();
787 
788  StorageList::operator[](seg) &= maskLower(off);
789  }
790  }
791  }
792  }
793  else if (size_ < oldSize)
794  {
795  // Resize shrinking
796  // - clear newly exposed elements
797 
798  // Fill in complete segments
799  const label oldLen = packedLength(oldSize);
800  const label newLen = packedLength(size_);
801  for (label i=newLen; i < oldLen; ++i)
802  {
803  StorageList::operator[](i) = 0u;
804  }
805 
806  // Mask off the final partial segment
807  {
808  const unsigned int off = size_ % packing();
809  if (off)
810  {
811  const unsigned int seg = size_ / packing();
812 
813  StorageList::operator[](seg) &= maskLower(off);
814  }
815  }
816  }
817 }
818 
819 
820 template<unsigned nBits>
822 (
823  const label newSize,
824  const unsigned int& val
825 )
826 {
827  resize(newSize, val);
828 }
829 
830 
831 
832 template<unsigned nBits>
834 {
835  return packing() * StorageList::size();
836 }
837 
838 
839 template<unsigned nBits>
841 {
843 
844  // Truncate addressed size too
845  if (size_ > nElem)
846  {
847  size_ = nElem;
848 
849  // Mask off the final partial segment
850  const unsigned int off = size_ % packing();
851  if (off)
852  {
853  const unsigned int seg = size_ / packing();
854 
855  StorageList::operator[](seg) &= maskLower(off);
856  }
857  }
858 }
859 
860 
861 template<unsigned nBits>
862 inline void Foam::PackedList<nBits>::reserve(const label nElem)
863 {
864  const label len = packedLength(nElem);
865 
866  // Need more capacity?
867  if (len > StorageList::size())
868  {
869  // Like DynamicList with SizeInc=0, SizeMult=2, SizeDiv=1
871  (
872  max
873  (
874  len,
876  ),
877  0u
878  );
879  }
880 }
881 
882 
883 template<unsigned nBits>
885 {
887 }
888 
889 
890 template<unsigned nBits>
892 {
893  reset();
894  size_ = 0;
895 }
896 
897 
898 template<unsigned nBits>
900 {
902  size_ = 0;
903 }
904 
905 
906 template<unsigned nBits>
908 {
909  // Any uneed space allocated?
910  const label len = packedLength();
911  if (len < StorageList::size())
912  {
914  }
915 }
916 
917 template<unsigned nBits>
919 {
920  return static_cast<StorageList&>(*this);
921 }
922 
923 
924 template<unsigned nBits>
926 {
927  return static_cast<const StorageList&>(*this);
928 }
929 
930 
931 template<unsigned nBits>
933 {
934  return packedLength(size_);
935 }
936 
937 
938 template<unsigned nBits>
939 inline std::streamsize Foam::PackedList<nBits>::byteSize() const
940 {
941  return packedLength() * sizeof(StorageType);
942 }
943 
944 
945 template<unsigned nBits>
947 {
948  size_ = lst.size_;
949  lst.size_ = 0;
950 
952 }
953 
954 
955 template<unsigned nBits>
957 {
958  return xferMove(*this);
959 }
960 
961 
962 template<unsigned nBits>
963 inline unsigned int Foam::PackedList<nBits>::get(const label i) const
964 {
965  // Lazy evaluation - return 0 for out-of-range
966  if (i < 0 || i >= size_)
967  {
968  return 0;
969  }
970  else
971  {
972  return iteratorBase(this, i).get();
973  }
974 }
975 
976 
977 template<unsigned nBits>
978 inline unsigned int Foam::PackedList<nBits>::operator[](const label i) const
979 {
980  // Lazy evaluation - return 0 for out-of-range
981  if (i < 0 || i >= size_)
982  {
983  return 0;
984  }
985  else
986  {
987  return iteratorBase(this, i).get();
988  }
989 }
990 
991 
992 template<unsigned nBits>
994 (
995  const label i,
996  const unsigned int val
997 )
998 {
999  if (i < 0)
1000  {
1001  // Lazy evaluation - ignore out-of-bounds
1002  return false;
1003  }
1004  else if (i >= size_)
1005  {
1006  // Lazy evaluation - increase size on assigment
1007  resize(i + 1);
1008  }
1009 
1010  return iteratorBase(this, i).set(val);
1011 }
1012 
1013 
1014 template<unsigned nBits>
1016 {
1017  // lazy evaluation - ignore out-of-bounds
1018  if (i < 0 || i >= size_)
1019  {
1020  return false;
1021  }
1022  else
1023  {
1024  return iteratorBase(this, i).set(0u);
1025  }
1026 }
1027 
1028 
1029 template<unsigned nBits>
1031 Foam::PackedList<nBits>::append(const unsigned int val)
1032 {
1033  const label elemI = size_;
1034  reserve(elemI + 1);
1035  size_++;
1036 
1037  iteratorBase(this, elemI).set(val);
1038  return *this;
1039 }
1040 
1041 
1042 template<unsigned nBits>
1043 inline unsigned int Foam::PackedList<nBits>::remove()
1044 {
1045  if (!size_)
1046  {
1048  << "List is empty" << abort(FatalError);
1049  }
1050 
1051  label elemI = size_ - 1;
1052  const unsigned int val = iteratorBase(this, elemI).get();
1053  resize(elemI);
1054 
1055  return val;
1056 }
1057 
1058 
1059 template<unsigned nBits>
1062 {
1063  return iteratorBase(this, i);
1064 }
1065 
1066 
1067 template<unsigned nBits>
1068 inline void Foam::PackedList<nBits>::operator=(const unsigned int val)
1069 {
1070  const label packLen = packedLength();
1071 
1072  if (val && size_)
1073  {
1074  unsigned int fill = val;
1075 
1076  if (val >= max_value())
1077  {
1078  // Fill everything
1079  fill = maskLower(packing());
1080  }
1081  else
1082  {
1083  for (unsigned int i = 1; i < packing(); ++i)
1084  {
1085  fill |= (fill << nBits);
1086  }
1087  }
1088 
1089  for (label i=0; i < packLen; ++i)
1090  {
1091  StorageList::operator[](i) = fill;
1092  }
1093 
1094  // Mask off the final partial segment
1095  {
1096  const unsigned int off = size_ % packing();
1097  if (off)
1098  {
1099  const unsigned int seg = size_ / packing();
1100 
1101  StorageList::operator[](seg) &= maskLower(off);
1102  }
1103  }
1104  }
1105  else
1106  {
1107  for (label i=0; i < packLen; ++i)
1108  {
1109  StorageList::operator[](i) = 0u;
1110  }
1111  }
1112 }
1113 
1114 
1115 // ************************************************************************* //
Istream & readBegin(const char *funcName)
Definition: Istream.C:86
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
const_iterator & operator--()
Definition: PackedListI.H:603
The iterator class used for PackedList.
Definition: PackedList.H:490
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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:978
unsigned int operator()() const
Return referenced value directly.
Definition: PackedListI.H:656
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:963
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:60
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:664
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:840
label index_
Element index.
Definition: PackedList.H:434
bool set(const label, const unsigned int val=~0u)
Set value at index I. Return true if value changed.
Definition: PackedListI.H:994
void reserve(const label)
Reserve allocation space for at least this size.
Definition: PackedListI.H:862
unsigned int remove()
Remove and return the last element.
Definition: PackedListI.H:1043
T * iterator
Random access iterator for traversing UList.
Definition: UList.H:272
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:153
std::streamsize byteSize() const
Return the binary size in number of characters.
Definition: PackedListI.H:939
void transfer(PackedList< nBits > &)
Transfer the contents of the argument list into this list.
Definition: PackedListI.H:946
iteratorBase()
Construct null.
Definition: PackedListI.H:269
Xfer< PackedList< nBits > > xfer()
Transfer contents to the Xfer container.
Definition: PackedListI.H:956
Istream & readEnd(const char *funcName)
Definition: Istream.C:103
label packedLength() const
The list length when packed.
Definition: PackedListI.H:932
A dynamically allocatable list of packed unsigned integers.
Definition: PackedList.H:117
Xfer< T > xferMove(T &)
Construct by transferring the contents of the arg.
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:1015
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:822
errorManip< error > abort(error &err)
Definition: errorManip.H:131
void clear()
Clear the list, i.e. set addressable size to zero.
Definition: PackedListI.H:891
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:61
Template-invariant bits for PackedList.
Definition: PackedList.H:130
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:728
PackedList< nBits > & append(const unsigned int val)
Append a value at the end of the list.
Definition: PackedListI.H:1031
The const_iterator for PackedList.
Definition: PackedList.H:558
The iterator base for PackedList.
Definition: PackedList.H:421
iterator end()
Iterator set to beyond the end of the PackedList.
Definition: PackedListI.H:688
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:918
void operator=(const unsigned int val)
Assignment of all entries to the given value. Takes linear time.
Definition: PackedListI.H:1068
#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:833
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:720
void clearStorage()
Clear the list and delete storage.
Definition: PackedListI.H:899
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:713
void reset()
Clear all bits.
Definition: PackedListI.H:884
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:704
void shrink()
Shrink the allocated space to what is actually used.
Definition: PackedListI.H:907
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:431
const_iterator & operator++()
Definition: PackedListI.H:565
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:680
Namespace for OpenFOAM.
unsigned int operator*() const
Return referenced value directly.
Definition: PackedListI.H:648
IOerror FatalIOError