7 #ifndef __FWCAMP_MAPPER_VALUEMAPPER_HPP__ 8 #define __FWCAMP_MAPPER_VALUEMAPPER_HPP__ 10 #include <boost/date_time/posix_time/posix_time.hpp> 11 #include <boost/filesystem/path.hpp> 12 #include <boost/lexical_cast.hpp> 13 #include <boost/logic/tribool.hpp> 15 #include <camp/camptype.hpp> 16 #include <camp/type.hpp> 17 #include <camp/valuemapper.hpp> 23 struct ValueMapper<
std::uint64_t>
26 static const int type = camp::intType;
29 static std::string to(
const std::uint64_t& source)
31 return boost::lexical_cast<std::string>(source);
37 static std::uint64_t from(
const T& source)
39 return boost::lexical_cast< std::uint64_t>(source);
50 static ::boost::logic::tribool
get(
const T& source)
52 return ::boost::logic::tribool();
63 static ::boost::logic::tribool
get(
const std::string& source)
65 ::boost::logic::tribool value;
67 if (source.compare(
"true") == 0)
71 else if (source.compare(
"false") == 0)
77 value = boost::logic::indeterminate;
87 struct ValueMapper< ::boost::logic::tribool>
90 static const int type = camp::stringType;
93 static std::string to(const ::boost::logic::tribool& source)
107 value =
"indeterminate";
113 template <
typename T>
114 static ::boost::logic::tribool from(
const T& source)
123 struct ValueMapper< ::boost::posix_time::ptime >
125 typedef boost::posix_time::ptime ReturnType;
126 static const int type = camp::stringType;
129 static const std::string to(
const ReturnType& source)
131 return boost::posix_time::to_simple_string(source);
136 static ReturnType from(
bool source)
138 CAMP_ERROR(camp::BadType(camp::boolType, camp::mapType<ReturnType>()));
142 static ReturnType from(
long source)
144 CAMP_ERROR(camp::BadType(camp::intType, camp::mapType<ReturnType>()));
148 static ReturnType from(
double source)
150 CAMP_ERROR(camp::BadType(camp::realType, camp::mapType<ReturnType>()));
154 static ReturnType from(
const camp::EnumObject& source)
156 CAMP_ERROR(camp::BadType(camp::enumType, camp::mapType<ReturnType>()));
160 static ReturnType from(
const camp::UserObject& source)
162 CAMP_ERROR(camp::BadType(camp::userType, camp::mapType<ReturnType>()));
166 static ReturnType from(
const std::string& source)
168 return boost::posix_time::time_from_string(source);
175 struct ValueMapper< ::boost::filesystem::path >
177 typedef ::boost::filesystem::path ReturnType;
178 static const int type = camp::stringType;
181 static const std::string to(
const ReturnType& source)
183 return source.string();
188 static ReturnType from(
bool source)
190 CAMP_ERROR(camp::BadType(camp::boolType, camp::mapType<ReturnType>()));
194 static ReturnType from(
long source)
196 CAMP_ERROR(camp::BadType(camp::intType, camp::mapType<ReturnType>()));
200 static ReturnType from(
double source)
202 CAMP_ERROR(camp::BadType(camp::realType, camp::mapType<ReturnType>()));
206 static ReturnType from(
const camp::EnumObject& source)
208 CAMP_ERROR(camp::BadType(camp::enumType, camp::mapType<ReturnType>()));
212 static ReturnType from(
const camp::UserObject& source)
214 CAMP_ERROR(camp::BadType(camp::userType, camp::mapType<ReturnType>()));
218 static ReturnType from(
const std::string& source)
220 return ::boost::filesystem::path(source);
230 struct ValueMapper<unsigned char>
232 static const int type = camp::stringType;
235 static std::string to(
unsigned char source)
237 unsigned int intValue = boost::numeric_cast<
unsigned int>(source);
239 return boost::lexical_cast<std::string>(intValue);
244 static unsigned char from(
bool source)
246 return static_cast<unsigned char>(source);
250 static unsigned char from(
long source)
252 return static_cast<unsigned char>(source);
256 static unsigned char from(
double source)
258 return static_cast<unsigned char>(source);
262 static unsigned char from(
const std::string& source)
264 unsigned int intValue = boost::lexical_cast<
unsigned int>(source);
265 return boost::numeric_cast<
unsigned char>(intValue);
269 static unsigned char from(
const camp::EnumObject& source)
271 return static_cast<unsigned char>(source.value());
275 static unsigned char from(
const camp::UserObject&)
277 CAMP_ERROR(camp::BadType(camp::userType, camp::realType));
283 template <
typename T>
284 struct ValueMapper<
std::shared_ptr<T> >
286 typedef std::shared_ptr<T> ReturnType;
287 static const int type = camp::userType;
290 static const camp::UserObject to(
const ReturnType& source)
292 return camp::UserObject(source);
297 static ReturnType from(
bool source)
299 CAMP_ERROR(camp::BadType(camp::boolType, camp::mapType<ReturnType>()));
303 static ReturnType from(
long source)
305 CAMP_ERROR(camp::BadType(camp::intType, camp::mapType<ReturnType>()));
309 static ReturnType from(
double source)
311 CAMP_ERROR(camp::BadType(camp::realType, camp::mapType<ReturnType>()));
315 static ReturnType from(
const std::string& source)
317 CAMP_ERROR(camp::BadType(camp::stringType, camp::mapType<ReturnType>()));
321 static ReturnType from(
const camp::EnumObject& source)
323 CAMP_ERROR(camp::BadType(camp::enumType, camp::mapType<ReturnType>()));
327 static ReturnType from(
const camp::UserObject& source)
332 T* ptr = source.get< T* >();
333 result = T::dynamicCast(ptr->getSptr());
337 std::shared_ptr<T> tmp;