]> git.lyx.org Git - lyx.git/blob - boost/boost/format/format_class.hpp
update to boost 1.30.1
[lyx.git] / boost / boost / format / format_class.hpp
1 // -*- C++ -*-
2 //  Boost general library 'format'   ---------------------------
3 //  See http://www.boost.org for updates, documentation, and revision history.
4
5 //  (C) Samuel Krempp 2001
6 //                  krempp@crans.ens-cachan.fr
7 //  Permission to copy, use, modify, sell and
8 //  distribute this software is granted provided this copyright notice appears
9 //  in all copies. This software is provided "as is" without express or implied
10 //  warranty, and with no claim as to its suitability for any purpose.
11
12 // ideas taken from RĂ¼diger Loos's format class
13 // and Karl Nelson's ofstream (also took its parsing code as basis for printf parsing)
14
15 // ------------------------------------------------------------------------------
16 // format_class.hpp :  class interface
17 // ------------------------------------------------------------------------------
18
19
20 #ifndef BOOST_FORMAT_CLASS_HPP
21 #define BOOST_FORMAT_CLASS_HPP
22
23 #include <vector>
24 #include <string>
25
26 #include <boost/format/format_fwd.hpp>
27 #include <boost/format/internals_fwd.hpp>
28
29 #include <boost/format/internals.hpp>
30
31 namespace boost {
32
33 template<class Ch, class Tr>
34 class basic_format 
35 {
36 public:
37   typedef Ch  CharT;   // those 2 are necessary for borland compatibilty,
38   typedef Tr  Traits;  // in the body of the operator% template.
39
40
41   typedef std::basic_string<Ch, Tr>                string_t;
42   typedef BOOST_IO_STD basic_ostringstream<Ch, Tr> internal_stream_t;
43 private:
44   typedef BOOST_IO_STD basic_ostream<Ch, Tr>       stream_t;
45   typedef io::detail::stream_format_state<Ch, Tr>  stream_format_state;
46   typedef io::detail::format_item<Ch, Tr>          format_item_t;
47
48 public:
49   basic_format(const Ch* str);
50   basic_format(const string_t& s);
51 #ifndef BOOST_NO_STD_LOCALE
52   basic_format(const Ch* str, const std::locale & loc);
53   basic_format(const string_t& s, const std::locale & loc);
54 #endif // no locale
55   basic_format(const basic_format& x);
56   basic_format& operator= (const basic_format& x);
57
58   basic_format& clear(); // empty the string buffers (except bound arguments, see clear_binds() )
59
60   // pass arguments through those operators :
61   template<class T>  basic_format&   operator%(const T& x) 
62   { 
63     return io::detail::feed<CharT, Traits, const T&>(*this,x);
64   }
65
66 #ifndef BOOST_NO_OVERLOAD_FOR_NON_CONST
67   template<class T>  basic_format&   operator%(T& x) 
68   {
69     return io::detail::feed<CharT, Traits, T&>(*this,x);
70   }
71 #endif
72
73
74   // system for binding arguments :
75   template<class T>  
76   basic_format&         bind_arg(int argN, const T& val) 
77   {
78     return io::detail::bind_arg_body(*this, argN, val); 
79   }
80   basic_format&         clear_bind(int argN);
81   basic_format&         clear_binds();
82
83   // modify the params of a directive, by applying a manipulator :
84   template<class T> 
85   basic_format&  modify_item(int itemN, const T& manipulator) 
86   {
87     return io::detail::modify_item_body(*this, itemN, manipulator) ;
88   }
89
90   // Choosing which errors will throw exceptions :
91   unsigned char exceptions() const;
92   unsigned char exceptions(unsigned char newexcept);
93
94   // final output
95   string_t str() const;
96   friend BOOST_IO_STD basic_ostream<Ch, Tr>& 
97 #if BOOST_WORKAROUND( BOOST_MSVC, <= 1300) \
98  &&  BOOST_WORKAROUND( BOOST_MSVC,  BOOST_TESTED_AT( 1300) )
99   operator<< ( BOOST_IO_STD basic_ostream<Ch, Tr>& , const basic_format& ); 
100 #else
101   operator<< <Ch, Tr> ( BOOST_IO_STD basic_ostream<Ch, Tr>& , const basic_format& ); 
102 #endif
103                       
104
105 #if !defined( BOOST_NO_MEMBER_TEMPLATE_FRIENDS )  && ! BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x570) ) && !BOOST_WORKAROUND( _CRAYC, != 0)
106
107   template<class Ch2, class Tr2, class T>  friend basic_format<Ch2, Tr2>&  
108   io::detail::feed(basic_format<Ch2,Tr2>&, T);
109     
110   template<class Ch2, class Tr2, class T>  friend   
111   void io::detail::distribute(basic_format<Ch2,Tr2>&, T);
112   
113   template<class Ch2, class Tr2, class T>  friend
114   basic_format<Ch2, Tr2>&  io::detail::modify_item_body(basic_format<Ch2, Tr2>&, int, const T&);
115
116   template<class Ch2, class Tr2, class T> friend
117   basic_format<Ch2, Tr2>&  io::detail::bind_arg_body(basic_format<Ch2, Tr2>&, int, const T&);
118
119 // make the members private only if the friend templates are supported
120 private:
121 #endif
122
123   // flag bits, used for style_
124   enum style_values  { ordered = 1,        // set only if all directives are  positional directives
125                        special_needs = 4 };     
126
127   // parse the format string :
128   void parse(const string_t&);
129
130   int                           style_;         // style of format-string :  positional or not, etc
131   int                           cur_arg_;       // keep track of wich argument will come
132   int                           num_args_;      // number of expected arguments
133   mutable bool                  dumped_;        // true only after call to str() or <<
134   std::vector<format_item_t>    items_;         // vector of directives (aka items)
135   string_t                      prefix_;        // piece of string to insert before first item
136
137   std::vector<bool>             bound_;         // stores which arguments were bound
138                                                 //   size = num_args OR zero
139   internal_stream_t             oss_;           // the internal stream.
140   stream_format_state           state0_;        // reference state for oss_
141   unsigned char                 exceptions_;
142 }; // class basic_format
143
144
145 } // namespace boost
146
147
148 #endif // BOOST_FORMAT_CLASS_HPP