Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 42daa69b authored by David Parsons's avatar David Parsons
Browse files

UHE SpecificAttributes class hierarchy

Handle UndirectedHyperedge SpecificAttributes through a class hierarchy
with base class UndirectedHyperedgeBase::SpecificAttributes
parent c5fa6ebe
No related branches found
No related tags found
No related merge requests found
......@@ -58,7 +58,7 @@ namespace hglib {
*/
class NamedUndirectedHyperedge final :
public UndirectedHyperedgeBase<
UndirectedVertex<NamedUndirectedHyperedge>>{
UndirectedVertex<NamedUndirectedHyperedge>> {
template <template <typename> typename DirectedVertex_t,
typename Hyperedge_t,
typename VertexProperty,
......@@ -90,15 +90,15 @@ class NamedUndirectedHyperedge final :
***************************************************************************/
public:
/**
* \brief SpecificAttributes class
* \brief SpecificAttributes nested class
*
* \details
* Each concrete class that is derived from UndirectedHyperedgeBase needs to
* provide a nested class SpecificAttributes to specify additional attributes
* to those of an UndirectedHyperedgeBase. A NamedUndirectedHyperedge has a
* name as specific attribute.
* The nested class SpecificAttributes allows classes derived from
* UndirectedHyperedgeBase to specify additional attributes in a packed and
* unified way.
*/
class SpecificAttributes {
class SpecificAttributes :
public UndirectedHyperedgeBase::SpecificAttributes {
public:
/// SpecificAttributes constructor
SpecificAttributes(const std::string& name) : name_(name) {}
......@@ -150,8 +150,6 @@ class NamedUndirectedHyperedge final :
* **************************************************************************
***************************************************************************/
protected:
/// Specific attributes (name)
std::unique_ptr<SpecificAttributes> specificAttributes_ = nullptr;
};
/**
......@@ -160,7 +158,7 @@ class NamedUndirectedHyperedge final :
* \return std::string Name of the directed hyperedge.
*/
std::string NamedUndirectedHyperedge::name() const {
return specificAttributes_->name_;
return specificAttributes(*this).name_;
}
} // namespace hglib
......
......@@ -81,23 +81,6 @@ class UndirectedHyperedge final :
/// Alias for the vertex type
using Vertex_t = UndirectedVertex<UndirectedHyperedge>;
/* **************************************************************************
* **************************************************************************
* Nested class
* **************************************************************************
***************************************************************************/
public:
/**
* \brief SpecificAttributes class
*
* \details
* Each concrete class that is derived from UndirectedHyperedgeBase needs to
* provide a nested class SpecificAttributes to specify additional attributes
* to those of an UndirectedHyperedgeBase. An UndirectedHyperedge has no
* specific attributes.
*/
class SpecificAttributes {};
/* **************************************************************************
* **************************************************************************
* Constructors
......@@ -140,8 +123,6 @@ class UndirectedHyperedge final :
* **************************************************************************
***************************************************************************/
protected:
/// Specific attributes (none)
std::unique_ptr<SpecificAttributes> specificAttributes_ = nullptr;
};
} // namespace hglib
......
......@@ -78,6 +78,17 @@ class UndirectedHyperedgeBase : public HyperedgeBase {
typename HypergraphProperty>
friend class UndirectedSubHypergraph;
public:
/**
* \brief SpecificAttributes nested class
*
* \details
* The nested class SpecificAttributes allows classes derived from
* UndirectedHyperedgeBase to specify additional attributes in a packed and
* unified way.
*/
class SpecificAttributes {};
protected:
/// UndirectedHyperedgeBase constructor
UndirectedHyperedgeBase(
......@@ -88,6 +99,8 @@ class UndirectedHyperedgeBase : public HyperedgeBase {
UndirectedHyperedgeBase(const UndirectedHyperedgeBase& other);
public:
/// Get the specific attributes
const auto& specific_attributes() const { return *specific_attributes_; }
/// Print the undirected hyperedge
void print(std::ostream& out) const;
......@@ -104,6 +117,8 @@ class UndirectedHyperedgeBase : public HyperedgeBase {
protected:
/// Vertices of the undirected hyperedge
std::shared_ptr<GraphElementContainer<UndirectedVertex_t*>> vertices_;
/// Specific attributes
std::unique_ptr<SpecificAttributes> specific_attributes_;
};
/**
......@@ -126,6 +141,21 @@ std::ostream& operator<< (
return out;
}
/**
* Get the specific attributes of hyperedge in its "final" type
*
* \tparam Hyperedge_t enclosing class for SpecificAttributes
* \param hyperedge hyperedge which specific attributes are to be returned
* \return hyperedge's specific attributes casted to
* const Hyperedge_t::SpecificAttributes
*/
template <typename Hyperedge_t>
typename Hyperedge_t::SpecificAttributes
specificAttributes(const Hyperedge_t& hyperedge) {
return static_cast<const typename Hyperedge_t::SpecificAttributes&>(
hyperedge.specific_attributes());
}
} // namespace hglib
#include "UndirectedHyperedgeBase.hpp"
......
......@@ -43,6 +43,17 @@ class VertexBase {
typename HypergraphProperty>
friend class Hypergraph;
public:
/**
* \brief SpecificAttributes nested class
*
* \details
* The nested class SpecificAttributes allows classes derived from
* VertexBase to specify additional attributes in a packed and
* unified way.
*/
class SpecificAttributes {};
protected:
/// VertexBase constructor
VertexBase(VertexIdType id, std::string name);
......@@ -70,6 +81,8 @@ class VertexBase {
VertexIdType id_;
/// Name of the vertex
std::string name_;
/// Specific attributes
std::unique_ptr<SpecificAttributes> specificAttributes_;
};
/// Operator<<
......
......@@ -79,18 +79,6 @@ class DirectedVertex : public VertexBase {
/// Alias to make the template parameter publicily available
using HyperarcType = Hyperarc_t;
public:
/**
* \brief SpecificAttributes class
*
* \details
* Each class that is derived from DirectedVertex needs to
* provide a nested class SpecificAttributes to specify additional attributes
* to those of a DirectedVertex. A DirectedVertex has thus no specific
* attributes.
*/
class SpecificAttributes {};
protected:
/// DirectedVertex constructor
DirectedVertex(VertexIdType id, std::string name,
......@@ -121,8 +109,6 @@ class DirectedVertex : public VertexBase {
std::shared_ptr<GraphElementContainer<Hyperarc_t*>> inHyperarcs_;
/// Outgoing directed hyperedges
std::shared_ptr<GraphElementContainer<Hyperarc_t*>> outHyperarcs_;
/// Specific attributes (none)
std::unique_ptr<SpecificAttributes> specificAttributes_ = nullptr;
};
} // namespace hglib
......
......@@ -79,18 +79,6 @@ class UndirectedVertex : public VertexBase {
/// Alias to make the template parameter publicly available
using HyperedgeType = Hyperedge_t;
public:
/**
* \brief SpecificAttributes class
*
* \details
* Each class that is derived from UndirectedVertex needs to
* provide a nested class SpecificAttributes to specify additional attributes
* to those of a UndirectedVertex. A UndirectedVertex has thus no specific
* attributes.
*/
class SpecificAttributes {};
protected:
/// UndirectedVertex constructor
UndirectedVertex(VertexIdType id, std::string name,
......@@ -115,8 +103,6 @@ class UndirectedVertex : public VertexBase {
protected:
/// Hyperedges that contain the undirected vertex
std::shared_ptr<GraphElementContainer<Hyperedge_t*>> hyperedges_;
/// Specific attributes (none)
std::unique_ptr<SpecificAttributes> specificAttributes_ = nullptr;
};
} // namespace hglib
......
......@@ -34,7 +34,7 @@ NamedUndirectedHyperedge(int id,
GraphElementContainer<Vertex_t*>> vertices,
const SpecificAttributes& specificAttributes) :
UndirectedHyperedgeBase(id, vertices) {
specificAttributes_ =
specific_attributes_ =
std::make_unique<SpecificAttributes>(specificAttributes);
}
......@@ -47,8 +47,8 @@ NamedUndirectedHyperedge(int id,
NamedUndirectedHyperedge::
NamedUndirectedHyperedge(const NamedUndirectedHyperedge& other) :
UndirectedHyperedgeBase(other) {
specificAttributes_ =
std::make_unique<SpecificAttributes>(*(other.specificAttributes_));
specific_attributes_ =
std::make_unique<SpecificAttributes>(specificAttributes(other));
}
......@@ -89,7 +89,8 @@ argumentsToCreateHyperedge() const {
vertices.push_back(vertex->id());
}
return ArgumentsToCreateUndirectedHyperedge<NamedUndirectedHyperedge>(
vertices, *specificAttributes_);
vertices,
specificAttributes(*this));
}
/**
......@@ -107,7 +108,7 @@ argumentsToCreateHyperedge() const {
*/
void NamedUndirectedHyperedge::
print(std::ostream& out) const {
out << specificAttributes_->name_ << ": ";
out << name() << ": ";
UndirectedHyperedgeBase<Vertex_t>::printVertices(out);
}
......@@ -131,7 +132,7 @@ print(std::ostream& out) const {
bool NamedUndirectedHyperedge::
compare(const std::vector<const Vertex_t*>& vertices,
const SpecificAttributes& specificAttributes) const {
return specificAttributes.name_.compare(specificAttributes_->name_) == 0 and
return specificAttributes.name_.compare(name()) == 0 and
UndirectedHyperedgeBase<Vertex_t>::compare(vertices);
}
} // namespace hglib
......@@ -30,7 +30,7 @@ UndirectedHyperedge(int id,
std::shared_ptr<GraphElementContainer<Vertex_t*>> vertices,
const SpecificAttributes& specificAttributes) :
UndirectedHyperedgeBase(id, vertices) {
specificAttributes_ =
specific_attributes_ =
std::make_unique<SpecificAttributes>(specificAttributes);
}
......@@ -43,8 +43,8 @@ UndirectedHyperedge(int id,
UndirectedHyperedge::
UndirectedHyperedge(const UndirectedHyperedge& other) :
UndirectedHyperedgeBase(other) {
specificAttributes_ =
std::make_unique<SpecificAttributes>(*(other.specificAttributes_));
specific_attributes_ =
std::make_unique<SpecificAttributes>(*(other.specific_attributes_));
}
......@@ -80,7 +80,7 @@ argumentsToCreateHyperedge() const {
vertices.push_back(vertex->id());
}
return ArgumentsToCreateUndirectedHyperedge<UndirectedHyperedge>(vertices,
*specificAttributes_);
*specific_attributes_);
}
......
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