Mentions légales du service

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

DHE SpecificAttributes class hierarchy

Handle DirectedHyperedge SpecificAttributes through a class hierarchy
with base class DirectedHyperedgeBase::SpecificAttributes
parent 42daa69b
No related branches found
No related tags found
No related merge requests found
...@@ -86,23 +86,6 @@ class DirectedHyperedge final : ...@@ -86,23 +86,6 @@ class DirectedHyperedge final :
/// Alias for the vertex type /// Alias for the vertex type
using Vertex_t = DirectedVertex<DirectedHyperedge>; using Vertex_t = DirectedVertex<DirectedHyperedge>;
/* **************************************************************************
* **************************************************************************
* Nested class
* **************************************************************************
***************************************************************************/
public:
/**
* \brief SpecificAttributes class
*
* \details
* Each concrete class that is derived from DirectedHyperedgeBase needs to
* provide a nested class SpecificAttributes to specify additional attributes
* to those of a DirectedHyperedgeBase. A DirectedHyperedge has no specific
* attributes.
*/
class SpecificAttributes {};
/* ************************************************************************** /* **************************************************************************
* ************************************************************************** * **************************************************************************
* Constructors * Constructors
...@@ -147,8 +130,6 @@ class DirectedHyperedge final : ...@@ -147,8 +130,6 @@ class DirectedHyperedge final :
* ************************************************************************** * **************************************************************************
***************************************************************************/ ***************************************************************************/
protected: protected:
/// Specific attributes (none)
std::unique_ptr<SpecificAttributes> specificAttributes_ = nullptr;
}; };
} // namespace hglib } // namespace hglib
......
...@@ -84,6 +84,17 @@ class DirectedHyperedgeBase : public HyperedgeBase { ...@@ -84,6 +84,17 @@ class DirectedHyperedgeBase : public HyperedgeBase {
typename HypergraphProperty> typename HypergraphProperty>
friend class DirectedSubHypergraph; friend class DirectedSubHypergraph;
public:
/**
* \brief SpecificAttributes nested class
*
* \details
* The nested class SpecificAttributes allows classes derived from
* DirectedHyperedgeBase to specify additional attributes in a packed and
* unified way.
*/
class SpecificAttributes {};
protected: protected:
/// DirectedHyperedgeBase constructor /// DirectedHyperedgeBase constructor
DirectedHyperedgeBase(HyperedgeIdType id, DirectedHyperedgeBase(HyperedgeIdType id,
...@@ -94,6 +105,8 @@ class DirectedHyperedgeBase : public HyperedgeBase { ...@@ -94,6 +105,8 @@ class DirectedHyperedgeBase : public HyperedgeBase {
DirectedHyperedgeBase(const DirectedHyperedgeBase& hyperarc); DirectedHyperedgeBase(const DirectedHyperedgeBase& hyperarc);
public: public:
/// Get the specific attributes
const auto& specific_attributes() const { return *specific_attributes_; }
/// Print the directed hyperedge /// Print the directed hyperedge
void print(std::ostream& out) const; void print(std::ostream& out) const;
...@@ -117,6 +130,8 @@ class DirectedHyperedgeBase : public HyperedgeBase { ...@@ -117,6 +130,8 @@ class DirectedHyperedgeBase : public HyperedgeBase {
std::shared_ptr<GraphElementContainer<DirectedVertex_t*>> tails_; std::shared_ptr<GraphElementContainer<DirectedVertex_t*>> tails_;
/// Head vertices of the hyperarc /// Head vertices of the hyperarc
std::shared_ptr<GraphElementContainer<DirectedVertex_t*>> heads_; std::shared_ptr<GraphElementContainer<DirectedVertex_t*>> heads_;
/// Specific attributes
std::unique_ptr<SpecificAttributes> specific_attributes_;
}; };
template <typename DirectedVertex_t> template <typename DirectedVertex_t>
...@@ -126,6 +141,22 @@ std::ostream& operator<< ( ...@@ -126,6 +141,22 @@ std::ostream& operator<< (
hyperarc.print(out); hyperarc.print(out);
return out; 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 } // namespace hglib
#include "DirectedHyperedgeBase.hpp" #include "DirectedHyperedgeBase.hpp"
......
...@@ -24,13 +24,14 @@ ...@@ -24,13 +24,14 @@
#ifndef HGLIB_NAMEDDIRECTEDHYPEREDGE_H #ifndef HGLIB_NAMEDDIRECTEDHYPEREDGE_H
#define HGLIB_NAMEDDIRECTEDHYPEREDGE_H #define HGLIB_NAMEDDIRECTEDHYPEREDGE_H
#include "DirectedHyperedgeBase.h"
#include <memory> #include <memory>
#include <tuple> #include <tuple>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include <string> #include <string>
#include "DirectedHyperedgeBase.h"
#include "hglib/vertex/directed/DirectedVertex.h" #include "hglib/vertex/directed/DirectedVertex.h"
#include "hglib/utils/types.h" #include "hglib/utils/types.h"
#include "ArgumentsToCreateDirectedHyperedge.h" #include "ArgumentsToCreateDirectedHyperedge.h"
...@@ -91,16 +92,16 @@ class NamedDirectedHyperedge final : ...@@ -91,16 +92,16 @@ class NamedDirectedHyperedge final :
* ************************************************************************** * **************************************************************************
***************************************************************************/ ***************************************************************************/
public: public:
/** /**
* \brief SpecificAttributes class * \brief SpecificAttributes nested class
* *
* \details * \details
* Each concrete class that is derived from DirectedHyperedgeBase needs to * The nested class SpecificAttributes allows classes derived from
* provide a nested class SpecificAttributes to specify additional attributes * DirectedHyperedgeBase to specify additional attributes in a packed and
* to those of a DirectedHyperedgeBase. A NamedDirectedHyperedge has a name * unified way.
* as specific attribute. */
*/ class SpecificAttributes :
class SpecificAttributes { public DirectedHyperedgeBase::SpecificAttributes {
public: public:
/// SpecificAttributes constructor /// SpecificAttributes constructor
SpecificAttributes(const std::string& name) : name_(name) {} SpecificAttributes(const std::string& name) : name_(name) {}
...@@ -154,8 +155,6 @@ class NamedDirectedHyperedge final : ...@@ -154,8 +155,6 @@ class NamedDirectedHyperedge final :
* ************************************************************************** * **************************************************************************
***************************************************************************/ ***************************************************************************/
protected: protected:
/// Specific attributes (name)
std::unique_ptr<SpecificAttributes> specificAttributes_ = nullptr;
}; };
/** /**
...@@ -164,7 +163,7 @@ class NamedDirectedHyperedge final : ...@@ -164,7 +163,7 @@ class NamedDirectedHyperedge final :
* \return std::string Name of the directed hyperedge. * \return std::string Name of the directed hyperedge.
*/ */
std::string NamedDirectedHyperedge::name() const { std::string NamedDirectedHyperedge::name() const {
return specificAttributes_->name_; return specificAttributes__(*this).name_;
} }
} // namespace hglib } // namespace hglib
......
...@@ -33,7 +33,7 @@ DirectedHyperedge::DirectedHyperedge( ...@@ -33,7 +33,7 @@ DirectedHyperedge::DirectedHyperedge(
std::shared_ptr<GraphElementContainer<Vertex_t*>> heads, std::shared_ptr<GraphElementContainer<Vertex_t*>> heads,
const SpecificAttributes& specificAttributes) : const SpecificAttributes& specificAttributes) :
DirectedHyperedgeBase(id, tails, heads) { DirectedHyperedgeBase(id, tails, heads) {
specificAttributes_ = specific_attributes_ =
std::make_unique<SpecificAttributes>(specificAttributes); std::make_unique<SpecificAttributes>(specificAttributes);
} }
...@@ -45,8 +45,8 @@ DirectedHyperedge::DirectedHyperedge( ...@@ -45,8 +45,8 @@ DirectedHyperedge::DirectedHyperedge(
*/ */
DirectedHyperedge::DirectedHyperedge(const DirectedHyperedge& other) : DirectedHyperedge::DirectedHyperedge(const DirectedHyperedge& other) :
DirectedHyperedgeBase(other) { DirectedHyperedgeBase(other) {
specificAttributes_ = specific_attributes_ =
std::make_unique<SpecificAttributes>(*(other.specificAttributes_)); std::make_unique<SpecificAttributes>(*(other.specific_attributes_));
} }
...@@ -84,7 +84,8 @@ argumentsToCreateHyperarc() const { ...@@ -84,7 +84,8 @@ argumentsToCreateHyperarc() const {
heads.push_back(vertex->id()); heads.push_back(vertex->id());
} }
return ArgumentsToCreateDirectedHyperedge<DirectedHyperedge>( return ArgumentsToCreateDirectedHyperedge<DirectedHyperedge>(
std::make_pair(tails, heads), *specificAttributes_); std::make_pair(tails, heads),
specificAttributes__(*this));
} }
/** /**
......
...@@ -36,7 +36,7 @@ NamedDirectedHyperedge( ...@@ -36,7 +36,7 @@ NamedDirectedHyperedge(
std::shared_ptr<GraphElementContainer<DirectedVertex_t*>> heads, std::shared_ptr<GraphElementContainer<DirectedVertex_t*>> heads,
const SpecificAttributes& specificAttributes) : const SpecificAttributes& specificAttributes) :
DirectedHyperedgeBase(id, tails, heads) { DirectedHyperedgeBase(id, tails, heads) {
specificAttributes_ = specific_attributes_ =
std::make_unique<SpecificAttributes>(specificAttributes); std::make_unique<SpecificAttributes>(specificAttributes);
} }
...@@ -49,8 +49,8 @@ NamedDirectedHyperedge( ...@@ -49,8 +49,8 @@ NamedDirectedHyperedge(
NamedDirectedHyperedge:: NamedDirectedHyperedge::
NamedDirectedHyperedge(const NamedDirectedHyperedge& other) : NamedDirectedHyperedge(const NamedDirectedHyperedge& other) :
DirectedHyperedgeBase(other) { DirectedHyperedgeBase(other) {
specificAttributes_ = specific_attributes_ =
std::make_unique<SpecificAttributes>(*(other.specificAttributes_)); std::make_unique<SpecificAttributes>(specificAttributes__(other));
} }
...@@ -97,7 +97,7 @@ argumentsToCreateHyperarc() const { ...@@ -97,7 +97,7 @@ argumentsToCreateHyperarc() const {
heads.push_back(vertex->id()); heads.push_back(vertex->id());
} }
return ArgumentsToCreateDirectedHyperedge<NamedDirectedHyperedge>( return ArgumentsToCreateDirectedHyperedge<NamedDirectedHyperedge>(
std::make_pair(tails, heads), *specificAttributes_); std::make_pair(tails, heads), specificAttributes__(*this));
} }
...@@ -112,7 +112,7 @@ argumentsToCreateHyperarc() const { ...@@ -112,7 +112,7 @@ argumentsToCreateHyperarc() const {
*/ */
void NamedDirectedHyperedge:: void NamedDirectedHyperedge::
print(std::ostream& out) const { print(std::ostream& out) const {
out << specificAttributes_->name_ << ": "; out << name() << ": ";
DirectedHyperedgeBase<DirectedVertex_t>::printTailsAndHeads(out); DirectedHyperedgeBase<DirectedVertex_t>::printTailsAndHeads(out);
} }
...@@ -140,7 +140,7 @@ bool NamedDirectedHyperedge:: ...@@ -140,7 +140,7 @@ bool NamedDirectedHyperedge::
compare(const std::vector<const DirectedVertex_t*>& tails, compare(const std::vector<const DirectedVertex_t*>& tails,
const std::vector<const DirectedVertex_t*>& heads, const std::vector<const DirectedVertex_t*>& heads,
const SpecificAttributes& specificAttributes) const { const SpecificAttributes& specificAttributes) const {
return specificAttributes.name_.compare(specificAttributes_->name_) == 0 and return specificAttributes.name_.compare(name()) == 0 and
DirectedHyperedgeBase<DirectedVertex_t>::compare(tails, heads); DirectedHyperedgeBase<DirectedVertex_t>::compare(tails, heads);
} }
......
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