Reference documentation for deal.II version 8.4.2
tria_iterator.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1998 - 2016 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii__tria_iterator_h
17 #define dealii__tria_iterator_h
18 
19 
20 /*---------------------------- tria-iterator.h ---------------------------*/
21 
22 
23 #include <deal.II/base/config.h>
24 #include <deal.II/base/exceptions.h>
25 
26 #include <deal.II/base/point.h>
27 #include <deal.II/grid/tria_iterator_base.h>
28 
29 #include <iterator>
30 
31 #include <ostream>
32 
33 DEAL_II_NAMESPACE_OPEN
34 
35 template <int dim, int spacedim> class Triangulation;
36 template <int, int, int> class TriaAccessorBase;
37 
38 template <typename> class TriaRawIterator;
39 template <typename> class TriaIterator;
40 template <typename> class TriaActiveIterator;
41 
42 
43 
44 // note: in non-debug mode, i.e. with optimizations, the file
45 // tria_iterator.templates.h is included at the end of this file.
46 // this includes a lot of templates and thus makes compilation
47 // slower, but at the same time allows for more aggressive
48 // inlining and thus faster code.
49 
50 
225 template <typename Accessor>
226 class TriaRawIterator : public std::iterator<std::bidirectional_iterator_tag,Accessor>
227 {
228 public:
234  typedef Accessor AccessorType;
235 
239  TriaRawIterator ();
240 
245 
259  explicit TriaRawIterator (const Accessor &a);
260 
265  template <typename OtherAccessor>
266  explicit TriaRawIterator (const OtherAccessor &a);
267 
274  const int level,
275  const int index,
276  const typename AccessorType::AccessorData *local_data = 0);
277 
287  template <typename OtherAccessor>
289 
296  const typename Accessor::AccessorData *local_data);
297 
302  template <typename OtherAccessor>
304 
309  template <typename OtherAccessor>
311 
328  const Accessor &operator * () const;
329 
333  Accessor &operator * ();
334 
341  const Accessor *operator -> () const;
342 
346  Accessor *operator -> ();
347 
348 
358  const Accessor &access_any () const;
359 
366 
370 // template <class OtherAccessor>
371 // TriaRawIterator & operator = (const TriaRawIterator<OtherAccessor>&);
372 
376 // template <class OtherAccessor>
377 // TriaRawIterator & operator = (const TriaIterator<OtherAccessor>&);
378 
382 // template <class OtherAccessor>
383 // TriaRawIterator & operator = (const TriaActiveIterator<OtherAccessor>&);
384 
388  bool operator == (const TriaRawIterator &) const;
389 
393  bool operator != (const TriaRawIterator &) const;
394 
420  bool operator < (const TriaRawIterator &) const;
421 
426  bool operator > (const TriaRawIterator &) const;
427 
436 
449 
455 
471 
476  template <class StreamType>
477  void print (StreamType &out) const;
478 
479 
484  std::size_t memory_consumption () const;
485 
486 
492  DeclException1 (ExcDereferenceInvalidCell,
493  Accessor,
494  << "You tried to dereference a cell iterator for which this "
495  << "is not possible. More information on this iterator: "
496  << "level=" << arg1.level()
497  << ", index=" << arg1.index()
498  << ", state="
499  << (arg1.state() == IteratorState::valid ? "valid" :
500  (arg1.state() == IteratorState::past_the_end ?
501  "past_the_end" : "invalid")));
502 
507  DeclException1 (ExcDereferenceInvalidObject,
508  Accessor,
509  << "You tried to dereference an iterator for which this "
510  << "is not possible. More information on this iterator: "
511  << "index=" << arg1.index()
512  << ", state="
513  << (arg1.state() == IteratorState::valid ? "valid" :
514  (arg1.state() == IteratorState::past_the_end ?
515  "past_the_end" : "invalid")));
516 
520  DeclException0 (ExcAdvanceInvalidObject);
524  DeclException0 (ExcInvalidComparison);
525 
527 protected:
531  Accessor accessor;
532 
533 
543  template <typename SomeAccessor> friend class TriaRawIterator;
544  template <typename SomeAccessor> friend class TriaIterator;
545  template <typename SomeAccessor> friend class TriaActiveIterator;
546 };
547 
548 
556 template <typename Accessor>
557 class TriaIterator : public TriaRawIterator<Accessor>
558 {
559 public:
563  TriaIterator ();
564 
569 
578 
588  const int level,
589  const int index,
590  const typename Accessor::AccessorData *local_data = 0);
591 
596  template <typename OtherAccessor>
597  explicit TriaIterator (const OtherAccessor &a);
598 
608  template <typename OtherAccessor>
610 
617  const typename Accessor::AccessorData *local_data);
618 
624  template <typename OtherAccessor>
626 
631  template <typename OtherAccessor>
633 
639 
646 
651  template <class OtherAccessor>
654 
660  template <class OtherAccessor>
663 
672 
683 
689 
699  DeclException0 (ExcAssignmentOfUnusedObject);
700 };
701 
702 
712 template <typename Accessor>
713 class TriaActiveIterator : public TriaIterator<Accessor>
714 {
715 public:
720 
725 
734 
743 
753  const int level,
754  const int index,
755  const typename Accessor::AccessorData *local_data = 0);
756 
766  template <typename OtherAccessor>
768 
775  const typename Accessor::AccessorData *local_data);
776 
784  template <typename OtherAccessor>
786 
792 
799 
806 
811  template <class OtherAccessor>
814 
820  template <class OtherAccessor>
823 
829  template <class OtherAccessor>
832 
839 
852 
858 
868  DeclException0 (ExcAssignmentOfInactiveObject);
869 };
870 
871 
872 /*----------------------- Inline functions -------------------*/
873 
874 
875 template <typename Accessor>
876 inline
878 TriaRawIterator (const Accessor &a)
879  :
880  accessor (a)
881 {}
882 
883 
884 
885 template <typename Accessor>
886 template <typename OtherAccessor>
887 inline
889 TriaRawIterator (const OtherAccessor &a)
890  :
891  accessor (a)
892 {}
893 
894 
895 
896 template <typename Accessor>
897 template <typename OtherAccessor>
898 inline
901  :
902  accessor (i.accessor)
903 {}
904 
905 
906 
907 template <typename Accessor>
908 template <typename OtherAccessor>
909 inline
912  :
913  accessor (i.accessor)
914 {}
915 
916 
917 
918 template <typename Accessor>
919 template <typename OtherAccessor>
920 inline
923  :
924  accessor (i.accessor)
925 {}
926 
927 
928 
929 template <typename Accessor>
930 inline
931 const Accessor &
933 {
934  Assert (Accessor::structure_dimension!=Accessor::dimension ||
936  ExcDereferenceInvalidCell(accessor));
937  Assert (Accessor::structure_dimension==Accessor::dimension ||
939  ExcDereferenceInvalidObject(accessor));
940 
941  return accessor;
942 }
943 
944 
945 
946 template <typename Accessor>
947 inline
948 Accessor &
950 {
951  Assert (Accessor::structure_dimension!=Accessor::dimension ||
953  ExcDereferenceInvalidCell(accessor));
954  Assert (Accessor::structure_dimension==Accessor::dimension ||
956  ExcDereferenceInvalidObject(accessor));
957 
958  return accessor;
959 }
960 
961 
962 
963 template <typename Accessor>
964 inline
965 const Accessor &
967 {
968  return accessor;
969 }
970 
971 
972 
973 template <typename Accessor>
974 inline
975 const Accessor *
977 {
978  return &(this->operator* ());
979 }
980 
981 
982 
983 template <typename Accessor>
984 inline
985 Accessor *
987 {
988  return &(this->operator* ());
989 }
990 
991 
992 
993 template <typename Accessor>
994 inline
997 {
998  return accessor.state ();
999 }
1000 
1001 
1002 
1003 template <typename Accessor>
1004 inline
1005 bool
1007 {
1008  Assert (state() != IteratorState::invalid, ExcDereferenceInvalidObject(accessor));
1009  Assert (other.state() != IteratorState::invalid, ExcDereferenceInvalidObject(other.accessor));
1010 
1011  Assert (&accessor.get_triangulation() == &other.accessor.get_triangulation(),
1012  ExcInvalidComparison());
1013 
1014  // Deal with iterators past end
1016  return false;
1017  if (other.state()==IteratorState::past_the_end)
1018  return true;
1019 
1020  return ((**this) < (*other));
1021 }
1022 
1023 
1024 
1025 template <typename Accessor>
1026 inline
1027 bool
1029 {
1030  return (other < *this);
1031 }
1032 
1033 
1034 
1035 template <typename Accessor>
1036 inline
1039 {
1040  Assert (state() == IteratorState::valid, ExcAdvanceInvalidObject());
1041 
1042  ++accessor;
1043  return *this;
1044 }
1045 
1046 
1047 
1048 template <typename Accessor>
1049 inline
1052 {
1053  Assert (state() == IteratorState::valid, ExcAdvanceInvalidObject());
1054 
1055  --accessor;
1056  return *this;
1057 }
1058 
1059 
1060 
1061 template <typename Accessor>
1062 template <class StreamType>
1063 inline
1064 void
1065 TriaRawIterator<Accessor>::print (StreamType &out) const
1066 {
1067  if (Accessor::structure_dimension==Accessor::dimension)
1068  out << accessor.level() << "." << accessor.index();
1069  else
1070  out << accessor.index();
1071 }
1072 
1073 
1074 
1075 template <typename Accessor>
1076 inline
1077 std::size_t
1079 {
1080  return sizeof(TriaRawIterator<Accessor>);
1081 }
1082 
1083 
1084 
1085 template <typename Accessor>
1086 template <typename OtherAccessor>
1087 inline
1089  :
1090  TriaRawIterator<Accessor> (i.accessor)
1091 {}
1092 
1093 
1094 
1095 template <typename Accessor>
1096 template <typename OtherAccessor>
1097 inline
1099  :
1100  TriaRawIterator<Accessor> (i.accessor)
1101 {}
1102 
1103 
1104 
1105 template <typename Accessor>
1106 template <typename OtherAccessor>
1107 inline
1109  :
1110  TriaRawIterator<Accessor> (i.accessor)
1111 {
1112 #ifdef DEBUG
1113  // do this like this, because:
1114  // if we write
1115  // "Assert (IteratorState::past_the_end || used)"
1116  // used() is called anyway, even if
1117  // state==IteratorState::past_the_end, and will then
1118  // throw the exception!
1119  if (this->state() != IteratorState::past_the_end)
1120  Assert (this->accessor.used(),
1121  ExcAssignmentOfUnusedObject());
1122 #endif
1123 }
1124 
1125 template <typename Accessor>
1126 template <typename OtherAccessor>
1128  :
1129  TriaRawIterator<Accessor> (a)
1130 {
1131 #ifdef DEBUG
1132  // do this like this, because:
1133  // if we write
1134  // "Assert (IteratorState::past_the_end || used)"
1135  // used() is called anyway, even if
1136  // state==IteratorState::past_the_end, and will then
1137  // throw the exception!
1138  if (this->state() != IteratorState::past_the_end)
1139  Assert (this->accessor.used(),
1140  ExcAssignmentOfUnusedObject());
1141 #endif
1142 }
1143 
1144 template <typename Accessor>
1145 template <typename OtherAccessor>
1146 inline
1148  :
1149  TriaIterator<Accessor> (i.accessor)
1150 {}
1151 
1152 
1153 
1154 template <typename Accessor>
1155 template <typename OtherAccessor>
1156 inline
1158  :
1159  TriaIterator<Accessor> (i)
1160 {
1161 #ifdef DEBUG
1162  // do this like this, because:
1163  // if we write
1164  // "Assert (IteratorState::past_the_end || !has_children())"
1165  // has_children() is called anyway, even if
1166  // state==IteratorState::past_the_end, and will then
1167  // throw the exception!
1168  if (this->state() != IteratorState::past_the_end)
1169  Assert (this->accessor.has_children()==false,
1170  ExcAssignmentOfInactiveObject());
1171 #endif
1172 }
1173 
1174 
1175 
1183 template <typename Accessor>
1184 inline
1185 std::ostream &operator << (std::ostream &out,
1186  const TriaRawIterator<Accessor> &i)
1187 {
1188  i.print(out);
1189  return out;
1190 }
1191 
1192 
1193 
1201 template <typename Accessor>
1202 inline
1203 std::ostream &operator << (std::ostream &out,
1204  const TriaIterator<Accessor> &i)
1205 {
1206  i.print(out);
1207  return out;
1208 }
1209 
1210 
1211 
1219 template <typename Accessor>
1220 inline
1221 std::ostream &operator << (std::ostream &out,
1223 {
1224  i.print(out);
1225  return out;
1226 }
1227 
1228 
1229 DEAL_II_NAMESPACE_CLOSE
1230 
1231 
1232 // if in optimized mode: include more templates
1233 #ifndef DEBUG
1234 # include "tria_iterator.templates.h"
1235 #endif
1236 
1237 
1238 /*---------------------------- tria-iterator.h ---------------------------*/
1239 #endif
1240 /*---------------------------- tria-iterator.h ---------------------------*/
Accessor AccessorType
Iterator is invalid, probably due to an error.
const Accessor * operator->() const
const Accessor & operator*() const
bool operator>(const TriaRawIterator &) const
#define Assert(cond, exc)
Definition: exceptions.h:294
TriaRawIterator & operator++()
bool operator==(const TriaRawIterator &) const
bool operator!=(const TriaRawIterator &) const
TriaRawIterator & operator--()
DeclException0(ExcAdvanceInvalidObject)
TriaRawIterator & operator=(const TriaRawIterator &)
Iterator reached end of container.
const Accessor & access_any() const
Iterator points to a valid object.
void print(StreamType &out) const
IteratorState::IteratorStates state() const
DeclException1(ExcDereferenceInvalidCell, Accessor,<< "You tried to dereference a cell iterator for which this "<< "is not possible. More information on this iterator: "<< "level="<< arg1.level()<< ", index="<< arg1.index()<< ", state="<<(arg1.state()==IteratorState::valid ? "valid" :(arg1.state()==IteratorState::past_the_end ? "past_the_end" :"invalid")))
StreamType & operator<<(StreamType &s, UpdateFlags u)
bool operator<(const TriaRawIterator &) const
std::size_t memory_consumption() const