Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57734 - trunk/boost/format
From: Samuel.Krempp_at_[hidden]
Date: 2009-11-17 17:46:34


Author: samuel_krempp
Date: 2009-11-17 17:46:33 EST (Tue, 17 Nov 2009)
New Revision: 57734
URL: http://svn.boost.org/trac/boost/changeset/57734

Log:
adds functions returning number of expected (|remaining|fed|bound) args
closes Ticket #2867 (feature request)
Text files modified:
   trunk/boost/format/format_class.hpp | 12 ++++++++++++
   trunk/boost/format/format_implementation.hpp | 37 ++++++++++++++++++++++++++++++++++++-
   2 files changed, 48 insertions(+), 1 deletions(-)

Modified: trunk/boost/format/format_class.hpp
==============================================================================
--- trunk/boost/format/format_class.hpp (original)
+++ trunk/boost/format/format_class.hpp 2009-11-17 17:46:33 EST (Tue, 17 Nov 2009)
@@ -80,6 +80,18 @@
 #endif
 #endif
 
+ // The total number of arguments expected to be passed to the format objectt
+ int expected_args() const
+ { return num_args_; }
+ // The number of arguments currently bound (see bind_arg(..) )
+ int bound_args() const;
+ // The number of arguments currently fed to the format object
+ int fed_args() const;
+ // The index (1-based) of the current argument (i.e. next to be formatted)
+ int cur_arg() const;
+ // The number of arguments still required to be fed
+ int remaining_args() const; // same as expected_args() - bound_args() - fed_args()
+
 
         // ** object modifying **//
         template<class T>

Modified: trunk/boost/format/format_implementation.hpp
==============================================================================
--- trunk/boost/format/format_implementation.hpp (original)
+++ trunk/boost/format/format_implementation.hpp 2009-11-17 17:46:33 EST (Tue, 17 Nov 2009)
@@ -172,6 +172,41 @@
     }
 
     template< class Ch, class Tr, class Alloc>
+ int basic_format<Ch,Tr, Alloc>::
+ bound_args() const {
+ int n=0;
+ for(int i=0; i<num_args_ ; ++i)
+ if(bound_[i])
+ ++n;
+ return n;
+ }
+
+ template< class Ch, class Tr, class Alloc>
+ int basic_format<Ch,Tr, Alloc>::
+ fed_args() const {
+ int n=0;
+ for(int i=0; i<cur_arg_ ; ++i)
+ if(!bound_[i])
+ ++n;
+ return n;
+ }
+
+ template< class Ch, class Tr, class Alloc>
+ int basic_format<Ch,Tr, Alloc>::
+ cur_arg() const {
+ { return cur_arg_+1; }
+
+ template< class Ch, class Tr, class Alloc>
+ int basic_format<Ch,Tr, Alloc>::
+ remaining_args() const {
+ int n=0;
+ for(int i=cur_arg_; i<num_args_ ; ++i)
+ if(!bound_[i])
+ ++n;
+ return n;
+ }
+
+ template< class Ch, class Tr, class Alloc>
     typename basic_format<Ch, Tr, Alloc>::string_type
     basic_format<Ch,Tr, Alloc>::
     str () const {
@@ -261,7 +296,7 @@
             while(self.cur_arg_ < self.num_args_ && self.bound_[self.cur_arg_])
                 ++self.cur_arg_;
         }
- // In any case, we either have all args, or are on a non-binded arg :
+ // In any case, we either have all args, or are on an unbound arg :
         BOOST_ASSERT( self.cur_arg_ >= self.num_args_ || ! self.bound_[self.cur_arg_]);
         return self;
     }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk