DSC
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros
key.h
1 //
2 // Deformabel Simplicial Complex (DSC) method
3 // Copyright (C) 2013 Technical University of Denmark
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // See licence.txt for a copy of the GNU General Public License.
16 
17 #pragma once
18 
19 #include <iostream>
20 
21 namespace is_mesh
22 {
23  // Note: Non-polymorphic
24  class Key
25  {
26  protected:
27  unsigned int key;
28 
29  Key() noexcept : Key(static_cast<unsigned int>(-1))
30  {
31 
32  }
33 
34  Key(unsigned int _key) noexcept : key(_key)
35  {
36 
37  }
38 
39  public:
40  bool is_valid() const noexcept
41  {
42  return key != static_cast<unsigned int>(-1);
43  }
44 
45  //conversion to int
46  operator unsigned int() const noexcept
47  {
48  return key;
49  }
50 
51  friend inline bool operator==(Key const & a, Key const & b) { return a.key == b.key; }
52  friend inline bool operator==(Key & a, Key & b) { return a.key == b.key; }
53  friend inline bool operator==(unsigned int const & k, Key const & b) { return k == b.key; }
54  friend inline bool operator==(Key const & a, unsigned int const & k) { return a.key == k; }
55  friend inline bool operator!=(Key const & a, Key const & b) { return a.key != b.key; }
56  friend inline bool operator!=(Key & a, Key & b) { return a.key != b.key; }
57  friend inline bool operator!=(unsigned int const & k, Key const & b) { return k != b.key; }
58  friend inline bool operator!=(Key const & a, unsigned int const & k) { return a.key != k; }
59  friend inline bool operator< (Key const & a, Key const & b) { return a.key < b.key; }
60  friend inline bool operator< (Key & a, Key & b) { return a.key < b.key; }
61  friend inline bool operator< (unsigned int const & k, Key const & b) { return k < b.key; }
62  friend inline bool operator< (Key const & a, unsigned int const & k) { return a.key < k; }
63 
64  friend std::ostream& operator<< (std::ostream & os, Key const & a) { return (os << a.key); }
65  friend std::istream& operator>> (std::istream & is, Key & a) { return (is >> a.key); }
66  };
67 
68  class NodeKey : public Key
69  {
70  public:
71  NodeKey() noexcept : Key() {}
72  NodeKey(unsigned int k) noexcept : Key(k) {}
73  };
74 
75  class EdgeKey : public Key
76  {
77  public:
78  EdgeKey() noexcept : Key() {}
79  EdgeKey(unsigned int k) noexcept : Key(k) {}
80  };
81 
82  class FaceKey : public Key
83  {
84  public:
85  FaceKey() noexcept : Key() {}
86  FaceKey(unsigned int k) noexcept : Key(k) {}
87  };
88 
89  class TetrahedronKey : public Key
90  {
91  public:
92  TetrahedronKey() noexcept : Key() {}
93  TetrahedronKey(unsigned int k) noexcept : Key(k) {}
94  };
95 
96 }
Definition: key.h:75
Definition: key.h:89
Definition: key.h:24
Definition: key.h:68
Definition: key.h:82