1 #ifndef PAGMO_DETAIL_SUPPORT_XEUS_CLING_HPP 2 #define PAGMO_DETAIL_SUPPORT_XEUS_CLING_HPP 3 4 #if defined(__CLING__) 5 6 #if __has_include(<nlohmann/json.hpp>) 7 8 #include <nlohmann/json.hpp> 9 #include <sstream> 10 11 namespace pagmo 12 { 13 14 namespace detail 15 { 16 17 template <typename T> cling_repr(const T & x)18inline nlohmann::json cling_repr(const T &x) 19 { 20 auto bundle = nlohmann::json::object(); 21 22 std::ostringstream oss; 23 oss << x; 24 bundle["text/plain"] = oss.str(); 25 26 return bundle; 27 } 28 29 } // namespace detail 30 31 } // namespace pagmo 32 33 #define PAGMO_IMPLEMENT_XEUS_CLING_REPR(name) \ 34 namespace pagmo \ 35 { \ 36 inline nlohmann::json mime_bundle_repr(const name &x) \ 37 { \ 38 return detail::cling_repr(x); \ 39 } \ 40 } 41 42 #else 43 44 // nlohmann::json not available. 45 #define PAGMO_IMPLEMENT_XEUS_CLING_REPR(name) 46 47 #endif 48 49 #else 50 51 // We are not using cling. 52 #define PAGMO_IMPLEMENT_XEUS_CLING_REPR(name) 53 54 #endif 55 56 #endif 57