@@ -241,36 +241,16 @@ domCreate(
241
241
*/
242
242
class DomParam : public dom ::Object
243
243
{
244
- Param const * I_;
245
- Corpus const & corpus_;
246
-
247
244
public:
248
245
DomParam (
249
246
Param const & I,
250
247
Corpus const & corpus) noexcept
251
- : I_(&I)
252
- , corpus_(corpus)
253
- {
254
- }
255
-
256
- dom::Value get (std::string_view key) const override
257
- {
258
- if (key == " name" )
259
- return dom::nonEmptyString (I_->Name );
260
- if (key == " type" )
261
- return dom::create<DomTypeInfo>(I_->Type , corpus_);
262
- if (key == " default" )
263
- return dom::nonEmptyString (I_->Default );
264
- return nullptr ;
265
- }
266
-
267
- std::vector<std::string_view> props () const override
248
+ : Object({
249
+ {" name" , dom::nonEmptyString (I.Name )},
250
+ {" type" , dom::create<DomTypeInfo>(I.Type , corpus)},
251
+ {" default" , dom::nonEmptyString (I.Default )}
252
+ })
268
253
{
269
- return {
270
- " name" ,
271
- " type" ,
272
- " default"
273
- };
274
254
}
275
255
};
276
256
@@ -312,61 +292,22 @@ class DomParamArray : public dom::Array
312
292
313
293
class DomTParam : public dom ::Object
314
294
{
315
- TParam const * I_;
316
- Corpus const & corpus_;
317
-
318
295
public:
319
- DomTParam (
296
+ DomTParam (
320
297
TParam const & I,
321
- Corpus const & corpus) noexcept
322
- : I_(&I)
323
- , corpus_(corpus)
324
- {
325
- }
326
-
327
- dom::Value get (std::string_view key) const override ;
328
-
329
- std::vector<std::string_view> props () const override
330
- {
331
- return {
332
- " kind" ,
333
- " name" ,
334
- " is-pack" ,
335
- " default" ,
336
- // only for NonTypeTParam
337
- " type" ,
338
- // only for TemplateTParam
339
- " params"
340
- };
341
- }
298
+ Corpus const & corpus) noexcept ;
342
299
};
343
300
344
301
class DomTArg : public dom ::Object
345
302
{
346
- TArg const * I_;
347
- Corpus const & corpus_;
348
-
349
303
public:
350
304
DomTArg (
351
305
TArg const & I,
352
306
Corpus const & corpus) noexcept
353
- : I_(&I)
354
- , corpus_(corpus)
355
- {
356
- }
357
-
358
- dom::Value get (std::string_view key) const override
359
- {
360
- if (key == " value" )
361
- return dom::nonEmptyString (I_->Value );
362
- return nullptr ;
363
- }
364
-
365
- std::vector<std::string_view> props () const override
307
+ : Object({
308
+ {" value" , dom::nonEmptyString (I.Value )}
309
+ })
366
310
{
367
- return {
368
- " value"
369
- };
370
311
}
371
312
};
372
313
@@ -430,137 +371,81 @@ class DomTArgArray : public dom::Array
430
371
}
431
372
};
432
373
433
- class MRDOX_DECL
434
- DomTemplate : public dom::Object
374
+ class DomTemplate : public dom ::Object
435
375
{
436
- TemplateInfo const * I_;
437
- Info const * Primary_;
438
- Corpus const & corpus_;
439
-
440
376
public:
441
377
DomTemplate (
442
378
TemplateInfo const & I,
443
379
Corpus const & corpus) noexcept
444
- : I_(&I)
445
- , corpus_(corpus)
446
- {
447
- if (I_->Primary )
448
- Primary_ = corpus_.find (*I_->Primary );
449
- else
450
- Primary_ = nullptr ;
451
- }
452
-
453
- dom::Value get (std::string_view key) const override
454
- {
455
- if (key == " kind" )
456
- {
457
- switch (I_->specializationKind ())
458
- {
459
- case TemplateSpecKind::Primary:
460
- return " primary" ;
461
- case TemplateSpecKind::Explicit:
462
- return " explicit" ;
463
- case TemplateSpecKind::Partial:
464
- return " partial" ;
465
- default :
466
- MRDOX_UNREACHABLE ();
467
- }
468
- }
469
- if (key == " primary" )
470
- {
471
- if (Primary_)
472
- return domCreateInfo (*Primary_, corpus_);
473
- return nullptr ;
474
- }
475
- if (key == " params" )
476
- return dom::create<DomTParamArray>(
477
- I_->Params , corpus_);
478
- if (key == " args" )
479
- return dom::create<DomTArgArray>(
480
- I_->Args , corpus_);
481
- return nullptr ;
482
- }
483
-
484
- std::vector<std::string_view> props () const override
380
+ : Object({
381
+ {" kind" , toString (I.specializationKind ())},
382
+ {" primary" , I.Primary ?
383
+ domCreateInfo (*I.Primary , corpus) :
384
+ nullptr },
385
+ {" params" , dom::create<DomTParamArray>(
386
+ I.Params , corpus)},
387
+ {" args" , dom::create<DomTArgArray>(
388
+ I.Args , corpus)}
389
+ })
485
390
{
486
- return {
487
- " params" ,
488
- " args" ,
489
- " kind" ,
490
- " primary"
491
- };
492
391
}
493
392
};
494
393
495
- // These are here for circular references
496
-
394
+ static
497
395
dom::Value
498
- DomTParam::
499
- get (std::string_view key) const
396
+ getTParamDefault (
397
+ TParam const & I,
398
+ Corpus const & corpus)
500
399
{
501
- if (key == " kind " )
400
+ switch (I. Kind )
502
401
{
503
- switch (I_->Kind )
504
- {
505
- case TParamKind::Type:
506
- return " type" ;
507
- case TParamKind::NonType:
508
- return " non-type" ;
509
- case TParamKind::Template:
510
- return " template" ;
511
- default :
512
- MRDOX_UNREACHABLE ();
513
- }
514
- }
515
- if (key == " name" )
516
- return dom::nonEmptyString (I_->Name );
517
- if (key == " is-pack" )
518
- return I_->IsParameterPack ;
519
- if (key == " type" )
402
+ case TParamKind::Type:
520
403
{
521
- if (I_->Kind != TParamKind::NonType)
404
+ const auto & P = I.get <TypeTParam>();
405
+ if (! P.Default )
522
406
return nullptr ;
523
407
return dom::create<DomTypeInfo>(
524
- I_-> get <NonTypeTParam>(). Type , corpus_ );
408
+ *P. Default , corpus );
525
409
}
526
- if (key == " params " )
410
+ case TParamKind::NonType:
527
411
{
528
- if (I_->Kind != TParamKind::Template)
412
+ const auto & P = I.get <NonTypeTParam>();
413
+ if (! P.Default )
529
414
return nullptr ;
530
- return dom::create<DomTParamArray>(
531
- I_->get <TemplateTParam>().Params , corpus_);
415
+ return *P.Default ;
532
416
}
533
- if (key == " default " )
417
+ case TParamKind::Template:
534
418
{
535
- switch (I_->Kind )
536
- {
537
- case TParamKind::Type:
538
- {
539
- const auto & P = I_->get <TypeTParam>();
540
- if (! P.Default )
541
- return nullptr ;
542
- return dom::create<DomTypeInfo>(
543
- *P.Default , corpus_);
544
- }
545
- case TParamKind::NonType:
546
- {
547
- const auto & P = I_->get <NonTypeTParam>();
548
- if (! P.Default )
549
- return nullptr ;
550
- return *P.Default ;
551
- }
552
- case TParamKind::Template:
553
- {
554
- const auto & P = I_->get <TemplateTParam>();
555
- if (! P.Default )
556
- return nullptr ;
557
- return *P.Default ;
558
- }
559
- default :
560
- MRDOX_UNREACHABLE ();
561
- }
419
+ const auto & P = I.get <TemplateTParam>();
420
+ if (! P.Default )
421
+ return nullptr ;
422
+ return *P.Default ;
562
423
}
563
- return nullptr ;
424
+ default :
425
+ MRDOX_UNREACHABLE ();
426
+ }
427
+ }
428
+
429
+ // this is here for circular references
430
+ DomTParam::
431
+ DomTParam (
432
+ TParam const & I,
433
+ Corpus const & corpus) noexcept
434
+ : Object({
435
+ {" kind" , toString (I.Kind )},
436
+ {" name" , dom::nonEmptyString (I.Name )},
437
+ {" is-pack" , I.IsParameterPack },
438
+ {" type" , I.Kind == TParamKind::NonType ?
439
+ dom::create<DomTypeInfo>(
440
+ I.get <NonTypeTParam>().Type , corpus) :
441
+ dom::Value ()},
442
+ {" params" , I.Kind == TParamKind::Template ?
443
+ dom::create<DomTParamArray>(
444
+ I.get <TemplateTParam>().Params , corpus) :
445
+ dom::Value ()},
446
+ {" default" , getTParamDefault (I, corpus)}
447
+ })
448
+ {
564
449
}
565
450
566
451
static
0 commit comments