DiaDes  0.1
DIAgnosis of Discrete-Event System
NodeImpl.hh
Go to the documentation of this file.
1 #ifndef __DIADES__GRAPH__NODEIMPL__HH
2 #define __DIADES__GRAPH__NODEIMPL__HH
3 
4 #include <sstream>
5 #include <list>
9 #include <diades/graph/Edge.hh>
10 #include <diades/graph/Node.hh>
11 #include <diades/graph/GraphInt.hh>
12 #include <diades/graph/EdgeImpl.hh>
13 
14 
15 
16 namespace Diades {
17  namespace Graph {
18  using std::cout;
19 
23  inline bool Node::valid() const {
24  return (_nData != nullptr) && (_nData->isValid());
25  }
26 
31  inline const Graph & NodeData::owner() const {
32  require(Exception, isValid(), "owner: invalid node data (no owner)");
33  return *_owner;
34  }
35 
39  inline void NodeData::setOwner(Graph & newOwner) {
40  _owner = &newOwner;
41  }
42 
46  inline const Graph & Node::owner() const {
47  require(Exception, valid(), "owner: invalid node (no node data)");
48  return _nData->owner();
49  }
50 
52  inline void Node::printInformation() const {
53  if (valid()) {
54  cout << "Node Id: " << id() << "\n";
55  cout << "Node Owner: " << &owner() << "\n";
56  cout << "Number of input edges: " << inDeg() << "\n";
57  cout << "Number of output edges: " << outDeg() << "\n";
58  } else {
59  cout << "Invalid node" << "\n";
60  }
61  }
62 
70  inline void Node::create(NodeId idt, Graph * own) {
71  require(Exception, _nData == nullptr, "create: _nData is not null");
72  require(Exception, own != nullptr, "create: own is null");
73 
74  _nData = new NodeData();
75  _nData->setOwner(*own);
76  _nData->setIdentifier(idt);
77  ensure(Exception, valid(), "Node::create: invalid node");
78  }
79 
83  inline bool Node::operator<(const Node & node) const {
84  if (!valid()) {
85  return node.valid();
86  }
87  if (!node.valid()) {
88  return false;
89  }
90  if (&owner() != &(node.owner())) {
91  return &owner() < &(node.owner());
92  }
93  return id() < node.id();
94  }
95 
96 
97  // template<class Archive>
98  // void Node::save(Archive & ar, const unsigned int version) const
99  // {
100  // Graph g = owner();
101  // ar & g;
102  // NodeId idt = id();
103  // ar & idt;
104  // }
105  //
106  //
107  // template<class Archive>
108  // void Node::load(Archive & ar, const unsigned int version)
109  // {
110  // Graph g;
111  // ar & g;
112  // NodeId id;
113  // ar & id;
114  // if(g.valid())
115  // {
116  // operator=(g.getNode(id));
117  // }
118  // else
119  // {
120  // _nData = 0;
121  // }
122  // }
123  };
124 };
125 
126 #endif
bool valid() const
Definition: NodeImpl.hh:23
SizeType inDeg() const
Definition: Node.hh:148
const Graph & owner() const
Definition: NodeImpl.hh:31
#define ensure(Exception, expr, message)
Definition: Assertion.hh:98
const Graph & owner() const
Definition: NodeImpl.hh:46
NodeData * _nData
Definition: Node.hh:298
void setOwner(Graph &newOwner)
Definition: NodeImpl.hh:39
bool isValid() const
Definition: Node.hh:202
SizeType outDeg() const
Definition: Node.hh:138
void setIdentifier(NodeId newId)
Definition: NodeData.hh:163
#define require(Exception, expr, message)
Definition: Assertion.hh:90
Namespace of the Diades project.
bool operator<(const Node &node) const
Definition: NodeImpl.hh:83
NodeId id() const
Definition: Node.hh:248
boost::adjacency_list Graph
Definition: ScaleFree.cc:9
bool isValid() const
Definition: NodeData.hh:57
SizeType NodeId
Definition: Node.hh:42
void create(NodeId idt, Graph *own)
Definition: NodeImpl.hh:70
void printInformation() const
Definition: NodeImpl.hh:52