fw4spl
core/fwMedDataTools/src/fwMedDataTools/helper/SeriesDB.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2016.
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 #include "fwMedDataTools/helper/SeriesDB.hpp"
8 
9 #include <fwCom/Signal.hpp>
10 #include <fwCom/Signal.hxx>
11 #include <fwCom/Signals.hpp>
12 
13 #include <fwMedData/SeriesDB.hpp>
14 
15 namespace fwMedDataTools
16 {
17 namespace helper
18 {
19 
20 //-----------------------------------------------------------------------------
21 
22 SeriesDB::SeriesDB( ::fwMedData::SeriesDB::wptr seriesDB ) :
23  m_seriesDB ( seriesDB )
24 {
25 }
26 
27 //-----------------------------------------------------------------------------
28 
30 {
31 }
32 
33 //-----------------------------------------------------------------------------
34 
35 void SeriesDB::add( ::fwMedData::Series::sptr newSeries )
36 {
37  ::fwMedData::SeriesDB::sptr seriesDB = m_seriesDB.lock();
38  OSLM_ASSERT( "The object " << newSeries->getID() << " must not exist in SeriesDB.",
39  std::find(seriesDB->begin(), seriesDB->end(), newSeries) == seriesDB->end());
40 
41  // Modify SeriesDB
42  seriesDB->getContainer().push_back( newSeries );
43 
44  m_addedSeries.push_back(newSeries);
45 
46 }
47 
48 //-----------------------------------------------------------------------------
49 
50 void SeriesDB::remove( ::fwMedData::Series::sptr oldSeries )
51 {
52  ::fwMedData::SeriesDB::sptr seriesDB = m_seriesDB.lock();
53  ::fwMedData::SeriesDB::iterator iter = std::find(seriesDB->begin(), seriesDB->end(), oldSeries);
54  OSLM_ASSERT( "The object " << oldSeries->getID() << " must exist in SeriesDB.",
55  iter != seriesDB->end());
56 
57  // Modify SeriesDB
58  seriesDB->getContainer().erase( iter );
59 
60  m_removedSeries.push_back( oldSeries );
61 
62 }
63 
64 //-----------------------------------------------------------------------------
65 
67 {
68  ::fwMedData::SeriesDB::sptr seriesDB = m_seriesDB.lock();
69 
70  while (!seriesDB->empty())
71  {
72  this->remove(seriesDB->front());
73  }
74 }
75 
76 //-----------------------------------------------------------------------------
77 
78 void SeriesDB::merge(::fwMedData::SeriesDB::sptr seriesDBIn)
79 {
80  ::fwMedData::SeriesDB::ContainerType& vectIn = seriesDBIn->getContainer();
81  for(::fwMedData::Series::sptr series : vectIn)
82  {
83  this->add(series);
84  }
85 }
86 
87 //-----------------------------------------------------------------------------
88 
90 {
91  if (!m_addedSeries.empty())
92  {
93  auto sig = m_seriesDB.lock()->signal< ::fwMedData::SeriesDB::AddedSeriesSignalType >(
95  sig->asyncEmit(m_addedSeries);
96 
97  }
98 
99  if (!m_removedSeries.empty())
100  {
101  auto sig = m_seriesDB.lock()->signal< ::fwMedData::SeriesDB::RemovedSeriesSignalType >(
103  sig->asyncEmit(m_removedSeries);
104 
105  }
106 
107  OSLM_INFO_IF("No changes were found on the SeriesDB '" + m_seriesDB.lock()->getID() + "', nothing to notify.",
108  m_addedSeries.empty() && m_removedSeries.empty());
109 }
110 
111 //-----------------------------------------------------------------------------
112 
113 } // namespace helper
114 } // namespace fwMedDataTools
#define OSLM_ASSERT(message, cond)
work like &#39;assert&#39; from &#39;cassert&#39;, with in addition a message logged by spylog (with FATAL loglevel) ...
Definition: spyLog.hpp:310
FWMEDDATATOOLS_API SeriesDB(::fwMedData::SeriesDB::wptr seriesDB)
Constructor. Initialize parameters.
#define OSLM_INFO_IF(message, cond)
Definition: spyLog.hpp:256
FWMEDDATATOOLS_API void add(::fwMedData::Series::sptr newSeries)
Add a Series in the SeriesDB.
FWMEDDATATOOLS_API void clear()
Clear all series in the SeriesDB.
static FWMEDDATA_APIconst::fwCom::Signals::SignalKeyType s_ADDED_SERIES_SIG
Type of signal when series are added.
static FWMEDDATA_APIconst::fwCom::Signals::SignalKeyType s_REMOVED_SERIES_SIG
Type of signal when series are added.
FWMEDDATATOOLS_API void remove(::fwMedData::Series::sptr oldSeries)
Remove a Series in the SeriesDB.
FWMEDDATATOOLS_API void notify()
Send the signal of modification.
Contains utilities dedicated to fwMedData.
FWMEDDATATOOLS_API void merge(::fwMedData::SeriesDB::sptr seriesDBIn)
Merge seriesDBIn all series from seriesDBIn to the SeriesDB.