Boost logo

Boost :

From: John Torjo (john.lists_at_[hidden])
Date: 2004-09-22 09:25:53


Vladimir Prus wrote:

> John Torjo wrote:
>
>
>>I would suggest every formatter takes only one string which parses and
>>finds all decorators itself.
>>Each formatter will have one or more escape sequences which it uses to
>>find the decorators.
>>
>>
>>Something like:
>>
>>// in this case, '%' is used for identifying an element
>>// '*' is to mean "leave default" (don't change)
>>
>>std::vector<int> v;
>>// equivalent to your "[ ", ", ", " ]"
>>std::cout << formatob(v, "[ %, % ]");
>
> .......
>
>>// for pair - you have "%1" and "%2"
>>std::vector< std::pair<int,long> > vp;
>>// write XML
>>std::cout << formatob(vp,
>> containerfmt("<elem> % </elem><elem> % </elem>",
>
>
> And how do you know what to output if there's only one element?
>

Basically this is just a simper interface for the user.
The decorator will parse the string, which in the above case means:

- open: "<elem> "
- seq : " </elem><elem> "
- close: " </elem>"

But to the human eye, it's much easier to understand:
"<elem> % </elem><elem> % </elem>"

than
"<elem> "," </elem><elem> "," </elem>"

At least, IMO.

Best,
John

-- 
John Torjo
-- john_at_[hidden]
Contributing editor, C/C++ Users Journal
-- "Win32 GUI Generics" -- generics & GUI do mix, after all
-- http://www.torjo.com/win32gui/
-- v1.4 - save_dlg - true binding of your data to UI controls!
    + easily add validation rules (win32gui/examples/smart_dlg)

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