00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef PALUDIS_GUARD_PALUDIS_FORMATTER_HH
00021 #define PALUDIS_GUARD_PALUDIS_FORMATTER_HH 1
00022
00023 #include <paludis/formatter-fwd.hh>
00024 #include <paludis/name-fwd.hh>
00025 #include <paludis/package_id-fwd.hh>
00026 #include <paludis/choice-fwd.hh>
00027 #include <paludis/dep_spec-fwd.hh>
00028 #include <paludis/util/attributes.hh>
00029 #include <string>
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 namespace paludis
00043 {
00044
00045
00046
00047
00048
00049
00050
00051
00052 namespace format
00053 {
00054
00055
00056
00057
00058
00059
00060
00061 struct Plain
00062 {
00063 };
00064
00065
00066
00067
00068
00069
00070
00071
00072 struct Enabled
00073 {
00074 };
00075
00076
00077
00078
00079
00080
00081
00082
00083 struct Disabled
00084 {
00085 };
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 struct Masked
00096 {
00097 };
00098
00099
00100
00101
00102
00103
00104
00105
00106 struct Forced
00107 {
00108 };
00109
00110
00111
00112
00113
00114
00115
00116
00117 struct Changed
00118 {
00119 };
00120
00121
00122
00123
00124
00125
00126
00127
00128 struct Added
00129 {
00130 };
00131
00132
00133
00134
00135
00136
00137
00138
00139 struct Accepted
00140 {
00141 };
00142
00143
00144
00145
00146
00147
00148
00149
00150 struct Unaccepted
00151 {
00152 };
00153
00154
00155
00156
00157
00158
00159
00160
00161 struct Installed
00162 {
00163 };
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173 struct Installable
00174 {
00175 };
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185 struct PlainRoles;
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197 struct ChoiceRoles;
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 struct AcceptableRoles;
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219 struct PackageRoles;
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233 struct NoRoles;
00234
00235
00236
00237
00238
00239
00240
00241
00242 template <typename T_>
00243 struct CategorySelector
00244 {
00245
00246 typedef PlainRoles Category;
00247 };
00248
00249
00250
00251
00252
00253
00254
00255
00256 template <>
00257 struct CategorySelector<ChoiceValue>
00258 {
00259
00260 typedef ChoiceRoles Category;
00261 };
00262
00263
00264
00265
00266
00267
00268
00269
00270 template <>
00271 struct CategorySelector<ConditionalDepSpec>
00272 {
00273
00274 typedef ChoiceRoles Category;
00275 };
00276
00277
00278
00279
00280
00281
00282
00283
00284 template <>
00285 struct CategorySelector<LicenseDepSpec>
00286 {
00287
00288 typedef AcceptableRoles Category;
00289 };
00290
00291
00292
00293
00294
00295
00296
00297
00298 template <>
00299 struct CategorySelector<KeywordName>
00300 {
00301
00302 typedef AcceptableRoles Category;
00303 };
00304
00305
00306
00307
00308
00309
00310
00311
00312 template <>
00313 struct CategorySelector<PackageDepSpec>
00314 {
00315
00316 typedef PackageRoles Category;
00317 };
00318
00319
00320
00321
00322
00323
00324
00325
00326 template <>
00327 struct CategorySelector<PackageID>
00328 {
00329
00330 typedef PackageRoles Category;
00331 };
00332
00333
00334
00335
00336
00337
00338
00339
00340 template <typename T_>
00341 struct CategorySelector<std::tr1::shared_ptr<T_> >
00342 {
00343
00344 typedef typename CategorySelector<T_>::ThisRoleIsWrong ThisRoleIsWrong;
00345 };
00346
00347
00348
00349
00350
00351
00352
00353
00354 template <typename T_>
00355 struct CategorySelector<std::tr1::shared_ptr<const T_> >
00356 {
00357
00358 typedef typename CategorySelector<T_>::ThisRoleIsWrong ThisRoleIsWrong;
00359 };
00360
00361
00362
00363
00364
00365
00366
00367
00368 template <typename T_>
00369 struct CategorySelector<const T_>
00370 {
00371
00372 typedef typename CategorySelector<T_>::Category Category;
00373 };
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385 template <unsigned u_>
00386 struct CategorySelector<NoType<u_> >
00387 {
00388
00389 typedef NoRoles Category;
00390 };
00391
00392
00393 }
00394
00395 template <typename T_, typename C_>
00396 struct CanFormatBase;
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406 template <typename T_>
00407 class PALUDIS_VISIBLE CanFormatBase<T_, format::PlainRoles>
00408 {
00409 public:
00410
00411
00412
00413 CanFormatBase()
00414 {
00415 }
00416
00417 virtual ~CanFormatBase()
00418 {
00419 }
00420
00421
00422
00423
00424
00425
00426 virtual std::string format(const T_ &, const format::Plain &) const
00427 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00428 };
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438 template <typename T_>
00439 class PALUDIS_VISIBLE CanFormatBase<T_, format::AcceptableRoles>
00440 {
00441 public:
00442
00443
00444
00445 CanFormatBase()
00446 {
00447 }
00448
00449 virtual ~CanFormatBase()
00450 {
00451 }
00452
00453
00454
00455
00456
00457
00458 virtual std::string format(const T_ &, const format::Plain &) const
00459 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00460
00461
00462
00463
00464 virtual std::string format(const T_ &, const format::Accepted &) const
00465 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00466
00467
00468
00469
00470 virtual std::string format(const T_ &, const format::Unaccepted &) const
00471 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00472 };
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482 template <typename T_>
00483 class PALUDIS_VISIBLE CanFormatBase<T_, format::ChoiceRoles>
00484 {
00485 public:
00486
00487
00488
00489 CanFormatBase()
00490 {
00491 }
00492
00493 virtual ~CanFormatBase()
00494 {
00495 }
00496
00497
00498
00499
00500
00501
00502 virtual std::string format(const T_ &, const format::Plain &) const
00503 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00504
00505
00506
00507
00508 virtual std::string format(const T_ &, const format::Enabled &) const
00509 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00510
00511
00512
00513
00514 virtual std::string format(const T_ &, const format::Disabled &) const
00515 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00516
00517
00518
00519
00520 virtual std::string format(const T_ &, const format::Forced &) const
00521 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00522
00523
00524
00525
00526 virtual std::string format(const T_ &, const format::Masked &) const
00527 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00528
00529
00530
00531
00532 virtual std::string decorate(const T_ &, const std::string &, const format::Added &) const
00533 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00534
00535
00536
00537
00538 virtual std::string decorate(const T_ &, const std::string &, const format::Changed &) const
00539 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00540 };
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550 template <typename T_>
00551 class PALUDIS_VISIBLE CanFormatBase<T_, format::PackageRoles>
00552 {
00553 public:
00554
00555
00556
00557 CanFormatBase()
00558 {
00559 }
00560
00561 virtual ~CanFormatBase()
00562 {
00563 }
00564
00565
00566
00567
00568
00569
00570 virtual std::string format(const T_ &, const format::Plain &) const
00571 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00572
00573
00574
00575
00576 virtual std::string format(const T_ &, const format::Installed &) const
00577 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00578
00579
00580
00581
00582 virtual std::string format(const T_ &, const format::Installable &) const
00583 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00584 };
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597 template <unsigned u_>
00598 class PALUDIS_VISIBLE CanFormatBase<NoType<u_>, format::NoRoles>
00599 {
00600 public:
00601
00602
00603
00604 CanFormatBase()
00605 {
00606 }
00607
00608
00609 };
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619 template <typename T_>
00620 class PALUDIS_VISIBLE CanFormat :
00621 public CanFormatBase<T_, typename format::CategorySelector<T_>::Category>
00622 {
00623 public:
00624
00625
00626
00627 CanFormat()
00628 {
00629 }
00630
00631
00632 };
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642 class PALUDIS_VISIBLE CanSpace
00643 {
00644 public:
00645
00646
00647
00648 CanSpace()
00649 {
00650 }
00651
00652 virtual ~CanSpace()
00653 {
00654 }
00655
00656
00657
00658
00659
00660
00661 virtual std::string newline() const = 0;
00662
00663
00664
00665
00666 virtual std::string indent(const int) const = 0;
00667 };
00668
00669 template <typename T_, typename C_, unsigned u_>
00670 class FormatFunctionsByProxy;
00671
00672
00673
00674
00675
00676
00677
00678
00679 template <typename T_, unsigned u_>
00680 class PALUDIS_VISIBLE FormatFunctionsByProxy<T_, format::PlainRoles, u_> :
00681 public CanFormat<T_>
00682 {
00683 private:
00684 const CanFormat<T_> * const _proxy;
00685
00686 public:
00687
00688
00689
00690 FormatFunctionsByProxy(const CanFormat<T_> * const p) :
00691 _proxy(p)
00692 {
00693 }
00694
00695
00696
00697 virtual std::string format(const T_ & s, const format::Plain & p) const
00698 {
00699 return _proxy->format(s, p);
00700 }
00701 };
00702
00703
00704
00705
00706
00707
00708
00709
00710 template <typename T_, unsigned u_>
00711 class PALUDIS_VISIBLE FormatFunctionsByProxy<T_, format::AcceptableRoles, u_> :
00712 public CanFormat<T_>
00713 {
00714 private:
00715 const CanFormat<T_> * const _proxy;
00716
00717 public:
00718
00719
00720
00721 FormatFunctionsByProxy(const CanFormat<T_> * const p) :
00722 _proxy(p)
00723 {
00724 }
00725
00726
00727
00728 virtual std::string format(const T_ & s, const format::Plain & p) const
00729 {
00730 return _proxy->format(s, p);
00731 }
00732
00733 virtual std::string format(const T_ & s, const format::Accepted & p) const
00734 {
00735 return _proxy->format(s, p);
00736 }
00737
00738 virtual std::string format(const T_ & s, const format::Unaccepted & p) const
00739 {
00740 return _proxy->format(s, p);
00741 }
00742 };
00743
00744
00745
00746
00747
00748
00749
00750
00751 template <typename T_, unsigned u_>
00752 class PALUDIS_VISIBLE FormatFunctionsByProxy<T_, format::ChoiceRoles, u_> :
00753 public CanFormat<T_>
00754 {
00755 private:
00756 const CanFormat<T_> * const _proxy;
00757
00758 public:
00759
00760
00761
00762 FormatFunctionsByProxy(const CanFormat<T_> * const p) :
00763 _proxy(p)
00764 {
00765 }
00766
00767
00768
00769 virtual std::string format(const T_ & s, const format::Plain & p) const
00770 {
00771 return _proxy->format(s, p);
00772 }
00773
00774 virtual std::string format(const T_ & s, const format::Enabled & p) const
00775 {
00776 return _proxy->format(s, p);
00777 }
00778
00779 virtual std::string format(const T_ & s, const format::Disabled & p) const
00780 {
00781 return _proxy->format(s, p);
00782 }
00783
00784 virtual std::string format(const T_ & s, const format::Forced & p) const
00785 {
00786 return _proxy->format(s, p);
00787 }
00788
00789 virtual std::string format(const T_ & s, const format::Masked & p) const
00790 {
00791 return _proxy->format(s, p);
00792 }
00793
00794 virtual std::string decorate(const T_ & t, const std::string & s, const format::Changed & p) const
00795 {
00796 return _proxy->decorate(t, s, p);
00797 }
00798
00799 virtual std::string decorate(const T_ & t, const std::string & s, const format::Added & p) const
00800 {
00801 return _proxy->decorate(t, s, p);
00802 }
00803 };
00804
00805
00806
00807
00808
00809
00810
00811
00812 template <typename T_, unsigned u_>
00813 class PALUDIS_VISIBLE FormatFunctionsByProxy<T_, format::PackageRoles, u_> :
00814 public CanFormat<T_>
00815 {
00816 private:
00817 const CanFormat<T_> * const _proxy;
00818
00819 public:
00820
00821
00822
00823 FormatFunctionsByProxy(const CanFormat<T_> * const p) :
00824 _proxy(p)
00825 {
00826 }
00827
00828
00829
00830 virtual std::string format(const T_ & s, const format::Plain & p) const
00831 {
00832 return _proxy->format(s, p);
00833 }
00834
00835 virtual std::string format(const T_ & s, const format::Installed & p) const
00836 {
00837 return _proxy->format(s, p);
00838 }
00839
00840 virtual std::string format(const T_ & s, const format::Installable & p) const
00841 {
00842 return _proxy->format(s, p);
00843 }
00844 };
00845
00846
00847
00848
00849
00850
00851
00852
00853 template <unsigned u_>
00854 class PALUDIS_VISIBLE FormatFunctionsByProxy<NoType<u_>, format::NoRoles, u_>
00855 {
00856 public:
00857
00858
00859
00860 FormatFunctionsByProxy(const void * const)
00861 {
00862 }
00863
00864
00865
00866 void format(const NoType<u_> &) const;
00867 };
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889 template <
00890 typename T1_,
00891 typename T2_,
00892 typename T3_,
00893 typename T4_,
00894 typename T5_,
00895 typename T6_,
00896 typename T7_,
00897 typename T8_,
00898 typename T9_,
00899 typename T10_,
00900 typename T11_,
00901 typename T12_,
00902 typename T13_,
00903 typename T14_,
00904 typename T15_
00905 >
00906 class PALUDIS_VISIBLE Formatter :
00907 public FormatFunctionsByProxy<T1_, typename format::CategorySelector<T1_>::Category, 1>,
00908 public FormatFunctionsByProxy<T2_, typename format::CategorySelector<T2_>::Category, 2>,
00909 public FormatFunctionsByProxy<T3_, typename format::CategorySelector<T3_>::Category, 3>,
00910 public FormatFunctionsByProxy<T4_, typename format::CategorySelector<T4_>::Category, 4>,
00911 public FormatFunctionsByProxy<T5_, typename format::CategorySelector<T5_>::Category, 5>,
00912 public FormatFunctionsByProxy<T6_, typename format::CategorySelector<T6_>::Category, 6>,
00913 public FormatFunctionsByProxy<T7_, typename format::CategorySelector<T7_>::Category, 7>,
00914 public FormatFunctionsByProxy<T8_, typename format::CategorySelector<T8_>::Category, 8>,
00915 public FormatFunctionsByProxy<T9_, typename format::CategorySelector<T9_>::Category, 9>,
00916 public FormatFunctionsByProxy<T10_, typename format::CategorySelector<T10_>::Category, 10>,
00917 public FormatFunctionsByProxy<T11_, typename format::CategorySelector<T11_>::Category, 11>,
00918 public FormatFunctionsByProxy<T12_, typename format::CategorySelector<T12_>::Category, 12>,
00919 public FormatFunctionsByProxy<T13_, typename format::CategorySelector<T13_>::Category, 13>,
00920 public FormatFunctionsByProxy<T14_, typename format::CategorySelector<T14_>::Category, 14>,
00921 public FormatFunctionsByProxy<T15_, typename format::CategorySelector<T15_>::Category, 15>,
00922 public CanSpace
00923 {
00924 private:
00925 const CanSpace * const _proxy;
00926
00927 public:
00928
00929
00930
00931
00932
00933
00934
00935
00936 template <typename T_>
00937 Formatter(const T_ & t) :
00938 FormatFunctionsByProxy<T1_, typename format::CategorySelector<T1_>::Category, 1>(&t),
00939 FormatFunctionsByProxy<T2_, typename format::CategorySelector<T2_>::Category, 2>(&t),
00940 FormatFunctionsByProxy<T3_, typename format::CategorySelector<T3_>::Category, 3>(&t),
00941 FormatFunctionsByProxy<T4_, typename format::CategorySelector<T4_>::Category, 4>(&t),
00942 FormatFunctionsByProxy<T5_, typename format::CategorySelector<T5_>::Category, 5>(&t),
00943 FormatFunctionsByProxy<T6_, typename format::CategorySelector<T6_>::Category, 6>(&t),
00944 FormatFunctionsByProxy<T7_, typename format::CategorySelector<T7_>::Category, 7>(&t),
00945 FormatFunctionsByProxy<T8_, typename format::CategorySelector<T8_>::Category, 8>(&t),
00946 FormatFunctionsByProxy<T9_, typename format::CategorySelector<T9_>::Category, 9>(&t),
00947 FormatFunctionsByProxy<T10_, typename format::CategorySelector<T10_>::Category, 10>(&t),
00948 FormatFunctionsByProxy<T11_, typename format::CategorySelector<T11_>::Category, 11>(&t),
00949 FormatFunctionsByProxy<T12_, typename format::CategorySelector<T12_>::Category, 12>(&t),
00950 FormatFunctionsByProxy<T13_, typename format::CategorySelector<T13_>::Category, 13>(&t),
00951 FormatFunctionsByProxy<T14_, typename format::CategorySelector<T14_>::Category, 14>(&t),
00952 FormatFunctionsByProxy<T15_, typename format::CategorySelector<T15_>::Category, 15>(&t),
00953 CanSpace(),
00954 _proxy(&t)
00955 {
00956 }
00957
00958 Formatter(const Formatter & other) :
00959 FormatFunctionsByProxy<T1_, typename format::CategorySelector<T1_>::Category, 1>(other),
00960 FormatFunctionsByProxy<T2_, typename format::CategorySelector<T2_>::Category, 2>(other),
00961 FormatFunctionsByProxy<T3_, typename format::CategorySelector<T3_>::Category, 3>(other),
00962 FormatFunctionsByProxy<T4_, typename format::CategorySelector<T4_>::Category, 4>(other),
00963 FormatFunctionsByProxy<T5_, typename format::CategorySelector<T5_>::Category, 5>(other),
00964 FormatFunctionsByProxy<T6_, typename format::CategorySelector<T6_>::Category, 6>(other),
00965 FormatFunctionsByProxy<T7_, typename format::CategorySelector<T7_>::Category, 7>(other),
00966 FormatFunctionsByProxy<T8_, typename format::CategorySelector<T8_>::Category, 8>(other),
00967 FormatFunctionsByProxy<T9_, typename format::CategorySelector<T9_>::Category, 9>(other),
00968 FormatFunctionsByProxy<T10_, typename format::CategorySelector<T10_>::Category, 10>(other),
00969 FormatFunctionsByProxy<T11_, typename format::CategorySelector<T11_>::Category, 11>(other),
00970 FormatFunctionsByProxy<T12_, typename format::CategorySelector<T12_>::Category, 12>(other),
00971 FormatFunctionsByProxy<T13_, typename format::CategorySelector<T13_>::Category, 13>(other),
00972 FormatFunctionsByProxy<T14_, typename format::CategorySelector<T14_>::Category, 14>(other),
00973 FormatFunctionsByProxy<T15_, typename format::CategorySelector<T15_>::Category, 15>(other),
00974 CanSpace(other),
00975 _proxy(other._proxy)
00976 {
00977 }
00978
00979
00980
00981 using FormatFunctionsByProxy<T1_, typename format::CategorySelector<T1_>::Category, 1>::format;
00982 using FormatFunctionsByProxy<T2_, typename format::CategorySelector<T2_>::Category, 2>::format;
00983 using FormatFunctionsByProxy<T3_, typename format::CategorySelector<T3_>::Category, 3>::format;
00984 using FormatFunctionsByProxy<T4_, typename format::CategorySelector<T4_>::Category, 4>::format;
00985 using FormatFunctionsByProxy<T5_, typename format::CategorySelector<T5_>::Category, 5>::format;
00986 using FormatFunctionsByProxy<T6_, typename format::CategorySelector<T6_>::Category, 6>::format;
00987 using FormatFunctionsByProxy<T7_, typename format::CategorySelector<T7_>::Category, 7>::format;
00988 using FormatFunctionsByProxy<T8_, typename format::CategorySelector<T8_>::Category, 8>::format;
00989 using FormatFunctionsByProxy<T9_, typename format::CategorySelector<T9_>::Category, 9>::format;
00990 using FormatFunctionsByProxy<T10_, typename format::CategorySelector<T10_>::Category, 10>::format;
00991 using FormatFunctionsByProxy<T11_, typename format::CategorySelector<T11_>::Category, 11>::format;
00992 using FormatFunctionsByProxy<T12_, typename format::CategorySelector<T12_>::Category, 12>::format;
00993 using FormatFunctionsByProxy<T13_, typename format::CategorySelector<T13_>::Category, 13>::format;
00994 using FormatFunctionsByProxy<T14_, typename format::CategorySelector<T14_>::Category, 14>::format;
00995 using FormatFunctionsByProxy<T15_, typename format::CategorySelector<T15_>::Category, 15>::format;
00996
00997 virtual std::string newline() const
00998 {
00999 return _proxy->newline();
01000 }
01001
01002 virtual std::string indent(const int i) const
01003 {
01004 return _proxy->indent(i);
01005 }
01006 };
01007 }
01008
01009 #endif