fw4spl
fwAtomConversion/include/fwAtomConversion/camp_ext/ValueMapper.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2018.
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 #pragma once
8 
9 #include <fwAtoms/Blob.hpp>
10 
11 #include <fwMemory/BufferObject.hpp>
12 
13 #include <camp/valuemapper.hpp>
14 
15 namespace camp_ext
16 {
17 
19 template <>
20 struct ValueMapper< ::fwAtoms::Blob::sptr >
21 {
22  typedef ::fwAtoms::Blob::sptr ReturnType;
23 
24  static const int type = camp::userType;
25 
26  //------------------------------------------------------------------------------
27 
28  static const ::fwMemory::BufferObject::sptr to(const ReturnType& source)
29  {
30  return source->getBufferObject();
31  }
32 
33  //------------------------------------------------------------------------------
34 
35  static ReturnType from(bool source)
36  {
37  CAMP_ERROR(camp::BadType(camp::boolType, camp::mapType<ReturnType>()));
38  }
39 
40  //------------------------------------------------------------------------------
41 
42  static ReturnType from(long source)
43  {
44  CAMP_ERROR(camp::BadType(camp::intType, camp::mapType<ReturnType>()));
45  }
46 
47  //------------------------------------------------------------------------------
48 
49  static ReturnType from(double source)
50  {
51  CAMP_ERROR(camp::BadType(camp::realType, camp::mapType<ReturnType>()));
52  }
53 
54  //------------------------------------------------------------------------------
55 
56  static ReturnType from(const std::string& source)
57  {
58  CAMP_ERROR(camp::BadType(camp::realType, camp::mapType<ReturnType>()));
59  }
60 
61  //------------------------------------------------------------------------------
62 
63  static ReturnType from(const camp::EnumObject& source)
64  {
65  CAMP_ERROR(camp::BadType(camp::enumType, camp::mapType<ReturnType>()));
66  }
67 
68  //------------------------------------------------------------------------------
69 
70  static ReturnType from(const camp::UserObject& source)
71  {
72  ::fwMemory::BufferObject::sptr tmp = source.get< ::fwMemory::BufferObject::sptr>()->getSptr();
73  return ::fwAtoms::Blob::New(tmp);
74  }
75 };
76 
77 }