Boost logo

Boost :

From: Reece Dunn (msclrhd_at_[hidden])
Date: 2004-09-12 15:44:11


Pavel Vozenilek wrote:
>"John Torjo" wrote:
>
> > The FORMAL Review of "Output Formatter" library begins today,
> >
>I briefly looked on the library and wrote down few
>notes. I am especially interested in point [4].
>
>1. Name of the library would be better changed.
> Hearing it for the first time I suspected
> something like variant on std::endl.

I agree, especially as it also works for input as well.

>2. The first part of documentation should
> be what is purpose of the library.

okay.

> I guess in this case it is debugging
> and testing support, 100% cases.

It can also be used for additional stuff (see Techniques section for
examples). As a demonstration, if you implement localization within your
program by providing a

   std::map< std::string, std::string > locale;

where you do something like:

   std::cout << locale[ "usage" ];

you can use my library to read it in. I understand you can use the
serialization library to do this, but you can control the formatting in my
library, allowing:
   english.loc
      "welcome" = "My World"
      ""
   spanish.loc
      "wecome" = "Mi Tierra"
      ""
   german.loc
      "wecome" = "Meine Welt"
      ""

I am not sure how feasible it is to do something like this in the
serialization library.

>4. There seems to be significant overlap
> with Boost.Serialization (I suspect
> outfm doesn't handle cyclic
> structures).

outfmt does not support cyclic structures.

> It may or may not be possible
> to implement outfm functionality
> with special archive.
>
> Was this considered?

Is it possible to control the formatting for the same type to produce
different results? For example:

   std::pair< std::pair< int, char >, std::pair< int, char > > p;

   std::cout << io::formatob( p,
         io::pairfmt
         (
            io::pairfmt().format( " | " ),
            io::pairfmt().format( "{ ", " }", " : " )
         )
      ).format( "<: ", " :>" );
   // output: <: ( 5 | a ), { 5 : a } :>

>5. To support debugging I would like to see
> many more features:

It is possible to create your own format object and delimeter formatter
classes to extend the libraries functionality, so some of what you suggest
can be done that way. I am thinking of extending the library to support
function objects as delimeter types, thus expanding the possible uses of the
library.

I am also planning on supporting character escaping to better support string
in/output as well as allowing HTML/XML character escapers.

You can produce simple HTML/XML output using format(), for example:

   std::cout << io::formatob( vec,
         io::containerfmt
         (
            io::wrappedfmt().format( "<li>", "</li>" )
         ).format( "<ol>", "</ol>" )
      ); // output: <ol><li>a</li><li>b</li><li>c</li></ol>

Regards,
Reece

_________________________________________________________________
Express yourself with cool new emoticons http://www.msn.co.uk/specials/myemo


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk