7 #include "fwTools/fwID.hpp" 9 #include "fwTools/Failed.hpp" 10 #include "fwTools/Object.hpp" 12 #include <fwCore/Demangler.hpp> 14 #include <boost/lexical_cast.hpp> 19 fwID::CategorizedCounter fwID::m_CategorizedCounter;
20 fwID::Dictionary fwID::m_dictionary;
22 ::fwCore::mt::Mutex fwID::s_mutexCounter;
36 return fwID::isIdFound(_id);
41 bool fwID::isIdFound( IDType _id)
43 return m_dictionary.find( _id ) != m_dictionary.end();
59 this->addIDInDictionary(newID);
64 void fwID::addIDInDictionary( IDType newID )
66 OSLM_FATAL_IF(
"Try to set an existing fwID = " << newID, isIdFound(newID));
69 fwID::removeIDfromDictionary(m_id);
72 m_dictionary[ newID ] = ((
Object*)(
this))->getSptr();
85 IDType newID = generate();
87 const_cast<fwID*
>(
this)->addIDInDictionary(newID);
89 else if ( policy ==
EMPTY )
102 fwID::IDType fwID::generate()
const 108 ::fwCore::mt::ScopedLock lock(s_mutexCounter);
109 newID = prefix +
"-" + boost::lexical_cast<std::string>( m_CategorizedCounter[prefix]++ );
111 while (
exist(newID ) );
120 Dictionary::iterator it = m_dictionary.find(requestID);
121 if ( it != m_dictionary.end() )
123 SLM_ASSERT(
"expired object in fwID::Dictionary for id=" + requestID, !it->second.expired() );
124 return it->second.lock();
128 return ::fwTools::Object::sptr();
138 fwID::removeIDfromDictionary(m_id);
144 void fwID::removeIDfromDictionary(IDType _id )
148 m_dictionary.erase(_id);
::boost::upgrade_lock< ReadWriteMutex > ReadToWriteLock
Defines an upgradable lock type for read/write mutex.
::boost::upgrade_to_unique_lock< ReadWriteMutex > UpgradeToWriteLock
Defines a write lock upgraded from ReadToWriteLock.
::boost::shared_mutex ReadWriteMutex
Defines a single writer, multiple readers mutex.
::boost::unique_lock< ReadWriteMutex > WriteLock
Defines a lock of write type for read/write mutex.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
::boost::shared_lock< ReadWriteMutex > ReadLock
Defines a lock of read type for read/write mutex.
#define OSLM_FATAL_IF(message, cond)