|
Boost : |
From: John Torjo (john.lists_at_[hidden])
Date: 2004-09-21 11:26:56
Hi Reece,
This just popped into my head. A lot of confusion seems to come from how
you pass decorators. What I'm trying to say is that it can be very
difficult to get the decorator strings right (especially for more
complex things like XML) from the first time.
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, "[ %, % ]");
// eq. to "<< ", " | ", " >>"
std::cout << formatob(v, "<< % | % >>");
// set only open/close decorators
std::cout << formatob(v, "<< %*% >>");
// sets only the separator
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>",
pairfrt("<int>%1</int><long>%2</long>")));
How's that?
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