fw4spl
core/fwData/include/fwData/factory/new.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 __FWDATA_FACTORY_NEW_HPP__
8 #define __FWDATA_FACTORY_NEW_HPP__
9 
10 #include "fwData/config.hpp"
11 #include "fwData/registry/detail.hpp"
12 
13 #include <string>
14 
15 namespace fwData
16 {
17 
18 class Object;
19 
20 namespace factory
21 {
22 
23 template<class CLASSNAME > SPTR( CLASSNAME ) New();
24 
29 class Key
30 {
31 private:
32  template<typename CLASSNAME>
33  friend SPTR( CLASSNAME ) fwData::factory::New();
34 
35  Key()
36  {
37  }
38 };
39 
40 FWDATA_API SPTR( ::fwData::Object ) New( const ::fwData::registry::KeyType & classname );
41 
42 template<class CLASSNAME > SPTR( CLASSNAME ) New()
43 {
44  SPTR(CLASSNAME) obj = std::make_shared< CLASSNAME >( Key() );
45  return obj;
46 }
47 
48 } // namespace factory
49 
50 } // namespace fwData
51 
52 #endif /* __FWDATA_FACTORY_NEW_HPP__ */
53 
#define SPTR(_cls_)
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
Contains fwAtomsFilter::factory utilities.
Base class for each data object.
Contains the representation of the data objects used in the framework.