00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __deal2__table_indices_h
00013 #define __deal2__table_indices_h
00014
00015
00016 #include <deal.II/base/config.h>
00017 #include <deal.II/base/exceptions.h>
00018
00019
00020
00021 #ifdef HAVE_STD_OSTREAM_HEADER
00022 # include <ostream>
00023 #else
00024 # include <iostream>
00025 #endif
00026
00027
00028
00029 DEAL_II_NAMESPACE_OPEN
00030
00031
00041 template <int N>
00042 class TableIndicesBase
00043 {
00044 public:
00049 unsigned int operator[] (const unsigned int i) const;
00050
00055 bool operator == (const TableIndicesBase<N> &other) const;
00056
00061 bool operator != (const TableIndicesBase<N> &other) const;
00062
00069 void sort ();
00070
00075 template <class Archive>
00076 void serialize (Archive & ar, const unsigned int version);
00077
00078 protected:
00082 unsigned indices[N];
00083 };
00084
00085
00101 template <int N>
00102 class TableIndices
00103 {
00108 TableIndices();
00115 TableIndices(...);
00116 };
00117
00118
00119
00133 template <>
00134 class TableIndices<1> : public TableIndicesBase<1>
00135 {
00136 public:
00141 TableIndices ();
00142
00147 TableIndices (const unsigned int index1);
00148 };
00149
00150
00151
00164 template <>
00165 class TableIndices<2> : public TableIndicesBase<2>
00166 {
00167 public:
00172 TableIndices ();
00173
00189 TableIndices (const unsigned int index1,
00190 const unsigned int index2 = numbers::invalid_unsigned_int);
00191 };
00192
00193
00194
00207 template <>
00208 class TableIndices<3> : public TableIndicesBase<3>
00209 {
00210 public:
00215 TableIndices ();
00216
00232 TableIndices (const unsigned int index1,
00233 const unsigned int index2 = numbers::invalid_unsigned_int,
00234 const unsigned int index3 = numbers::invalid_unsigned_int);
00235 };
00236
00237
00250 template <>
00251 class TableIndices<4> : public TableIndicesBase<4>
00252 {
00253 public:
00258 TableIndices ();
00259
00275 TableIndices (const unsigned int index1,
00276 const unsigned int index2 = numbers::invalid_unsigned_int,
00277 const unsigned int index3 = numbers::invalid_unsigned_int,
00278 const unsigned int index4 = numbers::invalid_unsigned_int);
00279 };
00280
00281
00294 template <>
00295 class TableIndices<5> : public TableIndicesBase<5>
00296 {
00297 public:
00302 TableIndices ();
00303
00319 TableIndices (const unsigned int index1,
00320 const unsigned int index2 = numbers::invalid_unsigned_int,
00321 const unsigned int index3 = numbers::invalid_unsigned_int,
00322 const unsigned int index4 = numbers::invalid_unsigned_int,
00323 const unsigned int index5 = numbers::invalid_unsigned_int);
00324 };
00325
00326
00339 template <>
00340 class TableIndices<6> : public TableIndicesBase<6>
00341 {
00342 public:
00347 TableIndices ();
00348
00364 TableIndices (const unsigned int index1,
00365 const unsigned int index2 = numbers::invalid_unsigned_int,
00366 const unsigned int index3 = numbers::invalid_unsigned_int,
00367 const unsigned int index4 = numbers::invalid_unsigned_int,
00368 const unsigned int index5 = numbers::invalid_unsigned_int,
00369 const unsigned int index6 = numbers::invalid_unsigned_int);
00370 };
00371
00372
00385 template <>
00386 class TableIndices<7> : public TableIndicesBase<7>
00387 {
00388 public:
00393 TableIndices ();
00394
00410 TableIndices (const unsigned int index1,
00411 const unsigned int index2 = numbers::invalid_unsigned_int,
00412 const unsigned int index3 = numbers::invalid_unsigned_int,
00413 const unsigned int index4 = numbers::invalid_unsigned_int,
00414 const unsigned int index5 = numbers::invalid_unsigned_int,
00415 const unsigned int index6 = numbers::invalid_unsigned_int,
00416 const unsigned int index7 = numbers::invalid_unsigned_int);
00417 };
00418
00419
00420
00421
00422
00423 template <int N>
00424 inline
00425 unsigned int
00426 TableIndicesBase<N>::operator [] (const unsigned int i) const
00427 {
00428 Assert (i < N, ExcIndexRange (i, 0, N));
00429 return indices[i];
00430 }
00431
00432
00433
00434 template <int N>
00435 inline
00436 bool
00437 TableIndicesBase<N>::operator == (const TableIndicesBase<N> &other) const
00438 {
00439 for (unsigned int i=0; i<N; ++i)
00440 if (indices[i] != other.indices[i])
00441 return false;
00442 return true;
00443 }
00444
00445
00446
00447 template <int N>
00448 inline
00449 bool
00450 TableIndicesBase<N>::operator != (const TableIndicesBase<N> &other) const
00451 {
00452 return !(*this == other);
00453 }
00454
00455
00456
00457 template <int N>
00458 template <class Archive>
00459 inline
00460 void
00461 TableIndicesBase<N>::serialize (Archive & ar, const unsigned int)
00462 {
00463 ar & indices;
00464 }
00465
00466
00467
00468 template <>
00469 inline
00470 void
00471 TableIndicesBase<1>::sort ()
00472 {}
00473
00474
00475
00476 template <>
00477 inline
00478 void
00479 TableIndicesBase<2>::sort ()
00480 {
00481 if (indices[1] < indices[0])
00482 std::swap (indices[0], indices[1]);
00483 }
00484
00485
00486
00487 template <>
00488 inline
00489 void
00490 TableIndicesBase<3>::sort ()
00491 {
00492
00493 if (indices[1] < indices[0])
00494 std::swap (indices[0], indices[1]);
00495 if (indices[2] < indices[1])
00496 std::swap (indices[1], indices[2]);
00497 if (indices[1] < indices[0])
00498 std::swap (indices[0], indices[1]);
00499 }
00500
00501
00502
00503
00504 inline
00505 TableIndices<1>::TableIndices ()
00506 {
00507 this->indices[0] = 0;
00508 }
00509
00510
00511
00512 inline
00513 TableIndices<1>::TableIndices (const unsigned int index1)
00514 {
00515 this->indices[0] = index1;
00516 }
00517
00518
00519
00520 inline
00521 TableIndices<2>::TableIndices ()
00522 {
00523 this->indices[0] = this->indices[1] = 0;
00524 }
00525
00526
00527
00528 inline
00529 TableIndices<2>::TableIndices (const unsigned int index1,
00530 const unsigned int index2)
00531 {
00532 this->indices[0] = index1;
00533 this->indices[1] = index2;
00534 }
00535
00536
00537
00538 inline
00539 TableIndices<3>::TableIndices ()
00540 {
00541 this->indices[0] = this->indices[1] = this->indices[2] = 0;
00542 }
00543
00544
00545
00546 inline
00547 TableIndices<3>::TableIndices (const unsigned int index1,
00548 const unsigned int index2,
00549 const unsigned int index3)
00550 {
00551 this->indices[0] = index1;
00552 this->indices[1] = index2;
00553 this->indices[2] = index3;
00554 }
00555
00556
00557
00558 inline
00559 TableIndices<4>::TableIndices ()
00560 {
00561 this->indices[0] = this->indices[1] = this->indices[2] = this->indices[3] = 0;
00562 }
00563
00564
00565
00566 inline
00567 TableIndices<4>::TableIndices (const unsigned int index1,
00568 const unsigned int index2,
00569 const unsigned int index3,
00570 const unsigned int index4)
00571 {
00572 this->indices[0] = index1;
00573 this->indices[1] = index2;
00574 this->indices[2] = index3;
00575 this->indices[3] = index4;
00576 }
00577
00578
00579
00580 inline
00581 TableIndices<5>::TableIndices ()
00582 {
00583 this->indices[0] = this->indices[1]
00584 = this->indices[2]
00585 = this->indices[3]
00586 = this->indices[4] = 0;
00587 }
00588
00589
00590
00591 inline
00592 TableIndices<5>::TableIndices (const unsigned int index1,
00593 const unsigned int index2,
00594 const unsigned int index3,
00595 const unsigned int index4,
00596 const unsigned int index5)
00597 {
00598 this->indices[0] = index1;
00599 this->indices[1] = index2;
00600 this->indices[2] = index3;
00601 this->indices[3] = index4;
00602 this->indices[4] = index5;
00603 }
00604
00605
00606
00607 inline
00608 TableIndices<6>::TableIndices ()
00609 {
00610 this->indices[0] = this->indices[1] = this->indices[2]
00611 = this->indices[3] = this->indices[4]
00612 = this->indices[5] = 0;
00613 }
00614
00615
00616
00617 inline
00618 TableIndices<6>::TableIndices (const unsigned int index1,
00619 const unsigned int index2,
00620 const unsigned int index3,
00621 const unsigned int index4,
00622 const unsigned int index5,
00623 const unsigned int index6)
00624 {
00625 this->indices[0] = index1;
00626 this->indices[1] = index2;
00627 this->indices[2] = index3;
00628 this->indices[3] = index4;
00629 this->indices[4] = index5;
00630 this->indices[5] = index6;
00631 }
00632
00633
00634
00635 inline
00636 TableIndices<7>::TableIndices ()
00637 {
00638 this->indices[0] = this->indices[1] = this->indices[2]
00639 = this->indices[3] = this->indices[4]
00640 = this->indices[5] = this->indices[6] = 0;
00641 }
00642
00643
00644
00645 inline
00646 TableIndices<7>::TableIndices (const unsigned int index1,
00647 const unsigned int index2,
00648 const unsigned int index3,
00649 const unsigned int index4,
00650 const unsigned int index5,
00651 const unsigned int index6,
00652 const unsigned int index7)
00653 {
00654 this->indices[0] = index1;
00655 this->indices[1] = index2;
00656 this->indices[2] = index3;
00657 this->indices[3] = index4;
00658 this->indices[4] = index5;
00659 this->indices[5] = index6;
00660 this->indices[6] = index7;
00661 }
00662
00663
00664
00669 template <int N>
00670 std::ostream &
00671 operator << (std::ostream &o,
00672 const TableIndices<N> &indices)
00673 {
00674 o << '[';
00675 for (unsigned int i=0; i<N; ++i)
00676 {
00677 o << indices[i];
00678 if (i+1 != N)
00679 o << ',';
00680 }
00681 o << ']';
00682
00683 return o;
00684 }
00685
00686
00687
00688
00689 DEAL_II_NAMESPACE_CLOSE
00690
00691 #endif
00692