Reference documentation for deal.II version 8.1.0
cell_id.h
1 // ---------------------------------------------------------------------
2 // @f$Id: cell_id.h 31527 2013-11-03 09:58:45Z maier @f$
3 //
4 // Copyright (C) 1998 - 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__cell_id_h
18 #define __deal2__cell_id_h
19 
20 #include <deal.II/base/config.h>
22 
23 #include <vector>
24 
25 
27 
28 
40 class CellId
41 {
42 public:
46  explicit CellId(unsigned int coarse_cell_id_, std::vector<unsigned char> id_)
47  : coarse_cell_id(coarse_cell_id_), id(id_)
48  {}
49 
54  : coarse_cell_id(-1)
55  {}
56 
60  bool operator== (const CellId &other) const;
61 
65  bool operator!= (const CellId &other) const;
66 
67 
68  friend std::istream &operator>> (std::istream &is, CellId &cid);
69  friend std::ostream &operator<< (std::ostream &os, const CellId &cid);
70 private:
71  unsigned int coarse_cell_id;
72  std::vector<unsigned char> id;
73 };
74 
78 inline std::ostream &operator<< (std::ostream &os, const CellId &cid)
79 {
80  os << cid.coarse_cell_id << '_' << cid.id.size() << ':';
81  for (unsigned int i=0; i<cid.id.size(); ++i)
82  os << static_cast<int>(cid.id[i]);
83  return os;
84 }
85 
89 inline std::istream &operator>> (std::istream &is, CellId &cid)
90 {
91  unsigned int cellid;
92  is >> cellid;
93  if (is.eof())
94  return is;
95 
96  cid.coarse_cell_id = cellid;
97  char dummy;
98  is >> dummy;
99  Assert(dummy=='_', ExcMessage("invalid CellId"));
100  unsigned int idsize;
101  is >> idsize;
102  is >> dummy;
103  Assert(dummy==':', ExcMessage("invalid CellId"));
104 
105  char value;
106  cid.id.clear();
107  for (unsigned int i=0; i<idsize; ++i)
108  {
109  is >> value;
110  cid.id.push_back(value-'0');
111  }
112  return is;
113 }
114 
115 inline bool
116 CellId::operator== (const CellId &other) const
117 {
118  if (this->coarse_cell_id != other.coarse_cell_id)
119  return false;
120  return id == other.id;
121 }
122 
126 inline bool
127 CellId::operator!= (const CellId &other) const
128 {
129  return !(*this == other);
130 }
131 
132 DEAL_II_NAMESPACE_CLOSE
133 
134 #endif
::ExceptionBase & ExcMessage(std::string arg1)
CellId()
Definition: cell_id.h:53
friend std::ostream & operator<<(std::ostream &os, const CellId &cid)
Definition: cell_id.h:78
#define Assert(cond, exc)
Definition: exceptions.h:299
friend std::istream & operator>>(std::istream &is, CellId &cid)
Definition: cell_id.h:89
std::ostream & operator<<(std::ostream &out, const SymmetricTensor< 2, dim, Number > &t)
Definition: cell_id.h:40
CellId(unsigned int coarse_cell_id_, std::vector< unsigned char > id_)
Definition: cell_id.h:46
bool operator==(const CellId &other) const
Definition: cell_id.h:116
bool operator!=(const CellId &other) const
Definition: cell_id.h:127
std::istream & operator>>(std::istream &in, Point< dim, Number > &p)
Definition: point.h:480