13#include <boost/python/type_id.hpp>
22using TypeIDMap = std::map<const boost::python::type_info, std::shared_ptr<PropertyValueHandler>>;
28TypeIDMap &typeRegistry() {
29 static TypeIDMap typeHandlers;
42#define SUBSCRIBE_HANDLER(Type) \
43 subscribe<TypedPropertyValueHandler<Type>>(); \
44 subscribe<SequenceTypeHandler<std::vector<Type>>>();
61#undef SUBSCRIBE_HANDLER
72 TypeIDMap &typeHandlers = typeRegistry();
73 boost::python::type_info typeInfo(typeObject);
74 if (typeHandlers.find(typeInfo) == typeHandlers.end()) {
75 typeHandlers.emplace(typeInfo, std::shared_ptr<PropertyValueHandler>(handler));
77 throw std::invalid_argument(std::string(
"TypeRegistry::subscribe() - A handler has already "
78 "registered for type '") +
79 typeInfo.name() +
"'");
90 TypeIDMap &typeHandlers = typeRegistry();
91 TypeIDMap::const_iterator itr = typeHandlers.find(boost::python::type_info(typeObject));
92 if (itr != typeHandlers.end()) {
93 return *(itr->second);
95 throw std::invalid_argument(std::string(
"TypeRegistry::retrieve(): No PropertyValueHandler "
96 "registered for type '") +
97 boost::python::type_info(typeObject).name() +
"'");
#define SUBSCRIBE_HANDLER(Type)
static void subscribe()
Subscribe a handler object for given template type.
static void registerBuiltins()
Register handlers for basic C++ types into the registry.
static const PropertyValueHandler & retrieve(const std::type_info &typeInfo)
Lookup a handler base on a given type_info object.
This class provides a base-class objects that are able to take a python object and set it on an algor...