/usr/include/deal.II/grid/filtered_iterator.h is in libdeal.ii-dev 6.3.1-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 | //---------------------------------------------------------------------------
// $Id: filtered_iterator.h 21358 2010-06-24 23:38:14Z bangerth $
// Version: $Name$
//
// Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010 by the deal.II authors
//
// This file is subject to QPL and may not be distributed
// without copyright and license information. Please refer
// to the file deal.II/doc/license.html for the text and
// further information on this license.
//
//---------------------------------------------------------------------------
#ifndef __deal2__filtered_iterator_h
#define __deal2__filtered_iterator_h
#include <base/config.h>
#include <base/exceptions.h>
#include <grid/tria_iterator_base.h>
DEAL_II_NAMESPACE_OPEN
/**
* In this namespace a number of classes is declared that may be used
* as filters in the FilteredIterator class. The filters either
* check for binary information (for example, the IteratorFilters::Active filter
* class checks whether the object pointed to is active), or for
* valued information by comparison with prescribed values (for
* example, the LevelEqualTo filter class checks whether the
* level of the object pointed to by the iterator under consideration
* is equal to a value that was given to the filter upon construction.
*
* For examples of use of these classes as well as requirements on
* filters see the general description of the FilteredIterator
* class.
*
* @ingroup Iterators
* @author Wolfgang Bangerth, 2002
*/
namespace IteratorFilters
{
/**
* Filter that evaluates to true if
* either the iterator points to an
* active object or an iterator
* past the end.
*
* @ingroup Iterators
*/
class Active
{
public:
/**
* Evaluate the iterator and
* return true if the object is
* active or past the end.
*/
template <class Iterator>
bool operator () (const Iterator &i) const;
};
/**
* Filter that evaluates to true if
* either the iterator points to an
* object for which the user flag
* is set or an iterator past the
* end.
*
* @ingroup Iterators
*/
class UserFlagSet
{
public:
/**
* Evaluate the iterator and
* return true if the object
* has a set user flag or past
* the end.
*/
template <class Iterator>
bool operator () (const Iterator &i) const;
};
/**
* Filter that evaluates to true if
* either the iterator points to an
* object for which the user flag
* is not set or an iterator past
* the end. Inverse filter to the
* previous class.
*
* @ingroup Iterators
*/
class UserFlagNotSet
{
public:
/**
* Evaluate the iterator and
* return true if the object
* has an unset user flag or
* past the end.
*/
template <class Iterator>
bool operator () (const Iterator &i) const;
};
/**
* Filter for iterators that
* evaluates to true if either the
* iterator is past the end or the
* level of the object pointed to
* is equal to a value given to the
* constructor.
*
* @ingroup Iterators
*/
class LevelEqualTo
{
public:
/**
* Constructor. Store the level
* which iterators shall have
* to be evaluated to true.
*/
LevelEqualTo (const unsigned int level);
/**
* Evaluation operator. Returns
* true if either the level of
* the object pointed to is
* equal to the stored value or
* the iterator is past the
* end.
*/
template <class Iterator>
bool operator () (const Iterator &i) const;
protected:
/**
* Stored value to compare the
* level with.
*/
const unsigned int level;
};
/**
* Filter for iterators that
* evaluates to true if either the
* iterator is past the end or the
* subdomain id of the object
* pointed to is equal to a value
* given to the constructor,
* assuming that the iterator
* allows querying for a subdomain
* id).
*
* @ingroup Iterators
*/
class SubdomainEqualTo
{
public:
/**
* Constructor. Store the
* subdomain which iterators
* shall have to be evaluated
* to true.
*/
SubdomainEqualTo (const unsigned int subdomain_id);
/**
* Evaluation operator. Returns
* true if either the subdomain
* of the object pointed to is
* equal to the stored value or
* the iterator is past the
* end.
*/
template <class Iterator>
bool operator () (const Iterator &i) const;
protected:
/**
* Stored value to compare the
* subdomain with.
*/
const unsigned int subdomain_id;
};
}
/**
* This class provides a certain view on a range of triangulation or
* DoFHandler iterators by only iterating over elements that satisfy a
* given filter (called a <em>predicate</em>, following the notation
* of the C++ standard library). Once initialized with a predicate and
* a value for the iterator, a filtered iterator hops to the next or
* previous element that satisfies the predicate if operators ++ or --
* are invoked. Intermediate iterator values that lie in between but
* do not satisfy the predicate are skipped. It is thus very simple to
* write loops over a certain class of objects without the need to
* explicitely write down the condition they have to satisfy in each
* loop iteration. This in particular is helpful if functions are
* called with a pair of iterators denoting a range on which they
* shall act, by choosing a filtered iterator instead of usual ones.
*
* This class is used in step-18.
*
*
* <h3>Predicates</h3>
*
* The object that represent the condition an iterator has to satisfy
* only have to provide an interface that allows to call the
* evaluation operator, i.e. <code>bool operator() (const
* BaseIterator&)</code>. This includes function pointers as well as
* classes that implement an <code>bool operator ()(const
* BaseIterator&)</code>. Then, the FilteredIterator will skip all
* objects where the return value of this function is <code>false</code>.
*
*
* An example of a simple valid predicate is the following: given the function
* @code
* template <typename BIterator>
* bool level_equal_to_3 (const BIterator& c)
* {
* return (static_cast<unsigned int>(c->level()) == 3);
* };
* @endcode
* then
* @code
* &level_equal_to_3<typename Triangulation<dim>::active_cell_iterator>
* @endcode
* is a valid predicate.
*
* Likewise, given the following binary function
* @code
* template <typename BIterator>
* bool level_equal_to (const BIterator& c,
* const unsigned int level)
* {
* return (static_cast<unsigned int>(c->level()) == level);
* };
* @endcode
* then
* @code
* std::bind2nd (std::ptr_fun(&level_equal_to<active_cell_iterator>), 3)
* @endcode
* is another valid predicate (here: a function that returns true if
* either the iterator is past the end or the level is equal to the
* second argument; this second argument is bound to a fixed value
* using the @p std::bind2nd function).
*
* Finally, classes can be predicates. The following class is one:
* @code
* class Active
* {
* public:
* template <class Iterator>
* bool operator () (const Iterator &i) const {
* return (i->active());
* }
* };
* @endcode
* and objects of this type can be used as predicates. Likewise, this
* more complicated one can also be used:
* @code
* class SubdomainEqualTo
* {
* public:
* SubdomainEqualTo (const unsigned int subdomain_id)
* : subdomain_id (subdomain_id) {};
*
* template <class Iterator>
* bool operator () (const Iterator &i) const {
* return (i->subdomain_id() == subdomain_id);
* }
*
* private:
* const unsigned int subdomain_id;
* };
* @endcode
* Objects like <code>SubdomainEqualTo(3)</code> can then be used as predicates.
*
* Since whenever a predicate is evaluated it is checked that the
* iterator checked is actually valid (i.e. not past the end), no
* checks for this case have to be performed inside predicates.
*
* A number of filter classes are already implemented in the
* IteratorFilters namespace, but writing different ones is
* simple following the examples above.
*
*
* <h3>Initialization of filtered iterators</h3>
*
* Filtered iterators are given a predicate at construction time which
* cannot be changed any more. This behaviour would be expected if the
* predicate would have been given as a template parameter to the
* class, but since that would make the declaration of filtered
* iterators a nightmare, we rather give the predicate as an
* unchangeable entity to the constructor. Note that one can assign a
* filtered iterator with one predicate to another filtered iterator
* with another type; yet, this does <em>not</em> change the predicate
* of the assigned-to iterator, only the pointer indicating the
* iterator is changed.
*
* If a filtered iterator is not assigned a value of the underlying
* (unfiltered) iterator type, the default value is taken. If,
* however, a value is given to the constructor, that value has either
* to be past the end, or has to satisfy the predicate. For example,
* if the predicate only evaluates to true if the level of an object
* is equal to three, then <code>tria.begin_active(3)</code> would be a valid
* choice while <code>tria.begin()</code> would not since the latter also
* returns iterators to non-active cells which always start at level
* 0.
*
* Since one often only has some iterator and wants to set a filtered
* iterator to the first one that satisfies a predicate (for example,
* the first one for which the user flag is set, or the first one with
* a given subdomain id), there are assignement functions
* #set_to_next_positive and #set_to_previous_positive that
* assign the next or last previous iterator that satisfies the
* predicate, i.e. they follow the list of iterators in either
* direction until they find a matching one (or the past-the-end
* iterator). Like the <code>operator=</code> they return the resulting value
* of the filtered iterator.
*
*
* <h3>Examples</h3>
*
* The following call counts the number of active cells that
* have a set user flag:
* @code
* FilteredIterator<typename Triangulation<dim>::active_cell_iterator>
* begin (IteratorFilters::UserFlagSet()),
* end (IteratorFilters::UserFlagSet());
* begin.set_to_next_positive(tria.begin_active());
* end = tria.end();
* n_flagged_cells = std::distance (begin, end);
* @endcode
* Note that by the @p set_to_next_positive call the first cell with
* a set user flag was assigned to the @p begin iterator. For the
* @{end} iterator, no such call was necessary, since the past-the-end
* iterator always satisfies all predicates.
*
* The same can be achieved by the following snippet, though harder to read:
* @code
* typedef FilteredIterator<typename Triangulation<dim>::active_cell_iterator> FI;
* n_flagged_cells =
* std::distance (FI(IteratorFilters::UserFlagSet())
* .set_to_next_positive(tria.begin_active()),
* FI(IteratorFilters::UserFlagSet(), tria.end()));
* @endcode
* It relies on the fact that if we create an unnamed filtered
* iterator with a given predicate but no iterator value and assign it
* the next positive value with respect to this predicate, it returns
* itself which is then used as the first parameter to the
* @p std::distance function. This procedure is not necessary for the
* end element to this function here, since the past-the-end iterator
* always satisfies the predicate so that we can assign this value to
* the filtered iterator directly in the constructor.
*
* Finally, the following loop only assembles the matrix on cells with
* subdomain id equal to three:
* @code
* FilteredIterator<typename Triangulation<dim>::active_cell_iterator>
* cell (IteratorFilters::SubdomainEqualTo(3)),
* endc (IteratorFilters::SubdomainEqualTo(3), tria.end());
* cell.set_to_next_positive (tria.begin_active());
* for (; cell!=endc; ++cell)
* assemble_local_matrix (cell);
* @endcode
*
* Since comparison between filtered and unfiltered iterators is
* defined, we could as well have let the @p endc variable in the
* last example be of type
* <code>Triangulation@<dim@>::active_cell_iterator</code> since it is unchanged
* and its value does not depend on the filter.
*
* @ingroup grid
* @ingroup Iterators
* @author Wolfgang Bangerth, 2002
*/
template <typename BaseIterator>
class FilteredIterator : public BaseIterator
{
public:
/**
* Typedef to the accessor type
* of the underlying iterator.
*/
typedef typename BaseIterator::AccessorType AccessorType;
/**
* Constructor. Set the iterator
* to the default state and use
* the given predicate for
* filtering subsequent
* assignement and iteration.
*/
template <typename Predicate>
FilteredIterator (Predicate p);
/**
* Constructor. Use the given
* predicate for filtering and
* initialize the iterator with
* the given value.
*
* If the initial value @p bi does
* not satisfy the predicate @p p
* then it is advanced until we
* either hit the the
* past-the-end iterator, or the
* predicate is satisfied. This
* allows, for example, to write
* code like
* @code
* FilteredIterator<typename Triangulation<dim>::active_cell_iterator>
* cell (IteratorFilters::SubdomainEqualTo(13),
* triangulation.begin_active());
* @endcode
*
* If the cell
* <code>triangulation.begin_active()</code>
* does not have a subdomain_id
* equal to 13, then the iterator
* will automatically be advanced
* to the first cell that has.
*/
template <typename Predicate>
FilteredIterator (Predicate p,
const BaseIterator &bi);
/**
* Copy constructor. Copy the
* predicate and iterator value
* of the given argument.
*/
FilteredIterator (const FilteredIterator &fi);
/**
* Destructor.
*/
~FilteredIterator ();
/**
* Assignment operator. Copy the
* iterator value of the
* argument, but as discussed in
* the class documentation, the
* predicate of the argument is
* not copied. The iterator value
* underlying the argument has to
* satisfy the predicate of the
* object assigned to, as given
* at its construction time.
*/
FilteredIterator & operator = (const FilteredIterator &fi);
/**
* Assignment operator. Copy the
* iterator value of the
* argument, and keep the
* predicate of this object. The
* given iterator value has to
* satisfy the predicate of the
* object assigned to, as given
* at its construction time.
*/
FilteredIterator & operator = (const BaseIterator &fi);
/**
* Search for the next iterator
* from @p bi onwards that
* satisfies the predicate of
* this object and assign it to
* this object.
*
* Since filtered iterators are
* automatically converted to the
* underlying base iterator type,
* you can also give a filtered
* iterator as argument to this
* function.
*/
FilteredIterator &
set_to_next_positive (const BaseIterator &bi);
/**
* As above, but search for the
* previous iterator from @p bi
* backwards that satisfies the
* predicate of this object and
* assign it to this object.
*
* Since filtered iterators are
* automatically converted to the
* underlying base iterator type,
* you can also give a filtered
* iterator as argument to this
* function.
*/
FilteredIterator &
set_to_previous_positive (const BaseIterator &bi);
/**
* Compare for equality of the
* underlying iterator values of
* this and the given object.
*
* We do not compare for equality
* of the predicates.
*/
bool operator == (const FilteredIterator &fi) const;
/**
* Compare for equality of the
* underlying iterator value of
* this object with the given
* object.
*
* The predicate of this object
* is irrelevant for this
* operation.
*/
bool operator == (const BaseIterator &fi) const;
/**
* Compare for inequality of the
* underlying iterator values of
* this and the given object.
*
* We do not compare for equality
* of the predicates.
*/
bool operator != (const FilteredIterator &fi) const;
/**
* Compare for inequality of the
* underlying iterator value of
* this object with the given
* object.
*
* The predicate of this object
* is irrelevant for this
* operation.
*/
bool operator != (const BaseIterator &fi) const;
/**
* Compare for ordering of the
* underlying iterator values of
* this and the given object.
*
* We do not compare the
* predicates.
*/
bool operator < (const FilteredIterator &fi) const;
/**
* Compare for ordering of the
* underlying iterator value of
* this object with the given
* object.
*
* The predicate of this object
* is irrelevant for this
* operation.
*/
bool operator < (const BaseIterator &fi) const;
/**
* Prefix advancement operator:
* move to the next iterator
* value satisfying the predicate
* and return the new iterator
* value.
*/
FilteredIterator & operator ++ ();
/**
* Postfix advancement operator:
* move to the next iterator
* value satisfying the predicate
* and return the old iterator
* value.
*/
FilteredIterator operator ++ (int);
/**
* Prefix decrement operator:
* move to the previous iterator
* value satisfying the predicate
* and return the new iterator
* value.
*/
FilteredIterator & operator -- ();
/**
* Postfix advancement operator:
* move to the previous iterator
* value satisfying the predicate
* and return the old iterator
* value.
*/
FilteredIterator operator -- (int);
/**
* Exception.
*/
DeclException1 (ExcInvalidElement,
BaseIterator,
<< "The element " << arg1
<< " with which you want to compare or which you want to"
<< " assign from is invalid since it does not satisfy the predicate.");
private:
/**
* Base class to encapsulate a
* predicate object. Since
* predicates can be of different
* types and we do not want to
* code these types into the
* template parameter list of the
* filtered iterator class, we
* use a base class with an
* abstract function and
* templatized derived classes
* that implement the use of
* actual predicate types through
* the virtual function.
*
* @ingroup Iterators
*/
class PredicateBase
{
public:
/**
* Mark the destructor
* virtual to allow
* destruction through
* pointers to the base
* class.
*/
virtual ~PredicateBase () {}
/**
* Abstract function which in
* derived classes denotes
* the evaluation of the
* predicate on the give
* iterator.
*/
virtual bool operator () (const BaseIterator &bi) const = 0;
/**
* Generate a copy of this
* object, i.e. of the actual
* type of this pointer.
*/
virtual PredicateBase * clone () const = 0;
};
/**
* Actual implementation of the
* above abstract base class. Use
* a template parameter to denote
* the actual type of the
* predicate and store a copy of
* it. When the virtual function
* is called evaluate the given
* iterator with the stored copy
* of the predicate.
*
* @ingroup Iterators
*/
template <typename Predicate>
class PredicateTemplate : public PredicateBase
{
public:
/**
* Constructor. Take a
* predicate and store a copy
* of it.
*/
PredicateTemplate (const Predicate &predicate);
/**
* Evaluate the iterator with
* the stored copy of the
* predicate.
*/
virtual bool operator () (const BaseIterator &bi) const;
/**
* Generate a copy of this
* object, i.e. of the actual
* type of this pointer.
*/
virtual PredicateBase * clone () const;
private:
/**
* Copy of the predicate.
*/
const Predicate predicate;
};
/**
* Pointer to an object that
* encapsulated the actual data
* type of the predicate given to
* the constructor.
*/
const PredicateBase * predicate;
#ifdef DEAL_II_NESTED_CLASS_FRIEND_BUG
# ifdef DEAL_II_NESTED_CLASS_TEMPL_FRIEND_BUG
template <typename> friend class PredicateTemplate;
# else
template <typename T>
template <typename>
friend class FilteredIterator<T>::PredicateTemplate;
# endif
#endif
};
/**
* Create an object of type FilteredIterator given the base iterator
* and predicate. This function makes the creation of temporary
* objects (for example as function arguments) a lot simpler because
* one does not have to explicitly specify the type of the base
* iterator by hand -- it is deduced automatically here.
*
* @author Wolfgang Bangerth
* @relates FilteredIterator
*/
template <typename BaseIterator, typename Predicate>
FilteredIterator<BaseIterator>
make_filtered_iterator (const BaseIterator &i,
const Predicate &p)
{
FilteredIterator<BaseIterator> fi(p);
fi.set_to_next_positive (i);
return fi;
}
/* ------------------ Inline functions and templates ------------ */
template <typename BaseIterator>
template <typename Predicate>
inline
FilteredIterator<BaseIterator>::
FilteredIterator (Predicate p)
:
predicate (new PredicateTemplate<Predicate>(p))
{}
template <typename BaseIterator>
template <typename Predicate>
inline
FilteredIterator<BaseIterator>::
FilteredIterator (Predicate p,
const BaseIterator &bi)
:
BaseIterator (bi),
predicate (new PredicateTemplate<Predicate>(p))
{
if ((this->state() == IteratorState::valid) &&
! (*predicate) (*this))
set_to_next_positive (bi);
}
template <typename BaseIterator>
inline
FilteredIterator<BaseIterator>::
FilteredIterator (const FilteredIterator &fi)
:
BaseIterator (static_cast<BaseIterator>(fi)),
predicate (fi.predicate->clone ())
{}
template <typename BaseIterator>
inline
FilteredIterator<BaseIterator>::
~FilteredIterator ()
{
delete predicate;
predicate = 0;
}
template <typename BaseIterator>
inline
FilteredIterator<BaseIterator> &
FilteredIterator<BaseIterator>::
operator = (const FilteredIterator &fi)
{
Assert ((fi.state() != IteratorState::valid) || (*predicate)(fi),
ExcInvalidElement(fi));
BaseIterator::operator = (fi);
return *this;
}
template <typename BaseIterator>
inline
FilteredIterator<BaseIterator> &
FilteredIterator<BaseIterator>::
operator = (const BaseIterator &bi)
{
Assert ((bi.state() != IteratorState::valid) || (*predicate)(bi),
ExcInvalidElement(bi));
BaseIterator::operator = (bi);
return *this;
}
template <typename BaseIterator>
inline
FilteredIterator<BaseIterator> &
FilteredIterator<BaseIterator>::
set_to_next_positive (const BaseIterator &bi)
{
BaseIterator::operator = (bi);
while ((this->state() == IteratorState::valid) &&
( ! (*predicate)(*this)))
BaseIterator::operator++ ();
return *this;
}
template <typename BaseIterator>
inline
FilteredIterator<BaseIterator> &
FilteredIterator<BaseIterator>::
set_to_previous_positive (const BaseIterator &bi)
{
BaseIterator::operator = (bi);
while ((this->state() == IteratorState::valid) &&
( ! (*predicate)(*this)))
BaseIterator::operator-- ();
return *this;
}
template <typename BaseIterator>
inline
bool
FilteredIterator<BaseIterator>::
operator == (const FilteredIterator &fi) const
{
return (static_cast<const BaseIterator &>(*this)
==
static_cast<const BaseIterator &>(fi));
}
template <typename BaseIterator>
inline
bool
FilteredIterator<BaseIterator>::
operator != (const FilteredIterator &fi) const
{
return (static_cast<const BaseIterator &>(*this)
!=
static_cast<const BaseIterator &>(fi));
}
template <typename BaseIterator>
inline
bool
FilteredIterator<BaseIterator>::
operator < (const FilteredIterator &fi) const
{
return (static_cast<const BaseIterator &>(*this)
<
static_cast<const BaseIterator &>(fi));
}
template <typename BaseIterator>
inline
bool
FilteredIterator<BaseIterator>::
operator == (const BaseIterator &bi) const
{
return (static_cast<const BaseIterator &>(*this) == bi);
}
template <typename BaseIterator>
inline
bool
FilteredIterator<BaseIterator>::
operator != (const BaseIterator &bi) const
{
return (static_cast<const BaseIterator &>(*this) != bi);
}
template <typename BaseIterator>
inline
bool
FilteredIterator<BaseIterator>::
operator < (const BaseIterator &bi) const
{
return (static_cast<const BaseIterator &>(*this) < bi);
}
template <typename BaseIterator>
inline
FilteredIterator<BaseIterator> &
FilteredIterator<BaseIterator>::
operator ++ ()
{
if (this->state() == IteratorState::valid)
do
BaseIterator::operator++ ();
while ((this->state() == IteratorState::valid) &&
!(*predicate) (*this));
return *this;
}
template <typename BaseIterator>
inline
FilteredIterator<BaseIterator>
FilteredIterator<BaseIterator>::
operator ++ (int)
{
const FilteredIterator old_state = *this;
if (this->state() == IteratorState::valid)
do
BaseIterator::operator++ ();
while ((this->state() == IteratorState::valid) &&
!(*predicate) (*this));
return old_state;
}
template <typename BaseIterator>
inline
FilteredIterator<BaseIterator> &
FilteredIterator<BaseIterator>::
operator -- ()
{
if (this->state() == IteratorState::valid)
do
BaseIterator::operator-- ();
while ((this->state() == IteratorState::valid) &&
!(*predicate) (*this));
return *this;
}
template <typename BaseIterator>
inline
FilteredIterator<BaseIterator>
FilteredIterator<BaseIterator>::
operator -- (int)
{
const FilteredIterator old_state = *this;
if (this->state() == IteratorState::valid)
do
BaseIterator::operator-- ();
while ((this->state() == IteratorState::valid) &&
!(*predicate) (*this));
return old_state;
}
template <typename BaseIterator>
template <typename Predicate>
inline
FilteredIterator<BaseIterator>::PredicateTemplate<Predicate>::
PredicateTemplate (const Predicate &predicate)
:
predicate (predicate)
{}
template <typename BaseIterator>
template <typename Predicate>
bool
FilteredIterator<BaseIterator>::PredicateTemplate<Predicate>::
operator () (const BaseIterator &bi) const
{
return predicate(bi);
}
template <typename BaseIterator>
template <typename Predicate>
typename FilteredIterator<BaseIterator>::PredicateBase *
FilteredIterator<BaseIterator>::PredicateTemplate<Predicate>::
clone () const
{
return new PredicateTemplate (predicate);
}
namespace IteratorFilters
{
// ---------------- IteratorFilters::Active ---------
template <class Iterator>
inline
bool
Active::operator () (const Iterator &i) const
{
return (i->active());
}
// ---------------- IteratorFilters::UserFlagSet ---------
template <class Iterator>
inline
bool
UserFlagSet::operator () (const Iterator &i) const
{
return (i->user_flag_set());
}
// ---------------- IteratorFilters::UserFlagNotSet ---------
template <class Iterator>
inline
bool
UserFlagNotSet::operator () (const Iterator &i) const
{
return (! i->user_flag_set());
}
// ---------------- IteratorFilters::LevelEqualTo ---------
inline
LevelEqualTo::LevelEqualTo (const unsigned int level)
:
level (level)
{}
template <class Iterator>
inline
bool
LevelEqualTo::operator () (const Iterator &i) const
{
return (static_cast<unsigned int>(i->level()) == level);
}
// ---------------- IteratorFilters::SubdomainEqualTo ---------
inline
SubdomainEqualTo::SubdomainEqualTo (const unsigned int subdomain_id)
:
subdomain_id (subdomain_id)
{}
template <class Iterator>
inline
bool
SubdomainEqualTo::operator () (const Iterator &i) const
{
return (static_cast<unsigned int>(i->subdomain_id()) == subdomain_id);
}
}
DEAL_II_NAMESPACE_CLOSE
/*------------------------- filtered_iterator.h ------------------------*/
#endif
/*------------------------- filtered_iterator.h ------------------------*/
|