fw4spl
UUID.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 __FWTOOLS_UUID_HPP__
8 #define __FWTOOLS_UUID_HPP__
9 
10 #include "fwTools/config.hpp"
11 #include "fwTools/Object.hpp"
12 
13 #include <fwCore/base.hpp>
14 #include <fwCore/mt/types.hpp>
15 
16 #include <map>
17 #include <string>
18 
19 namespace fwTools
20 {
24 class FWTOOLS_CLASS_API UUID
25 {
26 public:
27 
28  fwCoreClassFactoryMacro((UUID), (( )), new UUID );
29 
30  typedef std::string UUIDType;
31 
36  FWTOOLS_API static bool exist( const UUIDType& uuid);
37 
42  FWTOOLS_API static const UUIDType& get(::fwTools::Object::sptr object);
43 
48  FWTOOLS_API static ::fwTools::Object::sptr get( const UUIDType& uuid );
49 
54  FWTOOLS_API static UUIDType generateUUID();
55 
61  FWTOOLS_API static bool set(::fwTools::Object::sptr object, const UUID::UUIDType& uuid);
62 
66  FWTOOLS_API virtual ~UUID();
67 
68 protected:
69 
71  typedef std::map< UUIDType, ::fwTools::Object::wptr > UUIDContainer;
72 
73  FWTOOLS_API static UUIDContainer s_uuidMap;
74 
78  FWTOOLS_API UUID();
79 
82 
83 private:
84 
86  UUIDType m_uuid;
87 
89  static ::fwCore::mt::ReadWriteMutex s_uuidMapMutex;
90 
92  static ::fwCore::mt::Mutex s_generateUUIDMutex;
93 
94 };
95 
96 }
97 
98 #endif /* __FWTOOLS_UUID_HPP__ */
std::map< UUIDType,::fwTools::Object::wptr > UUIDContainer
Store association std::weak_ptr <–> uuid as a string.
Definition: UUID.hpp:71
The namespace fwTools contains several tools like UUID, factory, dispatche, stringizer, macros, helper.
::boost::shared_mutex ReadWriteMutex
Defines a single writer, multiple readers mutex.
::fwCore::mt::ReadWriteMutex m_uuidMutex
Mutex used to lock uuid object access.
Definition: UUID.hpp:81
Management of UUID on objects.
Definition: UUID.hpp:24
#define fwCoreClassFactoryMacro(_classinfo_, _parameters_, _factory_)
Generate methods for classes with one factory.