fw4spl
fwData/include/fwData/Graph.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2018.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #pragma once
8 
9 #include "fwData/config.hpp"
10 #include "fwData/Edge.hpp"
11 #include "fwData/factory/new.hpp"
12 #include "fwData/Node.hpp"
13 #include "fwData/Object.hpp"
14 
15 #include <map>
16 #include <set>
17 
18 fwCampAutoDeclareDataMacro((fwData)(Graph), FWDATA_API);
19 
20 namespace fwData
21 {
29 class FWDATA_CLASS_API Graph : public ::fwData::Object
30 {
31 
32 public:
33  fwCoreClassDefinitionsWithFactoryMacro( (Graph)(::fwData::Object), (()), ::fwData::factory::New< Graph >);
34 
35  fwCampMakeFriendDataMacro((fwData)(Graph));
36 
37  FWDATA_API static const bool UP_STREAM;
38  FWDATA_API static const bool DOWN_STREAM;
39 
40  typedef std::map< Edge::sptr, std::pair< Node::sptr, Node::sptr > > ConnectionContainer;
41  typedef std::set< Node::sptr > NodeContainer; // Be careful, if you change
42  // we use erase(it++)
43 
45  typedef std::vector< ::fwData::Object::sptr > UpdatedDataType;
46 
51  typedef ::fwCom::Signal< void (UpdatedDataType, UpdatedDataType ) > UpdatedSignalType;
52 
57  FWDATA_API Graph(::fwData::Object::Key key);
58 
60  FWDATA_API virtual ~Graph();
61 
67  FWDATA_API bool addNode( Node::sptr _node);
68 
74  FWDATA_API bool removeNode( Node::csptr _node);
75 
80  FWDATA_API NodeContainer& getNodes();
81  FWDATA_API const NodeContainer& getNodes() const;
83 
91  FWDATA_API const ConnectionContainer& getConnections() const;
92  FWDATA_API ConnectionContainer& getConnections();
93 
102  FWDATA_API bool addEdge(Edge::sptr _edge, Node::csptr _nodeSource, Node::csptr _nodeDestination);
103 
109  FWDATA_API
110  Edge::sptr makeConnection( Node::csptr _nodeSource,
111  std::string _nodeSourceOutputPortID,
112  Node::csptr _nodeDestination,
113  std::string _nodeDestinationInputPortID,
114  std::string _EdgeNature
115  );
116 
123  FWDATA_API bool removeEdge(Edge::sptr _edge);
124 
130  FWDATA_API Node::sptr getSourceNode(Edge::sptr _edge);
131 
137  FWDATA_API Node::sptr getDestinationNode(Edge::sptr _edge);
138 
147  FWDATA_API Node::sptr getNode(Edge::sptr _edge, bool _upStream);
148 
155  FWDATA_API std::vector< Edge::sptr > getInputEdges(Node::csptr _node);
156 
163  FWDATA_API std::vector< Edge::sptr > getOutputEdges(Node::csptr _node);
164 
175  FWDATA_API std::vector< Edge::sptr > getEdges(const Node::csptr& _node, bool _upStream,
176  const std::string& _nature = "",
177  const std::string& _portID = "");
178 
189  FWDATA_API std::vector< ::fwData::Node::sptr > getNodes( const ::fwData::Node::csptr& node, bool upStream,
190  const std::string& nature = "",
191  const std::string& portID = "" );
192 
196  FWDATA_API size_t getNbNodes() const;
197 
201  FWDATA_API size_t getNbEdges() const;
202 
203  FWDATA_API void shallowCopy( const Object::csptr& _source ) override;
204 
205  FWDATA_API void cachedDeepCopy(const Object::csptr& _source, DeepCopyCacheType& cache) override;
206 
212  FWDATA_API bool haveConnectedEdges(Node::csptr _node ) const;
213 
215  FWDATA_API static const ::fwCom::Signals::SignalKeyType s_UPDATED_SIG;
216 
217 protected:
218 
219  NodeContainer m_nodes;
220  ConnectionContainer m_connections;
221 
223  UpdatedSignalType::sptr m_sigUpdated;
224 };
225 
226 } // namespace fwData
This class defines a graph object.
std::vector< ::fwData::Object::sptr > UpdatedDataType
Type of signal m_sigUpdated.
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
::fwCom::Signal< void(UpdatedDataType, UpdatedDataType) > UpdatedSignalType
Update signal type Signal updated is composed of two parameters which represent added and removed ele...
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_UPDATED_SIG
Updated signal key.
#define fwCoreClassDefinitionsWithFactoryMacro(_classinfo_, _parameters_, _factory_)
Generate common construction methods for classes with one factory.
Base class for each data object.
UpdatedSignalType::sptr m_sigUpdated
Updated signal.
Contains the representation of the data objects used in the framework.