8 #ifndef FAIR_MQ_PROPERTIES_H
9 #define FAIR_MQ_PROPERTIES_H
11 #include <fairmq/EventManager.h>
13 #include <boost/any.hpp>
14 #include <boost/core/demangle.hpp>
18 #include <unordered_map>
28 using Property = boost::any;
29 using Properties = std::map<std::string, Property>;
31 struct PropertyChange : Event<std::string> {};
32 struct PropertyChangeAsString : Event<std::string> {};
38 static void AddType(std::string label =
"")
41 label = boost::core::demangle(
typeid(T).name());
43 fTypeInfos[std::type_index(
typeid(T))] = [label](
const Property& p) {
45 ss << boost::any_cast<T>(p);
46 return std::pair<std::string, std::string>{ss.str(), label};
48 fEventEmitters[std::type_index(
typeid(T))] = [](
const fair::mq::EventManager& em,
const std::string& k,
const Property& p) {
49 em.Emit<PropertyChange, T>(k, boost::any_cast<T>(p));
53 static std::string ConvertPropertyToString(
const Property& p)
55 return fTypeInfos.at(p.type())(p).first;
59 static std::pair<std::string, std::string> GetPropertyInfo(
const Property& p)
62 return fTypeInfos.at(p.type())(p);
63 }
catch (std::out_of_range& oor) {
64 return {
"[unidentified_type]",
"[unidentified_type]"};
68 static std::unordered_map<std::type_index, void(*)(
const fair::mq::EventManager&,
const std::string&,
const Property&)> fEventEmitters;
70 static std::unordered_map<std::type_index, std::function<std::pair<std::string, std::string>(
const Property&)>> fTypeInfos;