Skip to content
Snippets Groups Projects
Commit 60e7b151 authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

Use boost::optional in Element::addNeighbor return value.

parent cd1268ca
No related branches found
No related tags found
No related merge requests found
...@@ -41,18 +41,18 @@ void Element::setNeighbor(Element* neighbor, unsigned const face_id) ...@@ -41,18 +41,18 @@ void Element::setNeighbor(Element* neighbor, unsigned const face_id)
this->_neighbors[face_id] = neighbor; this->_neighbors[face_id] = neighbor;
} }
unsigned Element::addNeighbor(Element* e) boost::optional<unsigned> Element::addNeighbor(Element* e)
{ {
if (e == this || if (e == this ||
e == nullptr || e == nullptr ||
e->getDimension() != this->getDimension()) e->getDimension() != this->getDimension())
return -1; return boost::optional<unsigned>();
unsigned nNeighbors (this->getNNeighbors()); unsigned nNeighbors (this->getNNeighbors());
for (unsigned n=0; n<nNeighbors; n++) for (unsigned n=0; n<nNeighbors; n++)
{ {
if (this->_neighbors[n] == e) if (this->_neighbors[n] == e)
return -1; return boost::optional<unsigned>();
if (this->_neighbors[n] == nullptr) if (this->_neighbors[n] == nullptr)
break; break;
} }
...@@ -72,11 +72,11 @@ unsigned Element::addNeighbor(Element* e) ...@@ -72,11 +72,11 @@ unsigned Element::addNeighbor(Element* e)
if ((++count)>=dim) if ((++count)>=dim)
{ {
_neighbors[ this->identifyFace(face_nodes) ] = e; _neighbors[ this->identifyFace(face_nodes) ] = e;
return e->identifyFace(face_nodes); return boost::optional<unsigned>(e->identifyFace(face_nodes));
} }
} }
return -1; return boost::optional<unsigned>();
} }
MeshLib::Node Element::getCenterOfGravity() const MeshLib::Node Element::getCenterOfGravity() const
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#include <vector> #include <vector>
#include <limits> #include <limits>
#include <boost/optional.hpp>
#include "MeshEnums.h" #include "MeshEnums.h"
#include "Mesh.h" #include "Mesh.h"
#include "MeshQuality/ElementErrorCode.h" #include "MeshQuality/ElementErrorCode.h"
...@@ -45,7 +47,7 @@ public: ...@@ -45,7 +47,7 @@ public:
* neighbour-list and the face id of the neighbour connected to this element * neighbour-list and the face id of the neighbour connected to this element
* is returned. Otherwise the maximum value of the value type is returned. * is returned. Otherwise the maximum value of the value type is returned.
*/ */
unsigned addNeighbor(Element* e); boost::optional<unsigned> addNeighbor(Element* e);
// Calculates the center of gravity for the mesh element // Calculates the center of gravity for the mesh element
MeshLib::Node getCenterOfGravity() const; MeshLib::Node getCenterOfGravity() const;
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
* *
*/ */
#include "boost/optional.hpp"
#include "Mesh.h" #include "Mesh.h"
#include "Node.h" #include "Node.h"
...@@ -178,10 +180,10 @@ void Mesh::setElementNeighbors() ...@@ -178,10 +180,10 @@ void Mesh::setElementNeighbors()
for (auto neighbor = neighbors.begin(); neighbor != neighbors_new_end; ++neighbor) for (auto neighbor = neighbors.begin(); neighbor != neighbors_new_end; ++neighbor)
{ {
unsigned const opposite_face_id = element->addNeighbor(*neighbor); boost::optional<unsigned> const opposite_face_id = element->addNeighbor(*neighbor);
if (opposite_face_id != unsigned(-1)) if (opposite_face_id)
{ {
(*neighbor)->setNeighbor(element, opposite_face_id); (*neighbor)->setNeighbor(element, *opposite_face_id);
} }
} }
neighbors.clear(); neighbors.clear();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment