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