/******************************************************************************** * Copyright (C) 2014-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * * copied verbatim in the file "LICENSE" * ********************************************************************************/ #ifndef FAIR_MQ_PROPERTIES_H #define FAIR_MQ_PROPERTIES_H #include #include #include #include #include #include #include #include #include #include #include // pair namespace fair::mq { using Property = boost::any; using Properties = std::map; struct PropertyChange : Event {}; class PropertyHelper { public: template static void AddType(std::string label = "") { if (label.empty()) { label = boost::core::demangle(typeid(T).name()); } fTypeInfos[std::type_index(typeid(T))] = [label](const Property& p) { std::stringstream ss; ss << boost::any_cast(p); return std::pair{ss.str(), label}; }; fEventEmitters[std::type_index(typeid(T))] = [](const fair::mq::EventManager& em, const std::string& k, const Property& p) { em.Emit(k, boost::any_cast(p)); }; } static std::string ConvertPropertyToString(const Property& p) { return fTypeInfos.at(p.type())(p).first; } // returns static std::pair GetPropertyInfo(const Property& p) { try { return fTypeInfos.at(p.type())(p); } catch (std::out_of_range& oor) { return {"[unidentified_type]", "[unidentified_type]"}; } } static std::unordered_map fEventEmitters; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) private: static std::unordered_map(const Property&)>> fTypeInfos; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) }; } #endif /* FAIR_MQ_PROPERTIES_H */