fw4spl
VersionsGraph.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
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 #ifndef __FWATOMSPATCH_VERSIONSGRAPH_HPP__
8 #define __FWATOMSPATCH_VERSIONSGRAPH_HPP__
9 
10 #include "fwAtomsPatch/LinkDescriptor.hpp"
11 #include "fwAtomsPatch/VersionDescriptor.hpp"
12 #include "fwAtomsPatch/config.hpp"
13 
14 #include <fwCore/BaseObject.hpp>
15 #include <fwCore/mt/types.hpp>
16 
17 #include <boost/graph/adjacency_list.hpp>
18 #include <boost/graph/graph_traits.hpp>
19 
20 namespace fwAtomsPatch
21 {
22 
26 class FWATOMSPATCH_CLASS_API VersionsGraph : public ::fwCore::BaseObject
27 {
28 
29 public:
32 
36  typedef ::fwAtomsPatch::VersionDescriptor NodeType;
37  typedef ::fwAtomsPatch::LinkDescriptor EdgeType;
38  typedef ::boost::adjacency_list< ::boost::listS, ::boost::vecS, ::boost::directedS, NodeType, EdgeType> GraphType;
39  typedef ::boost::graph_traits<GraphType>::vertex_descriptor NodeIDType;
40  typedef ::boost::graph_traits<GraphType>::edge_descriptor EdgeIDType;
41  typedef std::map<NodeType, NodeIDType, ::fwAtomsPatch::VersionDescriptor::Compare> ExistingNodesType;
42  typedef std::map<EdgeType, EdgeIDType, ::fwAtomsPatch::LinkDescriptor::Compare> ExistingEdgesType;
43  typedef std::vector< NodeIDType > VersionSeriesType;
44  typedef std::pair<LinkDescriptor::VersionIDType, bool> LinkedVersionType;
50  FWATOMSPATCH_API VersionsGraph();
51 
55  FWATOMSPATCH_API ~VersionsGraph();
56 
61  FWATOMSPATCH_API void addNode(NodeType node);
62 
67  FWATOMSPATCH_API void addEdge(EdgeType edge);
68 
74  FWATOMSPATCH_API VersionSeriesType shortestPath(const std::string& origin, const std::string& target);
75 
79  FWATOMSPATCH_API NodeType getNode(const NodeIDType& nodeID);
80 
84  FWATOMSPATCH_API NodeIDType getNode(const std::string& name) const;
85 
89  FWATOMSPATCH_API EdgeType getEdge(const NodeIDType& origin, const NodeIDType& target);
90 
95  FWATOMSPATCH_API LinkedVersionType getLinkedVersion(
96  const NodeIDType& originID, const NodeIDType& targetID, LinkDescriptor::VersionIDType current);
97 
101  FWATOMSPATCH_API std::vector< std::string > getConnectedVersions(const std::string& currentVersion);
102 
103 private:
104 
109  FWATOMSPATCH_API NodeIDType createOrUpdateNode(const NodeType& node);
110 
115  FWATOMSPATCH_API EdgeIDType createEdge(const EdgeType& edge);
116 
122  FWATOMSPATCH_API VersionSeriesType shortestPath(const NodeType& origin, const NodeType& target);
123 
125  mutable ::fwCore::mt::ReadWriteMutex m_graphMutex;
126 
128  mutable ::fwCore::mt::ReadWriteMutex m_nodesMutex;
129 
131  mutable ::fwCore::mt::ReadWriteMutex m_edgesMutex;
132 
134  GraphType m_graph;
135 
137  ExistingNodesType m_nodes;
138 
140  ExistingEdgesType m_edges;
141 };
142 
143 } // fwAtomsPatch
144 
145 #endif /* __FWATOMSPATCH_VERSIONSGRAPH_HPP__ */
Base class for all FW4SPL&#39;s classes.
Definition: BaseObject.hpp:22
Version descriptor used to identify a version.
Contains base functionalities used to transform objects from a version to another.
Definition: Abstract.hpp:16
#define fwCoreClassDefinitionsWithFactoryMacro(_classinfo_, _parameters_, _factory_)
Generate common construction methods for classes with one factory.
Link descriptor used to identify a link between two versions.
Versions graph description.
#define fwCoreAllowSharedFromThis()
Generate getSptr and getConstSptr methods.
std::pair< std::string, std::string > VersionIDType
VersionID used to link type and version.