28 if (
const auto &maybe_module = e.
module(); maybe_module) {
29 j[
"module"][
"name"] = *maybe_module;
39 j[
"access"] = to_string(c.
access());
40 if (!c.
file().empty())
41 j[
"source_location"] =
43 if (
const auto &comment = c.
comment(); comment)
44 j[
"comment"] = comment.value();
88 j[
"id"] = std::to_string(c.
id().
value());
90 j[
"access"] = to_string(c.
access());
141 if (
config().using_namespace)
142 parent[
"using_namespace"] =
config().using_namespace().to_string();
144 if (
config().using_module)
145 parent[
"using_module"] =
config().using_module();
147 if (
config().generate_packages.has_value)
148 parent[
"package_type"] = to_string(
config().package_type());
149 parent[
"elements"] = std::vector<nlohmann::json>{};
150 parent[
"relationships"] = std::vector<nlohmann::json>{};
159 for (
const auto &p :
model()) {
160 if (
auto *pkg =
dynamic_cast<package *
>(p.get()); pkg) {
161 if (!pkg->is_empty())
164 else if (
auto *cls =
dynamic_cast<class_ *
>(p.get()); cls) {
167 else if (
auto *enm =
dynamic_cast<enum_ *
>(p.get()); enm) {
170 else if (
auto *cpt =
dynamic_cast<concept_ *
>(p.get()); cpt) {
178 const auto &uns =
config().using_namespace();
180 nlohmann::json package_object;
182 if (
config().generate_packages()) {
185 if (!uns.starts_with({p.full_name(false)})) {
188 package_object[
"type"] = to_string(
config().package_type());
189 package_object[
"name"] = p.
name();
190 package_object[
"display_name"] = p.
name();
194 for (
const auto &subpackage : p) {
195 if (
dynamic_cast<package *
>(subpackage.get()) !=
nullptr) {
196 const auto &sp =
dynamic_cast<package &
>(*subpackage);
197 if (!sp.is_empty()) {
198 if (
config().generate_packages())
204 else if (
auto *cls =
dynamic_cast<class_ *
>(subpackage.get()); cls) {
205 if (
config().generate_packages())
210 else if (
auto *enm =
dynamic_cast<enum_ *
>(subpackage.get()); enm) {
211 if (
config().generate_packages())
216 else if (
auto *cpt =
dynamic_cast<concept_ *
>(subpackage.get()); cpt) {
217 if (
config().generate_packages())
224 if (
config().generate_packages() && !package_object.empty()) {
225 parent[
"elements"].push_back(std::move(package_object));
231 nlohmann::json
object = c;
234 if (!
config().generate_fully_qualified_name())
235 object[
"display_name"] =
238 object[
"display_name"] =
239 config().simplify_template_type(
object[
"display_name"]);
241 for (
auto &tp :
object[
"template_parameters"]) {
242 if (tp.contains(
"type") && tp.at(
"type").is_string()) {
243 tp[
"type"] =
config().using_namespace().relative(tp.at(
"type"));
246 for (
auto &tp :
object[
"members"]) {
247 if (tp.contains(
"type") && tp.at(
"type").is_string()) {
248 tp[
"type"] =
config().using_namespace().relative(tp.at(
"type"));
252 std::string object_str =
object.dump(2);
254 parent[
"elements"].push_back(std::move(
object));
259 nlohmann::json
object = e;
261 if (!
config().generate_fully_qualified_name())
262 object[
"display_name"] =
265 parent[
"elements"].push_back(std::move(
object));
270 nlohmann::json
object = c;
272 if (!
config().generate_fully_qualified_name())
273 object[
"display_name"] =
276 parent[
"elements"].push_back(std::move(
object));
281 for (
const auto &p :
model()) {
282 if (
auto *pkg =
dynamic_cast<package *
>(p.get()); pkg) {
285 else if (
auto *cls =
dynamic_cast<class_ *
>(p.get()); cls) {
288 else if (
auto *enm =
dynamic_cast<enum_ *
>(p.get()); enm) {
291 else if (
auto *cpt =
dynamic_cast<concept_ *
>(p.get()); cpt) {
298 const class_ &c, nlohmann::json &parent)
const
301 auto target_element =
model().get(r.destination());
302 if (!target_element.has_value()) {
303 LOG_DBG(
"Skipping {} relation from {} to {} due "
304 "to unresolved destination id",
305 to_string(r.type()), c.
full_name(), r.destination());
309 nlohmann::json rel = r;
310 rel[
"source"] = std::to_string(c.
id().
value());
311 parent[
"relationships"].push_back(rel);
314 if (
model().should_include(relationship_t::kExtension)) {
315 for (
const auto &b : c.
parents()) {
317 relationship_t::kExtension, b.id(), b.access());
318 nlohmann::json rel = r;
319 rel[
"source"] = std::to_string(c.
id().
value());
320 parent[
"relationships"].push_back(rel);
326 const enum_ &c, nlohmann::json &parent)
const
329 auto target_element =
model().get(r.destination());
330 if (!target_element.has_value()) {
331 LOG_DBG(
"Skipping {} relation from {} to {} due "
332 "to unresolved destination id",
333 to_string(r.type()), c.
full_name(), r.destination());
337 nlohmann::json rel = r;
338 rel[
"source"] = std::to_string(c.
id().
value());
339 parent[
"relationships"].push_back(rel);
344 const concept_ &c, nlohmann::json &parent)
const
347 auto target_element =
model().get(r.destination());
348 if (!target_element.has_value()) {
349 LOG_DBG(
"Skipping {} relation from {} to {} due "
350 "to unresolved destination id",
351 to_string(r.type()), c.
full_name(), r.destination());
355 nlohmann::json rel = r;
356 rel[
"source"] = std::to_string(c.
id().
value());
357 parent[
"relationships"].push_back(rel);
362 const package &p, nlohmann::json &parent)
const
364 for (
const auto &subpackage : p) {
365 if (
dynamic_cast<package *
>(subpackage.get()) !=
nullptr) {
366 const auto &sp =
dynamic_cast<package &
>(*subpackage);
370 else if (
dynamic_cast<class_ *
>(subpackage.get()) !=
nullptr) {
371 if (
model().should_include(*subpackage)) {
373 dynamic_cast<class_ &
>(*subpackage), parent);
376 else if (
dynamic_cast<enum_ *
>(subpackage.get()) !=
nullptr) {
377 if (
model().should_include(*subpackage)) {
379 dynamic_cast<enum_ &
>(*subpackage), parent);
382 else if (
dynamic_cast<concept_ *
>(subpackage.get()) !=
nullptr) {
383 if (
model().should_include(*subpackage)) {
385 dynamic_cast<concept_ &
>(*subpackage), parent);