Evoplex  0.2.1
node.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 NODE_H
18 #define NODE_H
19 
20 #include <memory>
21 #include <unordered_map>
22 
23 #include "attributes.h"
24 #include "edges.h"
25 
26 namespace evoplex {
27 
28 class BaseNode;
29 using NodePtr = std::shared_ptr<BaseNode>;
30 
35 class Node
36 {
37  friend class AbstractGraph;
38  friend class NodesPrivate;
39  friend class TestNodes;
40 
41 public:
46  Node(NodePtr node);
51  Node(const std::pair<const int, Node>& p);
56  Node(const std::pair<const int, Edge>& p);
58  Node();
59 
63  Node& operator=(const Node& n);
64 
68  bool operator==(const Node& n) const;
69 
73  bool operator!=(const Node& n) const;
74 
78  bool isNull() const;
79 
81  NodePtr clone() const;
83  int id() const;
85  float x() const;
87  float y() const;
88 
90  const Attributes& attrs() const;
92  const Value& attr(int id) const;
94  Value attr(const QString& name, Value defaultValue=Value()) const;
95 
97  Node randNeighbour(PRG* prg) const;
99  const Edges& inEdges() const;
101  const Edges& outEdges() const;
102 
104  int degree() const;
106  int inDegree() const;
108  int outDegree() const;
109 
111  void setAttr(const int id, const Value& value);
113  void setX(float x);
115  void setY(float y);
117  void setCoords(float x, float y);
118 
119 private:
120  NodePtr m_ptr;
121 };
122 
123 } // evoplex
124 #endif // NODE_P_H
A class for variant data types (tagged union).
Definition: value.h:56
const Edges & outEdges() const
Gets the edges leaving the node.
void setX(float x)
Sets the node&#39;s x coordinate.
It wraps a std::shared_ptr<BaseNode>.
Definition: node.h:35
A collection of utility functions for creating and saving nodes.
Definition: nodes_p.h:32
const Value & attr(int id) const
Gets the value of the attribute at id.
float y() const
Gets the node&#39;s y coordinate.
Node randNeighbour(PRG *prg) const
Gets a random neighbour.
void setY(float y)
Sets the node&#39;s y coordinate.
float x() const
Gets the node&#39;s x coordinate.
const Attributes & attrs() const
Gets all the node&#39;s Attributes.
bool isNull() const
Checks if the current Node is null.
bool operator==(const Node &n) const
Checks if n and the current Node point to the same BaseNode.
const Edges & inEdges() const
Gets the edges entering the node.
int degree() const
Gets the node&#39;s degree.
NodePtr clone() const
Creates a new std::shared_ptr<BaseNode> with the same data of the current Node.
int outDegree() const
Gets the node&#39;s out-degree, i.e., the number of edges leaving the node.
Node()
Constructor.
void setCoords(float x, float y)
Sets the node&#39;s coordinates.
Node & operator=(const Node &n)
Sets the current node to n.
Pseudo-random number generator.
Definition: prg.h:29
int inDegree() const
Gets the node&#39;s in-degree, i.e., the number of edges entering the node.
void setAttr(const int id, const Value &value)
Sets the value at id.
bool operator!=(const Node &n) const
Checks if n and the current Node point to the same BaseNode.
Definition: abstractgraph.h:29
A container of labeled values.
Definition: attributes.h:39
Abstract base class for graph plugins.
Definition: abstractgraph.h:54
int id() const
Gets the node&#39;s id.
An Edge container.
Definition: edges.h:32