fw4spl
fwMedDataCamp/include/fwMedDataCamp/camp/mapper.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2016.
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 __FWMEDDATACAMP_CAMP_MAPPER_HPP__
8 #define __FWMEDDATACAMP_CAMP_MAPPER_HPP__
9 
10 #include <fwCamp/Mapper/ValueMapper.hpp>
11 
12 #include <fwMedData/NavigationSeries.hpp>
13 
14 #include <boost/algorithm/string.hpp>
15 
16 namespace camp_ext
17 {
18 
19 template <>
20 struct ValueMapper< ::fwMedData::NavigationSeries::CoordinateType >
21 {
22  typedef ::fwMedData::NavigationSeries::CoordinateType ReturnType;
23  static const int type = camp::stringType;
24  static const std::string to(const ReturnType& source)
25  {
26  std::string result;
27 
28  std::string current = ::boost::lexical_cast<std::string>(source[0]);
29  result += current;
30  result += ";";
31 
32  current = ::boost::lexical_cast<std::string>(source[1]);
33  result += current;
34  result += ";";
35 
36  current = ::boost::lexical_cast<std::string>(source[2]);
37  result += current;
38  result += ";";
39 
40  return result;
41  }
42 
43  static ReturnType from(bool source)
44  {
45  CAMP_ERROR(camp::BadType(camp::boolType, camp::mapType<ReturnType>()));
46  }
47  static ReturnType from(long source)
48  {
49  CAMP_ERROR(camp::BadType(camp::intType, camp::mapType<ReturnType>()));
50  }
51  static ReturnType from(double source)
52  {
53  CAMP_ERROR(camp::BadType(camp::realType, camp::mapType<ReturnType>()));
54  }
55  static ReturnType from(const camp::EnumObject& source)
56  {
57  CAMP_ERROR(camp::BadType(camp::enumType, camp::mapType<ReturnType>()));
58  }
59  static ReturnType from(const camp::UserObject& source)
60  {
61  CAMP_ERROR(camp::BadType(camp::userType, camp::mapType<ReturnType>()));
62  }
63  static ReturnType from(const std::string& source)
64  {
65  std::vector< std::string> result;
66  ReturnType coord;
67  ::boost::split(result, source, ::boost::is_any_of(";"));
68 
69  if(result.size() >= 3)
70  {
71  coord[0] = ValueMapper<double>::from(result[0]);
72  coord[1] = ValueMapper<double>::from(result[1]);
73  coord[2] = ValueMapper<double>::from(result[2]);
74  }
75  else
76  {
77  OSLM_WARN("Invalid number of components: " << result.size());
78  }
79  return coord;
80  }
81 };
82 
83 } //camp_ext
84 
85 #endif /* __FWMEDDATACAMP_CAMP_MAPPER_HPP__ */
#define OSLM_WARN(message)
Definition: spyLog.hpp:263