Boost::Format add-on

Who is in charge of Format maintenance ? I would like to propose a simple patch to add an accessor to the number of arguments expected by the formating : int args() const { return num_args_; } Regards

Joel Falcou <joel.falcou <at> u-psud.fr> writes:
Who is in charge of Format maintenance ?
Sorry, but I don't know. Just some comments on what's proposed. Also, you might post a patch to trac. It's too bad boost doesn't have something like reviewboard setup for proposed patches. http://code.google.com/p/reviewboard/
I would like to propose a simple patch to add an accessor to the number of arguments expected by the formating :
int args() const { return num_args_; }
I'm not a fan of this name and think that more should be done. For the method name, I think "num_expected_args" would be better. Further, "num_bound_args" and "num_remaining_args" may be nice to have. Finally, I'd like to see better documentation on the already existing "size" method. It's somewhat buried in the html documentation and the header docs are not as clear as they should be. -Ryan

Ryan Gallagher a écrit :
Joel Falcou <joel.falcou <at> u-psud.fr> writes:
Who is in charge of Format maintenance ?
Sorry, but I don't know. Just some comments on what's proposed. Also, you might post a patch to trac. It's too bad boost doesn't have something like reviewboard setup for proposed patches. http://code.google.com/p/reviewboard/
Indeed
I'm not a fan of this name and think that more should be done. For the method name, I think "num_expected_args" would be better. Further, "num_bound_args" and "num_remaining_args" may be nice to have.
This name was just thrown into the mail. Any better namle is welcomed.
Finally, I'd like to see better documentation on the already existing "size" method. It's somewhat buried in the html documentation and the header docs are not as clear as they should be.
Same here -- ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35

----- Original Message ----- From: "Ryan Gallagher" <ryan.gallagher@gmail.com> To: <boost@lists.boost.org> Sent: Tuesday, March 17, 2009 5:29 PM Subject: Re: [boost] Boost::Format add-on
Joel Falcou <joel.falcou <at> u-psud.fr> writes:
Who is in charge of Format maintenance ?
Sorry, but I don't know. Just some comments on what's proposed. Also, you might post a patch to trac. It's too bad boost doesn't have something like reviewboard setup for proposed patches. http://code.google.com/p/reviewboard/
I would like to propose a simple patch to add an accessor to the number of arguments expected by the formating :
int args() const { return num_args_; }
I'm not a fan of this name and think that more should be done. For the method name, I think "num_expected_args" would be better. Further, "num_bound_args" and "num_remaining_args" may be nice to have.
Finally, I'd like to see better documentation on the already existing "size" method. It's somewhat buried in the html documentation and the header docs are not as clear as they should be.
Hi, you might post a patch to trac ;-) Vicente

vicente.botet <vicente.botet <at> wanadoo.fr> writes:
From: "Ryan Gallagher" <ryan.gallagher <at> gmail.com> [snip]
Also, you might post a patch to trac. [snip]
I'm not a fan of this name and think that more should be done. For the method name, I think "num_expected_args" would be better. Further, "num_bound_args" and "num_remaining_args" may be nice to have.
Finally, I'd like to see better documentation on the already existing "size" method. It's somewhat buried in the html documentation and the header docs are not as clear as they should be.
you might post a patch to trac
I was wondering how long it'd take for someone to reply with this. ;-) I'm not really as antsy for the change as Joel may be. But if he doesn't mind I'd be happy to post a patch to trac in the next day or so. -Ryan

