formatter.hh

Go to the documentation of this file.
00001 /* vim: set sw=4 sts=4 et foldmethod=syntax : */
00002 
00003 /*
00004  * Copyright (c) 2007, 2008 Ciaran McCreesh
00005  *
00006  * This file is part of the Paludis package manager. Paludis is free software;
00007  * you can redistribute it and/or modify it under the terms of the GNU General
00008  * Public License version 2, as published by the Free Software Foundation.
00009  *
00010  * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
00011  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00012  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00013  * details.
00014  *
00015  * You should have received a copy of the GNU General Public License along with
00016  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00017  * Place, Suite 330, Boston, MA  02111-1307  USA
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 /** \file
00032  * Declarations for the Formatter class.
00033  *
00034  * \ingroup g_formatters
00035  *
00036  * \section Examples
00037  *
00038  * - \ref example_formatter.cc "example_formatter.cc"
00039  * - \ref example_stringify_formatter.cc "example_stringify_formatter.cc"
00040  */
00041 
00042 namespace paludis
00043 {
00044     /** \namespace paludis::format
00045      *
00046      * The paludis::format:: namespace contains various Formatter related
00047      * utilities.
00048      *
00049      * \ingroup g_formatters
00050      * \since 0.26
00051      */
00052     namespace format
00053     {
00054         /**
00055          * Tag to indicate that an item should be formatted as 'plain'.
00056          *
00057          * \ingroup g_formatters
00058          * \since 0.26
00059          * \nosubgrouping
00060          */
00061         struct Plain
00062         {
00063         };
00064 
00065         /**
00066          * Tag to indicate that an item should be formatted as 'enabled'.
00067          *
00068          * \ingroup g_formatters
00069          * \since 0.26
00070          * \nosubgrouping
00071          */
00072         struct Enabled
00073         {
00074         };
00075 
00076         /**
00077          * Tag to indicate that an item should be formatted as 'disabled'.
00078          *
00079          * \ingroup g_formatters
00080          * \since 0.26
00081          * \nosubgrouping
00082          */
00083         struct Disabled
00084         {
00085         };
00086 
00087         /**
00088          * Tag to indicate that an item should be formatted as 'masked'
00089          * (and disabled -- see format::Forced for masked and enabled).
00090          *
00091          * \ingroup g_formatters
00092          * \since 0.26
00093          * \nosubgrouping
00094          */
00095         struct Masked
00096         {
00097         };
00098 
00099         /**
00100          * Tag to indicate that an item should be formatted as 'forced'.
00101          *
00102          * \ingroup g_formatters
00103          * \since 0.26
00104          * \nosubgrouping
00105          */
00106         struct Forced
00107         {
00108         };
00109 
00110         /**
00111          * Tag to indicate that an item should be decorated as 'changed'.
00112          *
00113          * \ingroup g_formatters
00114          * \since 0.26
00115          * \nosubgrouping
00116          */
00117         struct Changed
00118         {
00119         };
00120 
00121         /**
00122          * Tag to indicate that an item should be decorated as 'added'.
00123          *
00124          * \ingroup g_formatters
00125          * \since 0.26
00126          * \nosubgrouping
00127          */
00128         struct Added
00129         {
00130         };
00131 
00132         /**
00133          * Tag to indicate that an item should be formatted as 'accepted'.
00134          *
00135          * \ingroup g_formatters
00136          * \since 0.26
00137          * \nosubgrouping
00138          */
00139         struct Accepted
00140         {
00141         };
00142 
00143         /**
00144          * Tag to indicate that an item should be formatted as 'unaccepted'.
00145          *
00146          * \ingroup g_formatters
00147          * \since 0.26
00148          * \nosubgrouping
00149          */
00150         struct Unaccepted
00151         {
00152         };
00153 
00154         /**
00155          * Tag to indicate that an item should be formatted as 'installed'.
00156          *
00157          * \ingroup g_formatters
00158          * \since 0.26
00159          * \nosubgrouping
00160          */
00161         struct Installed
00162         {
00163         };
00164 
00165         /**
00166          * Tag to indicate that an item should be formatted as 'installable'
00167          * (but not installed).
00168          *
00169          * \ingroup g_formatters
00170          * \since 0.26
00171          * \nosubgrouping
00172          */
00173         struct Installable
00174         {
00175         };
00176 
00177         /**
00178          * Used by CategorySelector<> to declare that format::Plain is the only
00179          * role supported by a particular class.
00180          *
00181          * \ingroup g_formatters
00182          * \since 0.26
00183          * \nosubgrouping
00184          */
00185         struct PlainRoles;
00186 
00187         /**
00188          * Used by CategorySelector<> to declare that format::Plain,
00189          * format::Enabled, format::Disabled, format::Forced, format::Masked,
00190          * format::Added and format::Changed are the roles supported by a
00191          * particular class.
00192          *
00193          * \ingroup g_formatters
00194          * \since 0.32
00195          * \nosubgrouping
00196          */
00197         struct ChoiceRoles;
00198 
00199         /**
00200          * Used by CategorySelector<> to declare that format::Plain,
00201          * format::Accepted and format::Unaccepted are the roles supported by a
00202          * particular class.
00203          *
00204          * \ingroup g_formatters
00205          * \since 0.26
00206          * \nosubgrouping
00207          */
00208         struct AcceptableRoles;
00209 
00210         /**
00211          * Used by CategorySelector<> to declare that format::Plain,
00212          * format::Installed and format::Installable are the roles supported by
00213          * a particular class.
00214          *
00215          * \ingroup g_formatters
00216          * \since 0.26
00217          * \nosubgrouping
00218          */
00219         struct PackageRoles;
00220 
00221         /**
00222          * Used by CategorySelector<> to declare that no roles at all are
00223          * supported by a particular class.
00224          *
00225          * This category is not used by any 'real' class. It is used for
00226          * NoType<> to work around the lack of variadic templates in the current
00227          * C++ standard.
00228          *
00229          * \ingroup g_formatters
00230          * \since 0.26
00231          * \nosubgrouping
00232          */
00233         struct NoRoles;
00234 
00235         /**
00236          * By default, a type supports format::PlainRoles.
00237          *
00238          * \ingroup g_formatters
00239          * \since 0.26
00240          * \nosubgrouping
00241          */
00242         template <typename T_>
00243         struct CategorySelector
00244         {
00245             /// The roles this type supports.
00246             typedef PlainRoles Category;
00247         };
00248 
00249         /**
00250          * ChoiceValue supports ChoiceRoles.
00251          *
00252          * \ingroup g_formatters
00253          * \since 0.32
00254          * \nosubgrouping
00255          */
00256         template <>
00257         struct CategorySelector<ChoiceValue>
00258         {
00259             /// The roles this type supports.
00260             typedef ChoiceRoles Category;
00261         };
00262 
00263         /**
00264          * ConditionalDepSpec supports ChoiceRoles.
00265          *
00266          * \ingroup g_formatters
00267          * \since 0.26
00268          * \nosubgrouping
00269          */
00270         template <>
00271         struct CategorySelector<ConditionalDepSpec>
00272         {
00273             /// The roles this type supports.
00274             typedef ChoiceRoles Category;
00275         };
00276 
00277         /**
00278          * LicenseDepSpec supports AcceptableRoles.
00279          *
00280          * \ingroup g_formatters
00281          * \since 0.26
00282          * \nosubgrouping
00283          */
00284         template <>
00285         struct CategorySelector<LicenseDepSpec>
00286         {
00287             /// The roles this type supports.
00288             typedef AcceptableRoles Category;
00289         };
00290 
00291         /**
00292          * KeywordName supports AcceptableRoles.
00293          *
00294          * \ingroup g_formatters
00295          * \since 0.26
00296          * \nosubgrouping
00297          */
00298         template <>
00299         struct CategorySelector<KeywordName>
00300         {
00301             /// The roles this type supports.
00302             typedef AcceptableRoles Category;
00303         };
00304 
00305         /**
00306          * PackageDepSpec supports PackageRoles.
00307          *
00308          * \ingroup g_formatters
00309          * \since 0.26
00310          * \nosubgrouping
00311          */
00312         template <>
00313         struct CategorySelector<PackageDepSpec>
00314         {
00315             /// The roles this type supports.
00316             typedef PackageRoles Category;
00317         };
00318 
00319         /**
00320          * PackageID supports PackageRoles.
00321          *
00322          * \ingroup g_formatters
00323          * \since 0.26
00324          * \nosubgrouping
00325          */
00326         template <>
00327         struct CategorySelector<PackageID>
00328         {
00329             /// The roles this type supports.
00330             typedef PackageRoles Category;
00331         };
00332 
00333         /**
00334          * A std::tr1::shared_ptr<T_> shouldn't be specified.
00335          *
00336          * \ingroup g_formatters
00337          * \since 0.26
00338          * \nosubgrouping
00339          */
00340         template <typename T_>
00341         struct CategorySelector<std::tr1::shared_ptr<T_> >
00342         {
00343             /// This role is wrong.
00344             typedef typename CategorySelector<T_>::ThisRoleIsWrong ThisRoleIsWrong;
00345         };
00346 
00347         /**
00348          * A std::tr1::shared_ptr<const T_> shouldn't be specified.
00349          *
00350          * \ingroup g_formatters
00351          * \since 0.26
00352          * \nosubgrouping
00353          */
00354         template <typename T_>
00355         struct CategorySelector<std::tr1::shared_ptr<const T_> >
00356         {
00357             /// This role is wrong.
00358             typedef typename CategorySelector<T_>::ThisRoleIsWrong ThisRoleIsWrong;
00359         };
00360 
00361         /**
00362          * A const T_ supports the same roles as T_.
00363          *
00364          * \ingroup g_formatters
00365          * \since 0.26
00366          * \nosubgrouping
00367          */
00368         template <typename T_>
00369         struct CategorySelector<const T_>
00370         {
00371             /// The roles this type supports.
00372             typedef typename CategorySelector<T_>::Category Category;
00373         };
00374 
00375         /**
00376          * NoType<> doesn't support any format roles.
00377          *
00378          * Used to work around the lack of variadic templates in the current C++
00379          * standard.
00380          *
00381          * \ingroup g_formatters
00382          * \since 0.26
00383          * \nosubgrouping
00384          */
00385         template <unsigned u_>
00386         struct CategorySelector<NoType<u_> >
00387         {
00388             /// The roles this type supports.
00389             typedef NoRoles Category;
00390         };
00391 
00392         ///\}
00393     }
00394 
00395     template <typename T_, typename C_>
00396     struct CanFormatBase;
00397 
00398     /**
00399      * Base class for anything that implements the format functions for
00400      * format::PlainRoles on type T_.
00401      *
00402      * \ingroup g_formatters
00403      * \since 0.26
00404      * \nosubgrouping
00405      */
00406     template <typename T_>
00407     class PALUDIS_VISIBLE CanFormatBase<T_, format::PlainRoles>
00408     {
00409         public:
00410             ///\name Basic operations
00411             ///\{
00412 
00413             CanFormatBase()
00414             {
00415             }
00416 
00417             virtual ~CanFormatBase()
00418             {
00419             }
00420 
00421             ///\}
00422 
00423             /**
00424              * Format this item as 'Plain'.
00425              */
00426             virtual std::string format(const T_ &, const format::Plain &) const
00427                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00428     };
00429 
00430     /**
00431      * Base class for anything that implements the format functions for
00432      * format::AcceptableRoles on type T_.
00433      *
00434      * \ingroup g_formatters
00435      * \since 0.26
00436      * \nosubgrouping
00437      */
00438     template <typename T_>
00439     class PALUDIS_VISIBLE CanFormatBase<T_, format::AcceptableRoles>
00440     {
00441         public:
00442             ///\name Basic operations
00443             ///\{
00444 
00445             CanFormatBase()
00446             {
00447             }
00448 
00449             virtual ~CanFormatBase()
00450             {
00451             }
00452 
00453             ///\}
00454 
00455             /**
00456              * Format this item as 'Plain'.
00457              */
00458             virtual std::string format(const T_ &, const format::Plain &) const
00459                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00460 
00461             /**
00462              * Format this item as 'Accepted'.
00463              */
00464             virtual std::string format(const T_ &, const format::Accepted &) const
00465                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00466 
00467             /**
00468              * Format this item as 'Unaccepted'.
00469              */
00470             virtual std::string format(const T_ &, const format::Unaccepted &) const
00471                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00472     };
00473 
00474     /**
00475      * Base class for anything that implements the format functions for
00476      * format::ChoiceRoles on type T_.
00477      *
00478      * \ingroup g_formatters
00479      * \since 0.26
00480      * \nosubgrouping
00481      */
00482     template <typename T_>
00483     class PALUDIS_VISIBLE CanFormatBase<T_, format::ChoiceRoles>
00484     {
00485         public:
00486             ///\name Basic operations
00487             ///\{
00488 
00489             CanFormatBase()
00490             {
00491             }
00492 
00493             virtual ~CanFormatBase()
00494             {
00495             }
00496 
00497             ///\}
00498 
00499             /**
00500              * Format this item as 'Plain'.
00501              */
00502             virtual std::string format(const T_ &, const format::Plain &) const
00503                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00504 
00505             /**
00506              * Format this item as 'Enabled'.
00507              */
00508             virtual std::string format(const T_ &, const format::Enabled &) const
00509                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00510 
00511             /**
00512              * Format this item as 'Disabled'.
00513              */
00514             virtual std::string format(const T_ &, const format::Disabled &) const
00515                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00516 
00517             /**
00518              * Format this item as 'Forced'.
00519              */
00520             virtual std::string format(const T_ &, const format::Forced &) const
00521                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00522 
00523             /**
00524              * Format this item as 'Masked'.
00525              */
00526             virtual std::string format(const T_ &, const format::Masked &) const
00527                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00528 
00529             /**
00530              * Decorate this item as 'Added'.
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              * Decorate this item as 'Changed'.
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      * Base class for anything that implements the format functions for
00544      * format::PackageRoles on type T_.
00545      *
00546      * \ingroup g_formatters
00547      * \since 0.26
00548      * \nosubgrouping
00549      */
00550     template <typename T_>
00551     class PALUDIS_VISIBLE CanFormatBase<T_, format::PackageRoles>
00552     {
00553         public:
00554             ///\name Basic operations
00555             ///\{
00556 
00557             CanFormatBase()
00558             {
00559             }
00560 
00561             virtual ~CanFormatBase()
00562             {
00563             }
00564 
00565             ///\}
00566 
00567             /**
00568              * Format this item as 'Plain'.
00569              */
00570             virtual std::string format(const T_ &, const format::Plain &) const
00571                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00572 
00573             /**
00574              * Format this item as 'Installed'.
00575              */
00576             virtual std::string format(const T_ &, const format::Installed &) const
00577                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00578 
00579             /**
00580              * Format this item as 'Installable'.
00581              */
00582             virtual std::string format(const T_ &, const format::Installable &) const
00583                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00584     };
00585 
00586     /**
00587      * Base class for anything that implements the format functions for
00588      * format::NoRoles on type NoType<T_>.
00589      *
00590      * Used to work around the lack of variadic templates in the current C++
00591      * standard.
00592      *
00593      * \ingroup g_formatters
00594      * \since 0.26
00595      * \nosubgrouping
00596      */
00597     template <unsigned u_>
00598     class PALUDIS_VISIBLE CanFormatBase<NoType<u_>, format::NoRoles>
00599     {
00600         public:
00601             ///\name Basic operations
00602             ///\{
00603 
00604             CanFormatBase()
00605             {
00606             }
00607 
00608             ///\}
00609     };
00610 
00611     /**
00612      * Descendents of this class implement the necessary methods to format an
00613      * item of type T_.
00614      *
00615      * \ingroup g_formatters
00616      * \since 0.26
00617      * \nosubgrouping
00618      */
00619     template <typename T_>
00620     class PALUDIS_VISIBLE CanFormat :
00621         public CanFormatBase<T_, typename format::CategorySelector<T_>::Category>
00622     {
00623         public:
00624             ///\name Basic operations
00625             ///\{
00626 
00627             CanFormat()
00628             {
00629             }
00630 
00631             ///\}
00632     };
00633 
00634     /**
00635      * Descendents of this class implement the necessary methods to format
00636      * whitespace.
00637      *
00638      * \ingroup g_formatters
00639      * \since 0.26
00640      * \nosubgrouping
00641      */
00642     class PALUDIS_VISIBLE CanSpace
00643     {
00644         public:
00645             ///\name Basic operations
00646             ///\{
00647 
00648             CanSpace()
00649             {
00650             }
00651 
00652             virtual ~CanSpace()
00653             {
00654             }
00655 
00656             ///\}
00657 
00658             /**
00659              * Output a newline.
00660              */
00661             virtual std::string newline() const = 0;
00662 
00663             /**
00664              * Output an indent marker of the specified indent level.
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      * Used by Formatter to implement the CanFormat<T_> interface.
00674      *
00675      * \ingroup g_formatters
00676      * \since 0.26
00677      * \nosubgrouping
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             ///\name Basic operations
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      * Used by Formatter to implement the CanFormat<T_> interface.
00705      *
00706      * \ingroup g_formatters
00707      * \since 0.26
00708      * \nosubgrouping
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             ///\name Basic operations
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      * Used by Formatter to implement the CanFormat<T_> interface.
00746      *
00747      * \ingroup g_formatters
00748      * \since 0.32
00749      * \nosubgrouping
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             ///\name Basic operations
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      * Used by Formatter to implement the CanFormat<T_> interface.
00807      *
00808      * \ingroup g_formatters
00809      * \since 0.26
00810      * \nosubgrouping
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             ///\name Basic operations
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      * Used by Formatter to implement the CanFormat<T_> interface.
00848      *
00849      * \ingroup g_formatters
00850      * \since 0.26
00851      * \nosubgrouping
00852      */
00853     template <unsigned u_>
00854     class PALUDIS_VISIBLE FormatFunctionsByProxy<NoType<u_>, format::NoRoles, u_>
00855     {
00856         public:
00857             ///\name Basic operations
00858             ///\{
00859 
00860             FormatFunctionsByProxy(const void * const)
00861             {
00862             }
00863 
00864             ///\}
00865 
00866             void format(const NoType<u_> &) const;
00867     };
00868 
00869     /**
00870      * A Formatter is a class that implements all the format routines for each
00871      * of its template parameters.
00872      *
00873      * A Formatter is required by most MetadataKey pretty_print methods. Instead
00874      * of requiring that formatters support every format method with every
00875      * possible role for every class, scary template voodoo is used to ensure that
00876      * only the format methods appropriate for the classes passed as template
00877      * parameters with roles appropriate for those classes are required.
00878      *
00879      * A Formatter can be implicitly constructed from any type that implements
00880      * CanFormat<> for every requested type, as well as the CanSpace interface.
00881      *
00882      * For a basic formatter that uses paludis::stringify() to do all
00883      * formatting, see StringifyFormatter.
00884      *
00885      * \ingroup g_formatters
00886      * \since 0.26
00887      * \nosubgrouping
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             ///\name Basic operations
00929             ///\{
00930 
00931             /**
00932              * A Formatter is implicitly constructible from any type that
00933              * supports all the relevant CanFormat<> interfaces, as well as the
00934              * CanSpace interface.
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

Generated on Mon Sep 21 10:36:08 2009 for paludis by  doxygen 1.5.4