diff --git a/include/hglib/hyperedge/directed/DirectedHyperedge.h b/include/hglib/hyperedge/directed/DirectedHyperedge.h index 6e3e428125f34acd3ad22d900e96114236366d23..db50b6f12c3855e6823c9448f197d78f56e4b089 100644 --- a/include/hglib/hyperedge/directed/DirectedHyperedge.h +++ b/include/hglib/hyperedge/directed/DirectedHyperedge.h @@ -24,13 +24,14 @@ #ifndef HGLIB_DIRECTEDHYPEREDGE_H #define HGLIB_DIRECTEDHYPEREDGE_H +#include "DirectedHyperedgeBase.h" + #include <memory> #include <tuple> #include <utility> #include <vector> #include <string> -#include "DirectedHyperedgeBase.h" #include "ArgumentsToCreateDirectedHyperedge.h" #include "hglib/vertex/directed/DirectedVertex.h" #include "hglib/utils/types.h" @@ -147,7 +148,7 @@ class DirectedHyperedge final : ***************************************************************************/ protected: /// Specific attributes (none) - SpecificAttributes specificAttributes_; + std::unique_ptr<SpecificAttributes> specificAttributes_ = nullptr; }; } // namespace hglib diff --git a/include/hglib/hyperedge/directed/NamedDirectedHyperedge.h b/include/hglib/hyperedge/directed/NamedDirectedHyperedge.h index 60906e9dfb64b387c34d00d0595fc0df2cff5e34..5f01d9eb90329232ebaac8e8e6ce63b6a78a7175 100644 --- a/include/hglib/hyperedge/directed/NamedDirectedHyperedge.h +++ b/include/hglib/hyperedge/directed/NamedDirectedHyperedge.h @@ -36,6 +36,7 @@ #include "ArgumentsToCreateDirectedHyperedge.h" namespace hglib { + /** * \brief Named directed hyperedge class * @@ -154,7 +155,7 @@ class NamedDirectedHyperedge final : ***************************************************************************/ protected: /// Specific attributes (name) - SpecificAttributes specificAttributes_; + std::unique_ptr<SpecificAttributes> specificAttributes_ = nullptr; }; /** @@ -163,7 +164,7 @@ class NamedDirectedHyperedge final : * \return std::string Name of the directed hyperedge. */ std::string NamedDirectedHyperedge::name() const { - return specificAttributes_.name_; + return specificAttributes_->name_; } } // namespace hglib diff --git a/include/hglib/hyperedge/undirected/NamedUndirectedHyperedge.h b/include/hglib/hyperedge/undirected/NamedUndirectedHyperedge.h index 9a00ee1533e2e016cf78dc71aa043482f9ecc4e9..5b117ba94569cb127e93b35b2a80028be29d91a8 100644 --- a/include/hglib/hyperedge/undirected/NamedUndirectedHyperedge.h +++ b/include/hglib/hyperedge/undirected/NamedUndirectedHyperedge.h @@ -25,6 +25,9 @@ #define HGLIB_NAMEDUNDIRECTEDHYPEREDGE_H #include "UndirectedHyperedgeBase.h" + +#include <memory> + #include "ArgumentsToCreateUndirectedHyperedge.h" #include "hglib/utils/types.h" #include "hglib/vertex/undirected/UndirectedVertex.h" @@ -148,7 +151,7 @@ class NamedUndirectedHyperedge final : ***************************************************************************/ protected: /// Specific attributes (name) - SpecificAttributes specificAttributes_; + std::unique_ptr<SpecificAttributes> specificAttributes_ = nullptr; }; /** @@ -157,7 +160,7 @@ class NamedUndirectedHyperedge final : * \return std::string Name of the directed hyperedge. */ std::string NamedUndirectedHyperedge::name() const { - return specificAttributes_.name_; + return specificAttributes_->name_; } } // namespace hglib diff --git a/include/hglib/hyperedge/undirected/UndirectedHyperedge.h b/include/hglib/hyperedge/undirected/UndirectedHyperedge.h index 66d9f36e39b9642c6b245dbd293717cefedd46a9..2c497ce3ffd2de1ca6b3c5ed5e20db3f900059d7 100644 --- a/include/hglib/hyperedge/undirected/UndirectedHyperedge.h +++ b/include/hglib/hyperedge/undirected/UndirectedHyperedge.h @@ -24,8 +24,11 @@ #ifndef HGLIB_UNDIRECTEDHYPEREDGE_H #define HGLIB_UNDIRECTEDHYPEREDGE_H -#include "ArgumentsToCreateUndirectedHyperedge.h" #include "UndirectedHyperedgeBase.h" + +#include <memory> + +#include "ArgumentsToCreateUndirectedHyperedge.h" #include "hglib/utils/types.h" #include "hglib/vertex/undirected/UndirectedVertex.h" @@ -138,7 +141,7 @@ class UndirectedHyperedge final : ***************************************************************************/ protected: /// Specific attributes (none) - SpecificAttributes specificAttributes_; + std::unique_ptr<SpecificAttributes> specificAttributes_ = nullptr; }; } // namespace hglib diff --git a/include/hglib/vertex/directed/DirectedVertex.h b/include/hglib/vertex/directed/DirectedVertex.h index ec0b6336664bbe5f873f9602f7baf871b74874d9..71a8aad4eaf529262649b3def9ce56e2c1e54ce4 100644 --- a/include/hglib/vertex/directed/DirectedVertex.h +++ b/include/hglib/vertex/directed/DirectedVertex.h @@ -24,10 +24,12 @@ #ifndef HGLIB_DIRECTEDVERTEX_H #define HGLIB_DIRECTEDVERTEX_H + +#include "hglib/vertex/VertexBase.h" + #include <memory> #include <vector> -#include "hglib/vertex/VertexBase.h" #include "hglib/utils/IsParentOf.h" #include "hglib/utils/types.h" #include "hglib/hyperedge/directed/DirectedHyperedgeBase.h" @@ -120,9 +122,11 @@ class DirectedVertex : public VertexBase { /// Outgoing directed hyperedges std::shared_ptr<GraphElementContainer<Hyperarc_t*>> outHyperarcs_; /// Specific attributes (none) - SpecificAttributes specificAttributes_; + std::unique_ptr<SpecificAttributes> specificAttributes_ = nullptr; }; + } // namespace hglib #include "DirectedVertex.hpp" + #endif // HGLIB_DIRECTEDVERTEX_H diff --git a/include/hglib/vertex/directed/DirectedVertex.hpp b/include/hglib/vertex/directed/DirectedVertex.hpp index 330810581fc2da4352ae275a5c952da412002700..69266057f6e224f512871912e657133276a62a52 100644 --- a/include/hglib/vertex/directed/DirectedVertex.hpp +++ b/include/hglib/vertex/directed/DirectedVertex.hpp @@ -21,10 +21,11 @@ // // **************************************************************************** -#include <iostream> - #include "DirectedVertex.h" +#include <iostream> +#include <memory> + #include "filtered_vector.h" namespace hglib { @@ -38,11 +39,14 @@ namespace hglib { */ template <typename Hyperarc_t> DirectedVertex<Hyperarc_t>::DirectedVertex( - VertexIdType id, std::string name, - const SpecificAttributes& specificAttributes) : - VertexBase(id, name), specificAttributes_(specificAttributes) { + VertexIdType id, + std::string name, + const SpecificAttributes& specificAttributes) : + VertexBase(id, name) { inHyperarcs_ = create_filtered_vector<Hyperarc_t*>(); outHyperarcs_ = create_filtered_vector<Hyperarc_t*>(); + specificAttributes_ = + std::make_unique<SpecificAttributes>(specificAttributes); } @@ -73,6 +77,8 @@ DirectedVertex<Hyperarc_t>::DirectedVertex(const DirectedVertex& other) : VertexBase(other) { inHyperarcs_ = create_filtered_vector<Hyperarc_t*>(); outHyperarcs_ = create_filtered_vector<Hyperarc_t*>(); + specificAttributes_ = + std::make_unique<SpecificAttributes>(*(other.specificAttributes_)); } /* **************************************************************************** @@ -170,11 +176,11 @@ removeInHyperarc(const Hyperarc_t& hyperarcToBeDeleted) { * add a directed vertex to a hypergraph via the function addVertex(). */ template <typename Hyperarc_t> -ArgumentsToCreateVertex<DirectedVertex<Hyperarc_t>> DirectedVertex< - Hyperarc_t>:: +ArgumentsToCreateVertex<DirectedVertex<Hyperarc_t>> +DirectedVertex<Hyperarc_t>:: argumentsToCreateVertex() const { return ArgumentsToCreateVertex<DirectedVertex<Hyperarc_t>>( - name_, specificAttributes_); + name_, *specificAttributes_); } diff --git a/include/hglib/vertex/undirected/UndirectedVertex.h b/include/hglib/vertex/undirected/UndirectedVertex.h index 330beaa30cbd7f06613ce856016b59b9f885d073..4503d58af507528e862699daf1b85dc4cad63330 100644 --- a/include/hglib/vertex/undirected/UndirectedVertex.h +++ b/include/hglib/vertex/undirected/UndirectedVertex.h @@ -24,10 +24,11 @@ #ifndef HGLIB_UNDIRECTEDVERTEX_H #define HGLIB_UNDIRECTEDVERTEX_H +#include "hglib/vertex/VertexBase.h" + #include <memory> #include <vector> -#include "hglib/vertex/VertexBase.h" #include "hglib/vertex/ArgumentsToCreateVertex.h" #include "hglib/hyperedge/undirected/UndirectedHyperedgeBase.h" #include "hglib/utils/IsParentOf.h" @@ -115,7 +116,7 @@ class UndirectedVertex : public VertexBase { /// Hyperedges that contain the undirected vertex std::shared_ptr<GraphElementContainer<Hyperedge_t*>> hyperedges_; /// Specific attributes (none) - SpecificAttributes specificAttributes_; + std::unique_ptr<SpecificAttributes> specificAttributes_ = nullptr; }; } // namespace hglib diff --git a/include/hglib/vertex/undirected/UndirectedVertex.hpp b/include/hglib/vertex/undirected/UndirectedVertex.hpp index 26b094b89af39e703a9a79540af446b5a3bcaf53..ddd32cd5594d85548aaade3b5efa47c906355593 100644 --- a/include/hglib/vertex/undirected/UndirectedVertex.hpp +++ b/include/hglib/vertex/undirected/UndirectedVertex.hpp @@ -23,6 +23,8 @@ #include "UndirectedVertex.h" +#include <memory> + #include "filtered_vector.h" namespace hglib { @@ -38,8 +40,10 @@ template <typename Hyperedge_t> UndirectedVertex<Hyperedge_t>:: UndirectedVertex(VertexIdType id, std::string name, const SpecificAttributes& specificAttributes) : - VertexBase(id, name), specificAttributes_(specificAttributes) { + VertexBase(id, name) { hyperedges_ = create_filtered_vector<Hyperedge_t*>(); + specificAttributes_ = + std::make_unique<SpecificAttributes>(specificAttributes); } @@ -71,6 +75,8 @@ template <typename Hyperedge_t> UndirectedVertex<Hyperedge_t>:: UndirectedVertex(const UndirectedVertex& other) : VertexBase(other) { hyperedges_ = create_filtered_vector<Hyperedge_t*>(); + specificAttributes_ = + std::make_unique<SpecificAttributes>(*(other.specificAttributes_)); } @@ -130,7 +136,7 @@ ArgumentsToCreateVertex<UndirectedVertex<Hyperedge_t>> UndirectedVertex< Hyperedge_t>:: argumentsToCreateVertex() const { return ArgumentsToCreateVertex<UndirectedVertex<Hyperedge_t>>( - name_, specificAttributes_); + name_, *specificAttributes_); } diff --git a/src/hyperedge/directed/DirectedHyperedge.cpp b/src/hyperedge/directed/DirectedHyperedge.cpp index aec3fb9e0c866d6d4298703ce6e7cdc7af6b9ddf..ef6daac668c6ebb7c9beff4c1fd272b8859c1a44 100644 --- a/src/hyperedge/directed/DirectedHyperedge.cpp +++ b/src/hyperedge/directed/DirectedHyperedge.cpp @@ -15,6 +15,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.*/ #include "hglib/hyperedge/directed/DirectedHyperedge.h" +#include <memory> + namespace hglib { /** @@ -30,8 +32,10 @@ DirectedHyperedge::DirectedHyperedge( std::shared_ptr<GraphElementContainer<Vertex_t*>> tails, std::shared_ptr<GraphElementContainer<Vertex_t*>> heads, const SpecificAttributes& specificAttributes) : - DirectedHyperedgeBase(id, tails, heads), - specificAttributes_(specificAttributes) {} + DirectedHyperedgeBase(id, tails, heads) { + specificAttributes_ = + std::make_unique<SpecificAttributes>(specificAttributes); +} /** @@ -40,8 +44,10 @@ DirectedHyperedge::DirectedHyperedge( * \param other To be copied DirectedHyperedge. */ DirectedHyperedge::DirectedHyperedge(const DirectedHyperedge& other) : - DirectedHyperedgeBase(other), - specificAttributes_(other.specificAttributes_) {} + DirectedHyperedgeBase(other) { + specificAttributes_ = + std::make_unique<SpecificAttributes>(*(other.specificAttributes_)); +} /** @@ -78,7 +84,7 @@ argumentsToCreateHyperarc() const { heads.push_back(vertex->id()); } return ArgumentsToCreateDirectedHyperedge<DirectedHyperedge>( - std::make_pair(tails, heads), specificAttributes_); + std::make_pair(tails, heads), *specificAttributes_); } /** diff --git a/src/hyperedge/directed/NamedDirectedHyperedge.cpp b/src/hyperedge/directed/NamedDirectedHyperedge.cpp index 6ee2a2ce75640c2e5e1f466295ceb77c598f9af1..fb0d684c719a154929a46d48f3679ffdfa03c1af 100644 --- a/src/hyperedge/directed/NamedDirectedHyperedge.cpp +++ b/src/hyperedge/directed/NamedDirectedHyperedge.cpp @@ -14,6 +14,9 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.*/ #include "hglib/hyperedge/directed/NamedDirectedHyperedge.h" + +#include <memory> + #include "hglib/hyperedge/directed/ArgumentsToCreateDirectedHyperedge.h" namespace hglib { @@ -32,8 +35,10 @@ NamedDirectedHyperedge( std::shared_ptr<GraphElementContainer<DirectedVertex_t*>> tails, std::shared_ptr<GraphElementContainer<DirectedVertex_t*>> heads, const SpecificAttributes& specificAttributes) : - DirectedHyperedgeBase(id, tails, heads), - specificAttributes_(specificAttributes) {} + DirectedHyperedgeBase(id, tails, heads) { + specificAttributes_ = + std::make_unique<SpecificAttributes>(specificAttributes); +} /** @@ -43,8 +48,10 @@ NamedDirectedHyperedge( */ NamedDirectedHyperedge:: NamedDirectedHyperedge(const NamedDirectedHyperedge& other) : - DirectedHyperedgeBase(other), - specificAttributes_(other.specificAttributes_) {} + DirectedHyperedgeBase(other) { + specificAttributes_ = + std::make_unique<SpecificAttributes>(*(other.specificAttributes_)); +} /** @@ -90,7 +97,7 @@ argumentsToCreateHyperarc() const { heads.push_back(vertex->id()); } return ArgumentsToCreateDirectedHyperedge<NamedDirectedHyperedge>( - std::make_pair(tails, heads), specificAttributes_); + std::make_pair(tails, heads), *specificAttributes_); } @@ -105,7 +112,7 @@ argumentsToCreateHyperarc() const { */ void NamedDirectedHyperedge:: print(std::ostream& out) const { - out << specificAttributes_.name_ << ": "; + out << specificAttributes_->name_ << ": "; DirectedHyperedgeBase<DirectedVertex_t>::printTailsAndHeads(out); } @@ -133,7 +140,8 @@ bool NamedDirectedHyperedge:: compare(const std::vector<const DirectedVertex_t*>& tails, const std::vector<const DirectedVertex_t*>& heads, const SpecificAttributes& specificAttributes) const { - return specificAttributes.name_.compare(specificAttributes_.name_) == 0 and + return specificAttributes.name_.compare(specificAttributes_->name_) == 0 and DirectedHyperedgeBase<DirectedVertex_t>::compare(tails, heads); } + } // namespace hglib diff --git a/src/hyperedge/undirected/NamedUndirectedHyperedge.cpp b/src/hyperedge/undirected/NamedUndirectedHyperedge.cpp index d1a75e0b03a3be804b6640bb2e55faab18914a62..b19a608e16b212028acf72b42977d613991bb698 100644 --- a/src/hyperedge/undirected/NamedUndirectedHyperedge.cpp +++ b/src/hyperedge/undirected/NamedUndirectedHyperedge.cpp @@ -14,6 +14,9 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.*/ #include "hglib/hyperedge/undirected/NamedUndirectedHyperedge.h" + +#include <memory> + #include "hglib/hyperedge/undirected/ArgumentsToCreateUndirectedHyperedge.h" namespace hglib { @@ -30,8 +33,10 @@ NamedUndirectedHyperedge(int id, std::shared_ptr< GraphElementContainer<Vertex_t*>> vertices, const SpecificAttributes& specificAttributes) : - UndirectedHyperedgeBase(id, vertices), - specificAttributes_(specificAttributes) {} + UndirectedHyperedgeBase(id, vertices) { + specificAttributes_ = + std::make_unique<SpecificAttributes>(specificAttributes); +} /** @@ -41,8 +46,10 @@ NamedUndirectedHyperedge(int id, */ NamedUndirectedHyperedge:: NamedUndirectedHyperedge(const NamedUndirectedHyperedge& other) : - UndirectedHyperedgeBase(other), - specificAttributes_(other.specificAttributes_) {} + UndirectedHyperedgeBase(other) { + specificAttributes_ = + std::make_unique<SpecificAttributes>(*(other.specificAttributes_)); +} /** @@ -82,7 +89,7 @@ argumentsToCreateHyperedge() const { vertices.push_back(vertex->id()); } return ArgumentsToCreateUndirectedHyperedge<NamedUndirectedHyperedge>( - vertices, specificAttributes_); + vertices, *specificAttributes_); } /** @@ -100,7 +107,7 @@ argumentsToCreateHyperedge() const { */ void NamedUndirectedHyperedge:: print(std::ostream& out) const { - out << specificAttributes_.name_ << ": "; + out << specificAttributes_->name_ << ": "; UndirectedHyperedgeBase<Vertex_t>::printVertices(out); } @@ -124,7 +131,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(specificAttributes_->name_) == 0 and UndirectedHyperedgeBase<Vertex_t>::compare(vertices); } } // namespace hglib diff --git a/src/hyperedge/undirected/UndirectedHyperedge.cpp b/src/hyperedge/undirected/UndirectedHyperedge.cpp index ecbdde296b8cc9c5448710fb626cc4dbbfda334a..18abc03a22f6f13d5c7d9c89f748384e367ee074 100644 --- a/src/hyperedge/undirected/UndirectedHyperedge.cpp +++ b/src/hyperedge/undirected/UndirectedHyperedge.cpp @@ -15,6 +15,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.*/ #include "hglib/hyperedge/undirected/UndirectedHyperedge.h" +#include <memory> + namespace hglib { /** * \brief UndirectedHyperedge constructor @@ -27,8 +29,10 @@ UndirectedHyperedge:: UndirectedHyperedge(int id, std::shared_ptr<GraphElementContainer<Vertex_t*>> vertices, const SpecificAttributes& specificAttributes) : - UndirectedHyperedgeBase(id, vertices), - specificAttributes_(specificAttributes) {} + UndirectedHyperedgeBase(id, vertices) { + specificAttributes_ = + std::make_unique<SpecificAttributes>(specificAttributes); +} /** @@ -38,8 +42,10 @@ UndirectedHyperedge(int id, */ UndirectedHyperedge:: UndirectedHyperedge(const UndirectedHyperedge& other) : - UndirectedHyperedgeBase(other), - specificAttributes_(other.specificAttributes_) {} + UndirectedHyperedgeBase(other) { + specificAttributes_ = + std::make_unique<SpecificAttributes>(*(other.specificAttributes_)); +} /** @@ -74,7 +80,7 @@ argumentsToCreateHyperedge() const { vertices.push_back(vertex->id()); } return ArgumentsToCreateUndirectedHyperedge<UndirectedHyperedge>(vertices, - specificAttributes_); + *specificAttributes_); }