fw4spl
StructuralPatchDB.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
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 
8 #include "fwAtomsPatch/StructuralPatchDB.hpp"
9 
10 namespace fwAtomsPatch
11 {
12 
13 StructuralPatchDB::sptr StructuralPatchDB::s_default = std::make_shared<StructuralPatchDB>();
14 
15 void StructuralPatchDB::registerPatch(::fwAtomsPatch::IStructuralPatch::sptr patch)
16 {
17  VersionIDType source = std::make_pair(patch->getOriginClassname(), patch->getOriginVersion());
18  VersionIDType target = std::make_pair(patch->getTargetClassname(), patch->getTargetVersion());
19  PatchKeyType key = std::make_pair(source, target);
20  ::fwCore::mt::WriteLock lock(m_mutex);
21  m_patches[key] = patch;
22 }
23 
24 // ----------------------------------------------------------------------------
25 
26 ::fwAtomsPatch::IStructuralPatch::sptr StructuralPatchDB::getPatch(const std::string& originClassname,
27  const std::string& originVersion,
28  const std::string& targetClassname,
29  const std::string& targetVersion) const
30 {
31  const VersionIDType source = std::make_pair(originClassname, originVersion);
32  const VersionIDType target = std::make_pair(targetClassname, targetVersion);
33  const PatchKeyType key = std::make_pair(source, target);
34 
35  ::fwCore::mt::ReadLock lock(m_mutex);
36  PatchesType::const_iterator it = m_patches.find(key);
37  if(it != m_patches.end())
38  {
39  return it->second;
40  }
41  else
42  {
43  return ::fwAtomsPatch::IStructuralPatch::sptr();
44  }
45 }
46 
47 // ----------------------------------------------------------------------------
48 
50 {
51  ::fwCore::mt::ReadLock lock(m_mutex);
52  return m_patches.size();
53 }
54 
55 } //fwAtomsPatch
std::pair< VersionIDType, VersionIDType > PatchKeyType
Typedef used to store link to data structure.
FWATOMSPATCH_API size_t size() const
Retrieves number of patch.
FWATOMSPATCH_API void registerPatch(std::shared_ptr< ::fwAtomsPatch::IStructuralPatch > patch)
Registers a new Path.
Contains base functionalities used to transform objects from a version to another.
Definition: Abstract.hpp:16
::boost::unique_lock< ReadWriteMutex > WriteLock
Defines a lock of write type for read/write mutex.
std::pair< std::string, std::string > VersionIDType
Typedef used to store the pair classname/version of a data structure.
::boost::shared_lock< ReadWriteMutex > ReadLock
Defines a lock of read type for read/write mutex.
FWATOMSPATCH_API std::shared_ptr< ::fwAtomsPatch::IStructuralPatch > getPatch(const std::string &originClassname, const std::string &originVersion, const std::string &targetClassname, const std::string &targetVersion) const
Retrieves patch to go to specified data revision.