CEPS  24.01
Cardiac ElectroPhysiology Simulator
HoldsNodes.hpp
Go to the documentation of this file.
1 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2  This file is part of CEPS.
3 
4  CEPS is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  CEPS is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with CEPS (see file LICENSE at root of project).
16  If not, see <https://www.gnu.org/licenses/>.
17 
18 
19  Copyright 2019-2024 Inria, Universite de Bordeaux
20 
21  Authors, in alphabetical order:
22 
23  Pierre-Elliott BECUE, Florian CARO, Yves COUDIERE(*), Andjela DAVIDOVIC,
24  Charlie DOUANLA-LONTSI, Marc FUENTES, Mehdi JUHOOR, Michael LEGUEBE(*),
25  Pauline MIGERDITICHAN, Valentin PANNETIER(*), Nejib ZEMZEMI.
26  * : currently active authors
27 
28 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
31 #pragma once
32 
34 #include <source_location>
35 
37 namespace ceps
38 {
39 
43  template <class NodeType>
44  class HoldsNodes
45  {
46 
47  public:
48 
50  explicit HoldsNodes(const CepsVector<NodeType*>& nodes);
51 
53  HoldsNodes(NodeType** nodes, const CepsUInt& n);
54 
56  HoldsNodes() = default;
57 
59  HoldsNodes(const HoldsNodes&) = default;
60 
62  HoldsNodes(HoldsNodes&&) noexcept = default;
63 
65  virtual ~HoldsNodes() = default;
66 
68  HoldsNodes&
69  operator=(const HoldsNodes&) = default;
70 
72  HoldsNodes&
73  operator=(HoldsNodes&&) noexcept = default;
74 
76  CepsUInt
78 
80  CepsUInt
82 
84  CepsVector<NodeType*>&
86 
88  const CepsVector<NodeType*>&
89  getNodes() const;
90 
92  NodeType*
93  getNodeAt(const CepsUInt& i);
94 
96  const NodeType*
97  getNodeAt(const CepsUInt& i) const;
98 
100  void
101  setNodes(const CepsVector<NodeType*>& nodes);
102 
104  void
105  setNodes(NodeType** nodes, const CepsUInt& n);
106 
108  template <class _It>
109  void
110  setNodes(_It first, _It last);
111 
113  void
114  setNodeAt(const CepsUInt& i, NodeType* neigh);
115 
117  void
118  addNode(NodeType* name);
119 
121  void
122  addNodes(const CepsVector<NodeType*>& nodes);
123 
125  void
126  addNodes(NodeType** nodes, const CepsUInt& n);
127 
129  template <class _It>
130  void
131  addNodes(_It first, _It last);
132 
134  void
135  removeNode(NodeType*& name);
136 
138  void
139  removeNodes(const CepsVector<NodeType*>& nodes);
140 
142  void
143  removeNodes(NodeType** nodes, const CepsUInt& n);
144 
146  template <class _It>
147  void
148  removeNodes(_It first, _It last);
149 
151  void
153 
155  CepsBool
156  hasNode(NodeType*& neigh);
157 
159  CepsBool
160  hasAllNodes(const CepsVector<NodeType*>& nodes);
161 
163  CepsBool
164  hasAllNodes(NodeType** nodes, const CepsUInt& n);
165 
167  template <class _It>
168  CepsBool
169  hasAllNodes(_It first, _It last);
170 
172  CepsBool
173  hasOneOfNodes(const CepsVector<NodeType*>& nodes);
174 
176  CepsBool
177  hasOneOfNodes(NodeType** nodes, const CepsUInt& n);
178 
180  template <class _It>
181  CepsBool
182  hasOneOfNodes(_It first, _It last);
183 
185  CepsVector<NodeType*>
186  getValidNodes() const;
187 
191 
194  getNodeIndices() const;
195 
197  void
198  getNodeIndices(CepsGlobalIndex* nodesIndices, const CepsSize& nAllocated) const;
199 
201  void
202  reset();
203 
204 
205  protected:
206 
208  void
209  errorOnNodeIndex(CepsUInt i, std::source_location loc = std::source_location::current()) const;
210 
211 
212  protected:
213 
215  CepsVector<NodeType*> m_nodes;
216 
218  NodeType* m_dummyNode;
219 
220  };
221 
222 } // namespace ceps
223 
224 // Template member functions in a fake cpp
225 #include "common/abstract/HoldsNodes.tpp"
std::vector< _Type, _Alloc > CepsVector
C++ vector.
Definition: CepsTypes.hpp:155
bool CepsBool
Booleans.
Definition: CepsTypes.hpp:124
size_t CepsSize
Size unsigned.
Definition: CepsTypes.hpp:126
CepsIndex CepsGlobalIndex
Many uses. Has to be signed for PETSc.
Definition: CepsTypes.hpp:218
std::make_unsigned_t< CepsInt > CepsUInt
Unsigned version on CepsInt.
Definition: CepsTypes.hpp:109
CepsBool hasOneOfNodes(const CepsVector< NodeType * > &nodes)
Tells if object has one of the given nodes.
void removeNodes(const CepsVector< NodeType * > &nodes)
Removes several nodes from the list.
CepsVector< NodeType * > & getNodes()
Reference to the node pointers array.
void setNodeAt(const CepsUInt &i, NodeType *neigh)
Set the i-th node. If i>nNodes, nullptrs fill the vector.
CepsVector< NodeType * > m_nodes
The node pointers.
Definition: HoldsNodes.hpp:215
CepsVector< CepsGlobalIndex > getNodeIndices() const
Get indices of all nodes.
CepsGlobalIndex getNodeIndex(CepsUInt i) const
Get the index of i-th node.
CepsUInt getNumberOfNodes() const
Returns the total number of nodes.
void removeNode(NodeType *&name)
Removes the given node from the list.
void clearNodes()
Wipes the vector of nodes.
void addNodes(const CepsVector< NodeType * > &nodes)
Add several nodes to the vector.
void reset()
Equivalent to HoldsNodes::clearNodes.
CepsUInt countValidNodes()
Returns the number of nodes that are not nullptr.
CepsVector< NodeType * > getValidNodes() const
Get pointers on all valid nodes.
NodeType * m_dummyNode
An empty node to be returned after abort when testing.
Definition: HoldsNodes.hpp:218
HoldsNodes(NodeType **nodes, const CepsUInt &n)
Constructor with nodes.
HoldsNodes()=default
Default constructor.
void errorOnNodeIndex(CepsUInt i, std::source_location loc=std::source_location::current()) const
Aborts if requesting node with wrong index.
NodeType * getNodeAt(const CepsUInt &i)
Pointer to the i-th node.
CepsBool hasNode(NodeType *&neigh)
Tells if object has the given node.
void setNodes(const CepsVector< NodeType * > &nodes)
Assign all nodes.
void addNode(NodeType *name)
Add a single node to the vector.
CepsBool hasAllNodes(const CepsVector< NodeType * > &nodes)
Tells if object has all the given nodes.
HoldsNodes(HoldsNodes &&) noexcept=default
Copy constructor.
HoldsNodes(const CepsVector< NodeType * > &nodes)
Constructor with nodes.
HoldsNodes(const HoldsNodes &)=default
Copy constructor.
A namespace for all utility methods.