MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / json_message

Function json_message

src/ifcparse/IfcLogger.cpp:93–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91
92template <typename T>
93void json_message(T& out, const IfcUtil::IfcBaseClass* current_product, Logger::Severity type, const std::string& message, const IfcUtil::IfcBaseInterface* instance) {
94 boost::property_tree::basic_ptree<std::basic_string<typename T::char_type>, std::basic_string<typename T::char_type>> property_tree;
95
96 // @todo this is crazy
97 static const typename T::char_type time_string[] = {'t', 'i', 'm', 'e', 0};
98 static const typename T::char_type level_string[] = {'l', 'e', 'v', 'e', 'l', 0};
99 static const typename T::char_type product_string[] = {'p', 'r', 'o', 'd', 'u', 'c', 't', 0};
100 static const typename T::char_type message_string[] = {'m', 'e', 's', 's', 'a', 'g', 'e', 0};
101 static const typename T::char_type instance_string[] = {'i', 'n', 's', 't', 'a', 'n', 'c', 'e', 0};
102
103 property_tree.put(level_string, severity_strings<typename T::char_type>::value[type]);
104 if (current_product) {
105 std::ostringstream oss;
106 current_product->toString(oss);
107 property_tree.put(product_string, string_as<typename T::char_type>(oss.str()));
108 }
109 property_tree.put(message_string, string_as<typename T::char_type>(message));
110 if (instance) {
111 std::ostringstream oss;
112 instance->as<IfcUtil::IfcBaseClass>()->toString(oss);
113 property_tree.put(instance_string, string_as<typename T::char_type>(oss.str()));
114 }
115
116 property_tree.put(time_string, string_as<typename T::char_type>(get_time()));
117
118 boost::property_tree::write_json(out, property_tree, false);
119
120 // Append a newline after the JSON object if the Boost version is 1.86 or higher
121#if BOOST_VERSION >= 108600
122 out << '\n';
123#endif
124
125}
126} // namespace
127
128void Logger::SetProduct(boost::optional<const IfcUtil::IfcBaseClass*> product) {

Callers 1

MessageMethod · 0.85

Calls 4

get_timeFunction · 0.85
putMethod · 0.80
toStringMethod · 0.80
strMethod · 0.45

Tested by

no test coverage detected