summaryrefslogtreecommitdiff
path: root/nix/boost/format/feed_args.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'nix/boost/format/feed_args.hpp')
-rw-r--r--nix/boost/format/feed_args.hpp247
1 files changed, 0 insertions, 247 deletions
diff --git a/nix/boost/format/feed_args.hpp b/nix/boost/format/feed_args.hpp
deleted file mode 100644
index 3d0b47b4a12..00000000000
--- a/nix/boost/format/feed_args.hpp
+++ /dev/null
@@ -1,247 +0,0 @@
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
14
15// ----------------------------------------------------------------------------
16// feed_args.hpp : functions for processing each argument
17// (feed, feed_manip, and distribute)
18// ----------------------------------------------------------------------------
19
20
21#ifndef BOOST_FORMAT_FEED_ARGS_HPP
22#define BOOST_FORMAT_FEED_ARGS_HPP
23
24#include "boost/format/format_class.hpp"
25#include "boost/format/group.hpp"
26
27#include "boost/throw_exception.hpp"
28
29namespace boost {
30namespace io {
31namespace detail {
32namespace {
33
34 inline
35 void empty_buf(BOOST_IO_STD ostringstream & os) {
36 static const std::string emptyStr;
37 os.str(emptyStr);
38 }
39
40 void do_pad( std::string & s,
41 std::streamsize w,
42 const char c,
43 std::ios::fmtflags f,
44 bool center)
45 // applies centered / left / right padding to the string s.
46 // Effects : string s is padded.
47 {
48 std::streamsize n=w-s.size();
49 if(n<=0) {
50 return;
51 }
52 if(center)
53 {
54 s.reserve(w); // allocate once for the 2 inserts
55 const std::streamsize n1 = n /2, n0 = n - n1;
56 s.insert(s.begin(), n0, c);
57 s.append(n1, c);
58 }
59 else
60 {
61 if(f & std::ios::left) {
62 s.append(n, c);
63 }
64 else {
65 s.insert(s.begin(), n, c);
66 }
67 }
68 } // -do_pad(..)
69
70
71 template<class T> inline
72 void put_head(BOOST_IO_STD ostream& , const T& ) {
73 }
74
75 template<class T> inline
76 void put_head( BOOST_IO_STD ostream& os, const group1<T>& x ) {
77 os << group_head(x.a1_); // send the first N-1 items, not the last
78 }
79
80 template<class T> inline
81 void put_last( BOOST_IO_STD ostream& os, const T& x ) {
82 os << x ;
83 }
84
85 template<class T> inline
86 void put_last( BOOST_IO_STD ostream& os, const group1<T>& x ) {
87 os << group_last(x.a1_); // this selects the last element
88 }
89
90#ifndef BOOST_NO_OVERLOAD_FOR_NON_CONST
91 template<class T> inline
92 void put_head( BOOST_IO_STD ostream& , T& ) {
93 }
94
95 template<class T> inline
96 void put_last( BOOST_IO_STD ostream& os, T& x ) {
97 os << x ;
98 }
99#endif
100
101
102
103
104template<class T>
105void put( T x,
106 const format_item& specs,
107 std::string & res,
108 BOOST_IO_STD ostringstream& oss_ )
109{
110 // does the actual conversion of x, with given params, into a string
111 // using the *supplied* strinstream. (the stream state is important)
112
113 typedef std::string string_t;
114 typedef format_item format_item_t;
115
116 stream_format_state prev_state(oss_);
117
118 specs.state_.apply_on(oss_);
119
120 // in case x is a group, apply the manip part of it,
121 // in order to find width
122 put_head( oss_, x );
123 empty_buf( oss_);
124
125 const std::streamsize w=oss_.width();
126 const std::ios::fmtflags fl=oss_.flags();
127 const bool internal = (fl & std::ios::internal) != 0;
128 const bool two_stepped_padding = internal
129 && ! ( specs.pad_scheme_ & format_item_t::spacepad )
130 && specs.truncate_ < 0 ;
131
132
133 if(! two_stepped_padding)
134 {
135 if(w>0) // handle simple padding via do_pad, not natively in stream
136 oss_.width(0);
137 put_last( oss_, x);
138 res = oss_.str();
139
140 if (specs.truncate_ >= 0)
141 res.erase(specs.truncate_);
142
143 // complex pads :
144 if(specs.pad_scheme_ & format_item_t::spacepad)
145 {
146 if( res.size()==0 || ( res[0]!='+' && res[0]!='-' ))
147 {
148 res.insert(res.begin(), 1, ' '); // insert 1 space at pos 0
149 }
150 }
151 if(w > 0) // need do_pad
152 {
153 do_pad(res,w,oss_.fill(), fl, (specs.pad_scheme_ & format_item_t::centered) !=0 );
154 }
155 }
156 else // 2-stepped padding
157 {
158 put_last( oss_, x); // oss_.width() may result in padding.
159 res = oss_.str();
160
161 if (specs.truncate_ >= 0)
162 res.erase(specs.truncate_);
163
164 if( res.size() - w > 0)
165 { // length w exceeded
166 // either it was multi-output with first output padding up all width..
167 // either it was one big arg and we are fine.
168 empty_buf( oss_);
169 oss_.width(0);
170 put_last(oss_, x );
171 string_t tmp = oss_.str(); // minimal-length output
172 std::streamsize d;
173 if( (d=w - tmp.size()) <=0 )
174 {
175 // minimal length is already >= w, so no padding (cool!)
176 res.swap(tmp);
177 }
178 else
179 { // hum.. we need to pad (it was necessarily multi-output)
180 typedef typename string_t::size_type size_type;
181 size_type i = 0;
182 while( i<tmp.size() && tmp[i] == res[i] ) // find where we should pad.
183 ++i;
184 tmp.insert(i, static_cast<size_type>( d ), oss_.fill());
185 res.swap( tmp );
186 }
187 }
188 else
189 { // okay, only one thing was printed and padded, so res is fine.
190 }
191 }
192
193 prev_state.apply_on(oss_);
194 empty_buf( oss_);
195 oss_.clear();
196} // end- put(..)
197
198
199} // local namespace
200
201
202
203
204
205template<class T>
206void distribute(basic_format& self, T x)
207 // call put(x, ..) on every occurence of the current argument :
208{
209 if(self.cur_arg_ >= self.num_args_)
210 {
211 if( self.exceptions() & too_many_args_bit )
212 boost::throw_exception(too_many_args()); // too many variables have been supplied !
213 else return;
214 }
215 for(unsigned long i=0; i < self.items_.size(); ++i)
216 {
217 if(self.items_[i].argN_ == self.cur_arg_)
218 {
219 put<T> (x, self.items_[i], self.items_[i].res_, self.oss_ );
220 }
221 }
222}
223
224template<class T>
225basic_format& feed(basic_format& self, T x)
226{
227 if(self.dumped_) self.clear();
228 distribute<T> (self, x);
229 ++self.cur_arg_;
230 if(self.bound_.size() != 0)
231 {
232 while( self.cur_arg_ < self.num_args_ && self.bound_[self.cur_arg_] )
233 ++self.cur_arg_;
234 }
235
236 // this arg is finished, reset the stream's format state
237 self.state0_.apply_on(self.oss_);
238 return self;
239}
240
241
242} // namespace detail
243} // namespace io
244} // namespace boost
245
246
247#endif // BOOST_FORMAT_FEED_ARGS_HPP