fw4spl
Bookmarks.cpp
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 #include "fwTools/Bookmarks.hpp"
8 
9 #include "fwTools/Object.hpp"
10 
11 namespace fwTools
12 {
13 Bookmarks::Dictionary Bookmarks::m_dictionary;
14 
15 //-----------------------------------------------------------------------------
16 
17 Bookmarks::Bookmarks()
18 {
19 }
20 
21 //-----------------------------------------------------------------------------
22 
23 Bookmarks::~Bookmarks()
24 {
25 }
26 
27 //-----------------------------------------------------------------------------
28 
29 bool Bookmarks::exist( Bookmarks::BookmarkName _id)
30 {
31  return m_dictionary.find( _id ) != m_dictionary.end();
32 }
33 
34 //-----------------------------------------------------------------------------
35 
36 void Bookmarks::add( Bookmarks::BookmarkName _bookmark, ::fwTools::Object::sptr obj )
37 {
38  OSLM_FATAL_IF("Try to set a Bookmarks on a null object ", !obj );
39  m_dictionary[ _bookmark ] = obj;
40 }
41 
42 //-----------------------------------------------------------------------------
43 
44 void Bookmarks::remove( Bookmarks::BookmarkName _bookmark )
45 {
46  m_dictionary.erase( m_dictionary.find( _bookmark ) );
47 }
48 
49 //-----------------------------------------------------------------------------
50 
51 ::fwTools::Object::sptr Bookmarks::getObject( Bookmarks::BookmarkName _bookmark )
52 {
53  ::fwTools::Object::sptr bookmark;
54  Dictionary::iterator iter = m_dictionary.find( _bookmark );
55  if ( iter != m_dictionary.end() && !iter->second.expired() )
56  {
57  bookmark = iter->second.lock();
58  }
59  return bookmark;
60 }
61 
62 //-----------------------------------------------------------------------------
63 
64 std::list<Bookmarks::BookmarkName> Bookmarks::getBookmarks( ::fwTools::Object::sptr obj )
65 {
66  std::list<Bookmarks::BookmarkName> result;
67  for( Bookmarks::Dictionary::value_type elt : m_dictionary)
68  {
69  if ( !elt.second.expired() && elt.second.lock() == obj )
70  {
71  result.push_back( elt.first );
72  }
73  }
74  return result;
75 }
76 
77 //-----------------------------------------------------------------------------
78 
79 std::list<Bookmarks::BookmarkName> Bookmarks::getBookmarks()
80 {
81  std::list<Bookmarks::BookmarkName> result;
82  for( Bookmarks::Dictionary::value_type elt : m_dictionary)
83  {
84  result.push_back( elt.first );
85  }
86  return result;
87 }
88 
89 //-----------------------------------------------------------------------------
90 
91 }
The namespace fwTools contains several tools like UUID, factory, dispatche, stringizer, macros, helper.
static FWTOOLS_API std::list< BookmarkName > getBookmarks()
Retrieves the list of bookmarks.
Definition: Bookmarks.cpp:79
static FWTOOLS_API bool exist(BookmarkName _bookmark)
Tests if the given id exist (i.e recorded in Bookmarks dictionary)
Definition: Bookmarks.cpp:29
static FWTOOLS_API void remove(Bookmarks::BookmarkName _bookmark)
silently remove given bookmark
Definition: Bookmarks.cpp:44
static FWTOOLS_API std::shared_ptr< ::fwTools::Object > getObject(BookmarkName _bookmark)
Retrieves the object attached to the given id. Return a null sptr if no correspondence exist...
Definition: Bookmarks.cpp:51
#define OSLM_FATAL_IF(message, cond)
Definition: spyLog.hpp:289