Reference documentation for deal.II version 8.1.0
table_indices.h
1 // ---------------------------------------------------------------------
2 // @f$Id: table_indices.h 30040 2013-07-18 17:06:48Z maier @f$
3 //
4 // Copyright (C) 2005 - 2013 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // The deal.II library is free software; you can use it, redistribute
9 // it, and/or modify it under the terms of the GNU Lesser General
10 // Public License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // The full text of the license can be found in the file LICENSE at
13 // the top level of the deal.II distribution.
14 //
15 // ---------------------------------------------------------------------
16 
17 #ifndef __deal2__table_indices_h
18 #define __deal2__table_indices_h
19 
20 
21 #include <deal.II/base/config.h>
23 
24 #include <ostream>
25 
26 
27 
29 
30 
40 template <int N>
42 {
43 public:
48  unsigned int operator[] (const unsigned int i) const;
49 
54  unsigned int &operator[] (const unsigned int i);
55 
60  bool operator == (const TableIndicesBase<N> &other) const;
61 
66  bool operator != (const TableIndicesBase<N> &other) const;
67 
74  void sort ();
75 
80  template <class Archive>
81  void serialize (Archive &ar, const unsigned int version);
82 
83 protected:
87  unsigned int indices[N];
88 };
89 
90 
106 template <int N>
108 {
113  TableIndices();
120  TableIndices(...);
121 };
122 
123 
124 
138 template <>
139 class TableIndices<1> : public TableIndicesBase<1>
140 {
141 public:
146  TableIndices ();
147 
152  TableIndices (const unsigned int index1);
153 };
154 
155 //TODO: Remove the default arguments and trickery below and put all
156 //the constructors into the class template
157 
170 template <>
171 class TableIndices<2> : public TableIndicesBase<2>
172 {
173 public:
178  TableIndices ();
179 
195  TableIndices (const unsigned int index1,
196  const unsigned int index2 = numbers::invalid_unsigned_int);
197 };
198 
199 
200 
213 template <>
214 class TableIndices<3> : public TableIndicesBase<3>
215 {
216 public:
221  TableIndices ();
222 
238  TableIndices (const unsigned int index1,
239  const unsigned int index2 = numbers::invalid_unsigned_int,
240  const unsigned int index3 = numbers::invalid_unsigned_int);
241 };
242 
243 
256 template <>
257 class TableIndices<4> : public TableIndicesBase<4>
258 {
259 public:
264  TableIndices ();
265 
281  TableIndices (const unsigned int index1,
282  const unsigned int index2 = numbers::invalid_unsigned_int,
283  const unsigned int index3 = numbers::invalid_unsigned_int,
284  const unsigned int index4 = numbers::invalid_unsigned_int);
285 };
286 
287 
300 template <>
301 class TableIndices<5> : public TableIndicesBase<5>
302 {
303 public:
308  TableIndices ();
309 
325  TableIndices (const unsigned int index1,
326  const unsigned int index2 = numbers::invalid_unsigned_int,
327  const unsigned int index3 = numbers::invalid_unsigned_int,
328  const unsigned int index4 = numbers::invalid_unsigned_int,
329  const unsigned int index5 = numbers::invalid_unsigned_int);
330 };
331 
332 
345 template <>
346 class TableIndices<6> : public TableIndicesBase<6>
347 {
348 public:
353  TableIndices ();
354 
370  TableIndices (const unsigned int index1,
371  const unsigned int index2 = numbers::invalid_unsigned_int,
372  const unsigned int index3 = numbers::invalid_unsigned_int,
373  const unsigned int index4 = numbers::invalid_unsigned_int,
374  const unsigned int index5 = numbers::invalid_unsigned_int,
375  const unsigned int index6 = numbers::invalid_unsigned_int);
376 };
377 
378 
391 template <>
392 class TableIndices<7> : public TableIndicesBase<7>
393 {
394 public:
399  TableIndices ();
400 
416  TableIndices (const unsigned int index1,
417  const unsigned int index2 = numbers::invalid_unsigned_int,
418  const unsigned int index3 = numbers::invalid_unsigned_int,
419  const unsigned int index4 = numbers::invalid_unsigned_int,
420  const unsigned int index5 = numbers::invalid_unsigned_int,
421  const unsigned int index6 = numbers::invalid_unsigned_int,
422  const unsigned int index7 = numbers::invalid_unsigned_int);
423 };
424 
425 
426 /* --------------------- Template and inline functions ---------------- */
427 
428 
429 template <int N>
430 inline
431 unsigned int
432 TableIndicesBase<N>::operator [] (const unsigned int i) const
433 {
434  Assert (i < N, ExcIndexRange (i, 0, N));
435  return indices[i];
436 }
437 
438 template <int N>
439 inline
440 unsigned int &
442 {
443  Assert (i < N, ExcIndexRange (i, 0, N));
444  return indices[i];
445 }
446 
447 
448 template <int N>
449 inline
450 bool
452 {
453  for (unsigned int i=0; i<N; ++i)
454  if (indices[i] != other.indices[i])
455  return false;
456  return true;
457 }
458 
459 
460 
461 template <int N>
462 inline
463 bool
465 {
466  return !(*this == other);
467 }
468 
469 
470 
471 template <int N>
472 template <class Archive>
473 inline
474 void
475 TableIndicesBase<N>::serialize (Archive &ar, const unsigned int)
476 {
477  ar &indices;
478 }
479 
480 
481 
482 template <>
483 inline
484 void
486 {}
487 
488 
489 
490 template <>
491 inline
492 void
494 {
495  if (indices[1] < indices[0])
496  std::swap (indices[0], indices[1]);
497 }
498 
499 
500 
501 template <>
502 inline
503 void
505 {
506  // bubble sort for 3 elements
507  if (indices[1] < indices[0])
508  std::swap (indices[0], indices[1]);
509  if (indices[2] < indices[1])
510  std::swap (indices[1], indices[2]);
511  if (indices[1] < indices[0])
512  std::swap (indices[0], indices[1]);
513 }
514 
515 
516 
517 
518 inline
520 {
521  this->indices[0] = 0;
522 }
523 
524 
525 
526 inline
527 TableIndices<1>::TableIndices (const unsigned int index1)
528 {
529  this->indices[0] = index1;
530 }
531 
532 
533 
534 inline
536 {
537  this->indices[0] = this->indices[1] = 0;
538 }
539 
540 
541 
542 inline
543 TableIndices<2>::TableIndices (const unsigned int index1,
544  const unsigned int index2)
545 {
546  this->indices[0] = index1;
547  this->indices[1] = index2;
548 }
549 
550 
551 
552 inline
554 {
555  this->indices[0] = this->indices[1] = this->indices[2] = 0;
556 }
557 
558 
559 
560 inline
561 TableIndices<3>::TableIndices (const unsigned int index1,
562  const unsigned int index2,
563  const unsigned int index3)
564 {
565  this->indices[0] = index1;
566  this->indices[1] = index2;
567  this->indices[2] = index3;
568 }
569 
570 
571 
572 inline
574 {
575  this->indices[0] = this->indices[1] = this->indices[2] = this->indices[3] = 0;
576 }
577 
578 
579 
580 inline
581 TableIndices<4>::TableIndices (const unsigned int index1,
582  const unsigned int index2,
583  const unsigned int index3,
584  const unsigned int index4)
585 {
586  this->indices[0] = index1;
587  this->indices[1] = index2;
588  this->indices[2] = index3;
589  this->indices[3] = index4;
590 }
591 
592 
593 
594 inline
596 {
597  this->indices[0] = this->indices[1]
598  = this->indices[2]
599  = this->indices[3]
600  = this->indices[4] = 0;
601 }
602 
603 
604 
605 inline
606 TableIndices<5>::TableIndices (const unsigned int index1,
607  const unsigned int index2,
608  const unsigned int index3,
609  const unsigned int index4,
610  const unsigned int index5)
611 {
612  this->indices[0] = index1;
613  this->indices[1] = index2;
614  this->indices[2] = index3;
615  this->indices[3] = index4;
616  this->indices[4] = index5;
617 }
618 
619 
620 
621 inline
623 {
624  this->indices[0] = this->indices[1] = this->indices[2]
625  = this->indices[3] = this->indices[4]
626  = this->indices[5] = 0;
627 }
628 
629 
630 
631 inline
632 TableIndices<6>::TableIndices (const unsigned int index1,
633  const unsigned int index2,
634  const unsigned int index3,
635  const unsigned int index4,
636  const unsigned int index5,
637  const unsigned int index6)
638 {
639  this->indices[0] = index1;
640  this->indices[1] = index2;
641  this->indices[2] = index3;
642  this->indices[3] = index4;
643  this->indices[4] = index5;
644  this->indices[5] = index6;
645 }
646 
647 
648 
649 inline
651 {
652  this->indices[0] = this->indices[1] = this->indices[2]
653  = this->indices[3] = this->indices[4]
654  = this->indices[5] = this->indices[6] = 0;
655 }
656 
657 
658 
659 inline
660 TableIndices<7>::TableIndices (const unsigned int index1,
661  const unsigned int index2,
662  const unsigned int index3,
663  const unsigned int index4,
664  const unsigned int index5,
665  const unsigned int index6,
666  const unsigned int index7)
667 {
668  this->indices[0] = index1;
669  this->indices[1] = index2;
670  this->indices[2] = index3;
671  this->indices[3] = index4;
672  this->indices[4] = index5;
673  this->indices[5] = index6;
674  this->indices[6] = index7;
675 }
676 
677 
678 
683 template <int N>
684 std::ostream &
685 operator << (std::ostream &o,
686  const TableIndices<N> &indices)
687 {
688  o << '[';
689  for (unsigned int i=0; i<N; ++i)
690  {
691  o << indices[i];
692  if (i+1 != N)
693  o << ',';
694  }
695  o << ']';
696 
697  return o;
698 }
699 
700 
701 
702 
703 DEAL_II_NAMESPACE_CLOSE
704 
705 #endif
static const unsigned int invalid_unsigned_int
Definition: types.h:191
void serialize(Archive &ar, const unsigned int version)
bool operator==(const TableIndicesBase< N > &other) const
unsigned int indices[N]
Definition: table_indices.h:87
#define Assert(cond, exc)
Definition: exceptions.h:299
bool operator!=(const TableIndicesBase< N > &other) const
::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
std::ostream & operator<<(std::ostream &out, const SymmetricTensor< 2, dim, Number > &t)
unsigned int operator[](const unsigned int i) const