Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:35:41

0001 // ----------------------------------------------------------------------------
0002 //  format_class.hpp :  class interface
0003 // ----------------------------------------------------------------------------
0004 
0005 //  Copyright Samuel Krempp 2003. Use, modification, and distribution are
0006 //  subject to the Boost Software License, Version 1.0. (See accompanying
0007 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 //  See http://www.boost.org/libs/format for library home page
0010 
0011 // ----------------------------------------------------------------------------
0012 
0013 #ifndef BOOST_FORMAT_CLASS_HPP
0014 #define BOOST_FORMAT_CLASS_HPP
0015 
0016 
0017 #include <vector>
0018 #include <string>
0019 
0020 #include <boost/optional.hpp> // to store locale when needed
0021 
0022 #include <boost/format/format_fwd.hpp>
0023 #include <boost/format/internals_fwd.hpp>
0024 #include <boost/format/internals.hpp>
0025 #include <boost/format/alt_sstream.hpp>
0026 
0027 namespace boost {
0028 
0029     template<class Ch, class Tr, class Alloc>
0030     class basic_format 
0031     {
0032         typedef typename io::CompatTraits<Tr>::compatible_type compat_traits;  
0033     public:
0034         typedef Ch  CharT;   // borland fails in operator% if we use Ch and Tr directly
0035         typedef std::basic_string<Ch, Tr, Alloc>              string_type;
0036         typedef typename string_type::size_type               size_type;
0037         typedef io::detail::format_item<Ch, Tr, Alloc>        format_item_t;
0038         typedef io::basic_altstringbuf<Ch, Tr, Alloc>         internal_streambuf_t;
0039         
0040 
0041         explicit basic_format(const Ch* str=NULL);
0042         explicit basic_format(const string_type& s);
0043         basic_format(const basic_format& x);
0044         basic_format& operator= (const basic_format& x);
0045         void swap(basic_format& x);
0046 
0047 #if !defined(BOOST_NO_STD_LOCALE)
0048         explicit basic_format(const Ch* str, const std::locale & loc);
0049         explicit basic_format(const string_type& s, const std::locale & loc);
0050 #endif
0051         io::detail::locale_t  getloc() const;
0052 
0053         basic_format& clear();       // empty all converted string buffers (except bound items)
0054         basic_format& clear_binds(); // unbind all bound items, and call clear()
0055         basic_format& parse(const string_type&); // resets buffers and parse a new format string
0056 
0057         // ** formatted result ** //
0058         size_type   size() const;    // sum of the current string pieces sizes
0059         string_type str()  const;    // final string 
0060 
0061         // ** arguments passing ** //
0062         template<class T>  
0063         basic_format&   operator%(const T& x)
0064             { return io::detail::feed<CharT, Tr, Alloc, const T&>(*this,x); }
0065 
0066 #ifndef BOOST_NO_OVERLOAD_FOR_NON_CONST
0067         template<class T>  basic_format&   operator%(T& x) 
0068             { return io::detail::feed<CharT, Tr, Alloc, T&>(*this,x); }
0069 #endif
0070 
0071         template<class T>
0072         basic_format& operator%(volatile const T& x)
0073             { /* make a non-volatile copy */ const T v(x);
0074               /* pass the copy along      */ return io::detail::feed<CharT, Tr, Alloc, const T&>(*this, v); }
0075 
0076 #ifndef BOOST_NO_OVERLOAD_FOR_NON_CONST
0077         template<class T>
0078         basic_format& operator%(volatile T& x)
0079             { /* make a non-volatile copy */ T v(x);
0080               /* pass the copy along      */ return io::detail::feed<CharT, Tr, Alloc, T&>(*this, v); }
0081 #endif
0082 
0083 #if defined(__GNUC__)
0084         // GCC can't handle anonymous enums without some help
0085         // ** arguments passing ** //
0086         basic_format&   operator%(const int& x)
0087             { return io::detail::feed<CharT, Tr, Alloc, const int&>(*this,x); }
0088 
0089 #ifndef BOOST_NO_OVERLOAD_FOR_NON_CONST
0090         basic_format&   operator%(int& x)
0091             { return io::detail::feed<CharT, Tr, Alloc, int&>(*this,x); }
0092 #endif
0093 #endif
0094 
0095         // The total number of arguments expected to be passed to the format objectt
0096         int expected_args() const
0097             { return num_args_; }
0098         // The number of arguments currently bound (see bind_arg(..) )
0099         int bound_args() const;
0100         // The number of arguments currently fed to the format object
0101         int fed_args() const;
0102         // The index (1-based) of the current argument (i.e. next to be formatted)
0103         int cur_arg() const;
0104         // The number of arguments still required to be fed
0105         int remaining_args() const; // same as expected_args() - bound_args() - fed_args()
0106 
0107 
0108         // ** object modifying **//
0109         template<class T>
0110         basic_format&  bind_arg(int argN, const T& val) 
0111             { return io::detail::bind_arg_body(*this, argN, val); }
0112         basic_format&  clear_bind(int argN);
0113         template<class T> 
0114         basic_format&  modify_item(int itemN, T manipulator) 
0115             { return io::detail::modify_item_body<Ch,Tr, Alloc, T> (*this, itemN, manipulator);}
0116 
0117         // Choosing which errors will throw exceptions :
0118         unsigned char exceptions() const;
0119         unsigned char exceptions(unsigned char newexcept);
0120 
0121 #if !defined( BOOST_NO_MEMBER_TEMPLATE_FRIENDS )  \
0122     && !BOOST_WORKAROUND(BOOST_BORLANDC, <= 0x570) \
0123     && !BOOST_WORKAROUND( _CRAYC, != 0) \
0124     && !BOOST_WORKAROUND(__DECCXX_VER, BOOST_TESTED_AT(60590042))
0125         // use friend templates and private members only if supported
0126 
0127 #ifndef  BOOST_NO_TEMPLATE_STD_STREAM
0128         template<class Ch2, class Tr2, class Alloc2>
0129         friend std::basic_ostream<Ch2, Tr2> & 
0130         operator<<( std::basic_ostream<Ch2, Tr2> & ,
0131                     const basic_format<Ch2, Tr2, Alloc2>& );
0132 #else
0133         template<class Ch2, class Tr2, class Alloc2>
0134         friend std::ostream & 
0135         operator<<( std::ostream & ,
0136                     const basic_format<Ch2, Tr2, Alloc2>& );
0137 #endif
0138 
0139         template<class Ch2, class Tr2, class Alloc2, class T>  
0140         friend basic_format<Ch2, Tr2, Alloc2>&  
0141         io::detail::feed_impl (basic_format<Ch2, Tr2, Alloc2>&, T);
0142 
0143         template<class Ch2, class Tr2, class Alloc2, class T>  friend   
0144         void io::detail::distribute (basic_format<Ch2, Tr2, Alloc2>&, T);
0145         
0146         template<class Ch2, class Tr2, class Alloc2, class T>  friend
0147         basic_format<Ch2, Tr2, Alloc2>& 
0148         io::detail::modify_item_body (basic_format<Ch2, Tr2, Alloc2>&, int, T);
0149         
0150         template<class Ch2, class Tr2, class Alloc2, class T> friend
0151         basic_format<Ch2, Tr2, Alloc2>&  
0152         io::detail::bind_arg_body (basic_format<Ch2, Tr2, Alloc2>&, int, const T&);
0153 
0154     private:
0155 #endif
0156         typedef io::detail::stream_format_state<Ch, Tr>  stream_format_state;
0157         // flag bits, used for style_
0158         enum style_values  { ordered = 1, // set only if all directives are  positional
0159                              special_needs = 4 };     
0160 
0161         void make_or_reuse_data(std::size_t nbitems);// used for (re-)initialisation
0162 
0163         // member data --------------------------------------------//
0164         std::vector<format_item_t>  items_; // each '%..' directive leads to a format_item
0165         std::vector<bool> bound_; // stores which arguments were bound. size() == 0 || num_args
0166 
0167         int              style_; // style of format-string :  positional or not, etc
0168         int             cur_arg_; // keep track of wich argument is current
0169         int            num_args_; // number of expected arguments
0170         mutable bool     dumped_; // true only after call to str() or <<
0171         string_type      prefix_; // piece of string to insert before first item
0172         unsigned char exceptions_;
0173         internal_streambuf_t   buf_; // the internal stream buffer.
0174         boost::optional<io::detail::locale_t>     loc_;
0175     }; // class basic_format
0176 
0177 } // namespace boost
0178 
0179 
0180 #endif // BOOST_FORMAT_CLASS_HPP