Evoplex  0.2.1
edge.h
1 /* Evoplex <https://evoplex.org>
2  * Copyright (C) 2016-present - Marcos Cardinot <marcos@cardinot.net>
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef EDGE_H
18 #define EDGE_H
19 
20 #include <memory>
21 #include <unordered_map>
22 
23 #include "attributes.h"
24 
25 namespace evoplex {
26 
27 class Node;
28 class BaseEdge;
29 using EdgePtr = std::shared_ptr<BaseEdge>;
30 
37 class Edge
38 {
39  friend class AbstractGraph;
40  friend class TestEdge;
41 
42 public:
47  Edge(EdgePtr edge);
52  Edge(const std::pair<const int, Edge>& p);
54  Edge();
55 
57  int id() const;
59  const Node& origin() const;
61  const Node& neighbour() const;
62 
64  const Attributes* attrs() const;
66  const Value& attr(int id) const;
68  Value attr(const QString& name, Value defaultValue=Value()) const;
69 
71  void setAttr(const int id, const Value& value);
73  void addAttr(QString name, Value value);
74 
75 private:
76  EdgePtr m_ptr;
77 };
78 
79 } // evoplex
80 #endif // EDGE_H
A class for variant data types (tagged union).
Definition: value.h:56
It wraps a std::shared_ptr<BaseNode>.
Definition: node.h:35
const Node & neighbour() const
Gets the target Node.
void setAttr(const int id, const Value &value)
Sets the value at id.
const Value & attr(int id) const
Gets the value of the attribute at id.
Edge()
Constructor.
An Edge connects a Node to itself or to another Node.
Definition: edge.h:37
int id() const
Gets the edge&#39;s id.
const Node & origin() const
Gets the source Node.
Definition: abstractgraph.h:29
A container of labeled values.
Definition: attributes.h:39
Abstract base class for graph plugins.
Definition: abstractgraph.h:54
const Attributes * attrs() const
Gets the edge&#39;s attributes.
void addAttr(QString name, Value value)
Appends the attribute name with the value value.