Boost logo

Boost :

From: Reece Dunn (msclrhd_at_[hidden])
Date: 2004-09-17 07:44:23


Throughout this e-mail, I assume the following aliases:

   namespace io = boost::io;
   namespace fmt = boost::io::format;
   namespace css = boost::io::css;

NOTE: This is a design outline for features in a future version of the
library.

David Abrahams has suggested the ability to specify default formatting on a
stream. I have implemented a simple version of this so that you can do:

   io::sequence_decorators< char > seq( "; " );
   std::cout << '"' << seq.open( std::cout ) << "\"\n" // "[ "
             << '"' << seq.close( std::cout ) << "\"\n" // " ]"
             << '"' << seq.separator( std::cout ) << "\"\n"; // "; "

where separator( std::cout ) uses the separator value specified by seq and
the others use the values set on the std::cout stream. To change these
defaults, you can use:

   std::cout << io::cdecorate( "[{ ", " }]" ); // [{ a, b, c }]

The problem with this is that it changes the defaults for all the formatting
used, thus you cannot have different defaults for sequences and n-ary types.

Cascading Style Sheets (CSS) are a web standard
[http://www.w3.org/Style/CSS/] used for controlling how HTML tags are
displayed to different devices (screen, printer and speech).

== Inlined Styles

In HTML you can specify "inlined" styles using a style attribute, e.g.:
   <div style = "color: red;">Red Text</div>

My library equivalent is to use the decorate() function, e.g.:
   fmt::range().decorate( "<-- ", " -->" );

== Dynamic Styles

You can also set CSS properties within script code, e.g.
   tag.style.fontFamily = "Times New Roman";

This style behaviour is available in the new decorators, for example:
   io::wrapper_decorators< char > wrap;
   wrap.open = "<< ";
   wrap.close = " >>";

A more complex example that uses nested format objects:
   fmt::container_t< char, fmt::pair_t< char > > my_fo
      = fmt::container( fmt::pair());
   my_fo.elem.open = "<< ";
   my_ob.elem.close = " >>";
   my_ob.separator = " | ";

   std::cout << io::object( ob, my_ob ); // output: [ << a, 5 >> | << b, -1
>> ]

== Cascading Style Sheets

HTML provides a <style> tag to specify styling across the document without
linking to an external file, e.g.:
   <style>h1{ color: orange; font-size: 2pc; }</style>

The equivalent within my library would be to define the styling on a stream,
e.g.:

   std::cout
      << css::element( "pair" )
         [
            ( css::attribute( "open" ) = "<< " )
         + ( css::attribute( "close" ) = " >>" )
         ]
      << css::element( "container" )
         [
            css::attribute( "separator" ) = " | "
         ]
      << io::object( ob ) // output: [ << a, 5 >> | << b, -1 >> ]
      << css::element( "pair" )
         [
            css::attribute( "separator" ) = " = "
         ]
      << io::object( ob ); // output: [ << a = 5 >> | << b = -1 >> ]

HTML can import styling from an external CSS file. The equivalent would be
to use an object to hold the styling, e.g.:

   css::stylesheet< char > style
      = css::element( "pair" )
        [
           css::attribute( "separator" ) = " = "
        ]
      + css::element( "container" )
        [
           ( css::attribute( "open" ) = "{ " )
        + ( css::attribute( "close" ) = " }" )
        ]
      ;

   std::cout << style << io::object( ob ); // output: { [ a = 5 ], [ b = -1
] }

It should be possible to provide the ability to save/load styling to/from a
file and allow copying of style objects, e.g.:

   css::stylesheet< char > style2( "mystyles.style" ); // load styling
   style.load( "newstyles.style" );
   style = style2;
   style.save( "stylings.sty" );

NOTE: The css::stylesheet class will store the styles using something like:
   std::map< std::string, std::map< std::string, std::string > >
therefore it will be possible to use my library to implement the load and
save facilities!

Regards,
Reece

_________________________________________________________________
It's fast, it's easy and it's free. Get MSN Messenger today!
http://www.msn.co.uk/messenger


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