joel falcou <joel.falcou <at> u-psud.fr> writes:
I'm not really as antsy for the change as Joel may be. But if he doesn't mind I'd be happy to post a patch to trac in the next day or so.
I can do the patch, we just have to settle on the method name :)
Well, I guess I gave my vote, but I'm open to other suggestions as well. I didn't see your message until now and already have a patch using my suggested names. You can use it if filing a trac item, otherwise feel free to modify or redo if the names change. -Ryan PS -- Another possible accessor is num_items, perhaps useful in conjunction with modify_item, though I don't really see much of a use-case for it so left it out. Index: boost/format/format_class.hpp =================================================================== --- boost/format/format_class.hpp (revision 51826) +++ boost/format/format_class.hpp (working copy) @@ -50,12 +50,22 @@ #endif io::detail::locale_t getloc() const; + // The total number of arguments expected to be passed to the format string. + int num_expected_args() const + { return num_args_; } + // The number of arguments currently bound to the format string. + int num_bound_args() const + { return cur_arg_; } + // The number of arguments still required to be passed to the format string. + int num_remaining_args() const + { return num_expected_args() - num_bound_args(); } + basic_format& clear(); // empty all converted string buffers (except bound items) basic_format& clear_binds(); // unbind all bound items, and call clear() basic_format& parse(const string_type&); // resets buffers and parse a new format string // ** formatted result ** // - size_type size() const; // sum of the current string pieces sizes + size_type size() const; // The number of characters in the formatted result string. string_type str() const; // final string // ** arguments passing ** // @@ -127,7 +137,7 @@ std::vector<format_item_t> items_; // each '%..' directive leads to a format_item std::vector<bool> bound_; // stores which arguments were bound. size() == 0 || num_args - int style_; // style of format-string : positional or not, etc + int style_; // style of format-string : positional or not, etc int cur_arg_; // keep track of wich argument is current int num_args_; // number of expected arguments mutable bool dumped_; // true only after call to str() or << Index: libs/format/test/format_test3.cpp =================================================================== --- libs/format/test/format_test3.cpp (revision 51826) +++ libs/format/test/format_test3.cpp (working copy) @@ -93,6 +93,31 @@ BOOST_ERROR("nesting did not work"); } + // observers + BOOST_CHECK_EQUAL(format("foo").num_expected_args(), 0); + BOOST_CHECK_EQUAL(format("foo").num_bound_args(), 0); + BOOST_CHECK_EQUAL(format("foo").num_remaining_args(), 0); + + BOOST_CHECK_EQUAL(format("foo%s").num_expected_args(), 1); + BOOST_CHECK_EQUAL(format("foo%s").num_bound_args(), 0); + BOOST_CHECK_EQUAL(format("foo%s").num_remaining_args(), 1); + + BOOST_CHECK_EQUAL((format("foo%s") % "bar").num_expected_args(), 1); + BOOST_CHECK_EQUAL((format("foo%s") % "bar").num_bound_args(), 1); + BOOST_CHECK_EQUAL((format("foo%s") % "bar").num_remaining_args(), 0); + + BOOST_CHECK_EQUAL((format("%2%%1%") % "bar" % "foo").num_expected_args(), 2); + BOOST_CHECK_EQUAL((format("%2%%1%") % "bar" % "foo").num_bound_args(), 2); + BOOST_CHECK_EQUAL((format("%2%%1%") % "bar" % "foo").num_remaining_args(), 0); + + BOOST_CHECK_EQUAL((format("%1$s %2$s %1$s") % "bar").num_expected_args(), 2); + BOOST_CHECK_EQUAL((format("%1$s %2$s %1$s") % "bar").num_bound_args(), 1); + BOOST_CHECK_EQUAL((format("%1$s %2$s %1$s") % "bar").num_remaining_args(), 1); + + BOOST_CHECK_EQUAL((format("%1%, %2%, %|40t|%3%\n") % "foo" % "bar").num_expected_args(), 3); + BOOST_CHECK_EQUAL((format("%1%, %2%, %|40t|%3%\n") % "foo" % "bar").num_bound_args(), 2); + BOOST_CHECK_EQUAL((format("%1%, %2%, %|40t|%3%\n") % "foo" % "bar").num_remaining_args(), 1); + // testcase for bug reported at // http://lists.boost.org/boost-users/2006/05/19723.php format f("%40t%1%");

Ryan Gallagher a écrit :
joel falcou <joel.falcou <at> u-psud.fr> writes:
I'm not really as antsy for the change as Joel may be. But if he doesn't mind I'd be happy to post a patch to trac in the next day
or so.
I can do the patch, we just have to settle on the method name :)
Well, I guess I gave my vote, but I'm open to other suggestions as well.
I didn't see your message until now and already have a patch using my suggested names. You can use it if filing a trac item, otherwise feel free to modify or redo if the names change.
-Ryan
PS -- Another possible accessor is num_items, perhaps useful in conjunction with modify_item, though I don't really see much of a use-case for it so left it out Sounds good to me. I am not that picky on this matter so this patch is fine.
I'll file a trac during the evening. -- ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35

Feature submitted on trac : https://svn.boost.org/trac/boost/ticket/2867 -- ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35

----- Original Message ----- From: "Joel Falcou" <joel.falcou@u-psud.fr> To: <boost@lists.boost.org> Sent: Tuesday, March 17, 2009 3:08 PM Subject: [boost] Boost::Format add-on
Who is in charge of Format maintenance ? I would like to propose a simple patch to add an accessor to the number of arguments expected by the formating :
int args() const { return num_args_; }
Hi, You can find the list of maintainer in libs/maintainers.txt on the distribution directory format Samuel Krempp <krempp -at- crans.ens-cachan.fr> Best, Vicente
participants (4)
-
joel falcou
-
Joel Falcou
-
Ryan Gallagher
-
vicente.botet