Merge branch 'nix' into 'master'.
[jackhill/guix/guix.git] / nix / 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 class basic_format
34 {
35 public:
36 typedef std::string string_t;
37 typedef BOOST_IO_STD ostringstream internal_stream_t;
38 private:
39 typedef BOOST_IO_STD ostream stream_t;
40 typedef io::detail::stream_format_state stream_format_state;
41 typedef io::detail::format_item format_item_t;
42
43 public:
44 basic_format(const char* str);
45 basic_format(const string_t& s);
46 #ifndef BOOST_NO_STD_LOCALE
47 basic_format(const char* str, const std::locale & loc);
48 basic_format(const string_t& s, const std::locale & loc);
49 #endif // no locale
50 basic_format(const basic_format& x);
51 basic_format& operator= (const basic_format& x);
52
53 basic_format& clear(); // empty the string buffers (except bound arguments, see clear_binds() )
54
55 // pass arguments through those operators :
56 template<class T> basic_format& operator%(const T& x)
57 {
58 return io::detail::feed<const T&>(*this,x);
59 }
60
61 #ifndef BOOST_NO_OVERLOAD_FOR_NON_CONST
62 template<class T> basic_format& operator%(T& x)
63 {
64 return io::detail::feed<T&>(*this,x);
65 }
66 #endif
67
68
69 // system for binding arguments :
70 template<class T>
71 basic_format& bind_arg(int argN, const T& val)
72 {
73 return io::detail::bind_arg_body(*this, argN, val);
74 }
75 basic_format& clear_bind(int argN);
76 basic_format& clear_binds();
77
78 // modify the params of a directive, by applying a manipulator :
79 template<class T>
80 basic_format& modify_item(int itemN, const T& manipulator)
81 {
82 return io::detail::modify_item_body(*this, itemN, manipulator) ;
83 }
84
85 // Choosing which errors will throw exceptions :
86 unsigned char exceptions() const;
87 unsigned char exceptions(unsigned char newexcept);
88
89 // final output
90 string_t str() const;
91 friend BOOST_IO_STD ostream&
92 operator<< ( BOOST_IO_STD ostream& , const basic_format& );
93
94
95 template<class T> friend basic_format&
96 io::detail::feed(basic_format&, T);
97
98 template<class T> friend
99 void io::detail::distribute(basic_format&, T);
100
101 template<class T> friend
102 basic_format& io::detail::modify_item_body(basic_format&, int, const T&);
103
104 template<class T> friend
105 basic_format& io::detail::bind_arg_body(basic_format&, int, const T&);
106
107 // make the members private only if the friend templates are supported
108 private:
109
110 // flag bits, used for style_
111 enum style_values { ordered = 1, // set only if all directives are positional directives
112 special_needs = 4 };
113
114 // parse the format string :
115 void parse(const string_t&);
116
117 int style_; // style of format-string : positional or not, etc
118 int cur_arg_; // keep track of wich argument will come
119 int num_args_; // number of expected arguments
120 mutable bool dumped_; // true only after call to str() or <<
121 std::vector<format_item_t> items_; // vector of directives (aka items)
122 string_t prefix_; // piece of string to insert before first item
123
124 std::vector<bool> bound_; // stores which arguments were bound
125 // size = num_args OR zero
126 internal_stream_t oss_; // the internal stream.
127 stream_format_state state0_; // reference state for oss_
128 unsigned char exceptions_;
129 }; // class basic_format
130
131
132 } // namespace boost
133
134
135 #endif // BOOST_FORMAT_CLASS_HPP