2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Authors: Nathan Binkert
36 #include "base/cprintf.hh"
44 while (!objects
.empty()) {
45 delete objects
.front();
51 ArgList::dump(const string
&format
)
53 list_t::iterator iter
= objects
.begin();
54 list_t::iterator end
= objects
.end();
56 const char *p
= format
.c_str();
59 stream
->flags((ios::fmtflags
)0);
72 bool end_number
= false;
73 bool have_precision
= false;
78 if (*p
>= '0' && *p
<= '9') {
81 } else if (number
> 0)
86 fmt
.format
= Format::string
;
91 fmt
.format
= Format::character
;
99 fmt
.format
= Format::integer
;
100 fmt
.base
= Format::hex
;
101 fmt
.alternate_form
= true;
106 fmt
.uppercase
= true;
108 fmt
.base
= Format::hex
;
109 fmt
.format
= Format::integer
;
114 fmt
.base
= Format::oct
;
115 fmt
.format
= Format::integer
;
122 fmt
.format
= Format::integer
;
127 fmt
.uppercase
= true;
129 fmt
.format
= Format::floating
;
130 fmt
.float_format
= Format::best
;
135 fmt
.uppercase
= true;
137 fmt
.format
= Format::floating
;
138 fmt
.float_format
= Format::scientific
;
143 fmt
.format
= Format::floating
;
144 fmt
.float_format
= Format::fixed
;
149 *stream
<< "we don't do %n!!!\n";
154 fmt
.alternate_form
= true;
158 fmt
.flush_left
= true;
162 fmt
.print_sign
= true;
166 fmt
.blank_space
= true;
172 have_precision
= true;
179 fmt
.fill_zero
= true;
191 number
= number
* 10 + (*p
- '0');
195 assert("we shouldn't get here");
205 fmt
.precision
= number
;
216 ios::fmtflags saved_flags
= stream
->flags();
217 char old_fill
= stream
->fill();
218 int old_precision
= stream
->precision();
220 (*iter
)->process(*stream
, fmt
);
222 stream
->flags(saved_flags
);
223 stream
->fill(old_fill
);
224 stream
->precision(old_precision
);
228 *stream
<< "<missing arg for format>";
246 size_t len
= strcspn(p
, "%\n\r\0");
247 stream
->write(p
, len
);
254 while (iter
!= end
) {
255 *stream
<< "<extra arg>";
261 ArgList::dumpToString(const string
&format
)