* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Authors: Nathan Binkert
*/
-#ifndef __CPRINTF_FORMATS_HH__
-#define __CPRINTF_FORMATS_HH__
+#ifndef __BASE_CPRINTF_FORMATS_HH__
+#define __BASE_CPRINTF_FORMATS_HH__
-#include <sstream>
+#include <cstring>
#include <ostream>
+#include <sstream>
namespace cp {
enum { best, fixed, scientific } float_format;
int precision;
int width;
+ bool get_precision;
+ bool get_width;
Format() { clear(); }
uppercase = false;
base = dec;
format = none;
+ float_format = best;
precision = -1;
width = 0;
+ get_precision = false;
+ get_width = false;
}
};
{
using namespace std;
+ ios::fmtflags flags(out.flags());
+
switch (fmt.base) {
case Format::hex:
out.setf(std::ios::hex, std::ios::basefield);
out.setf(std::ios::uppercase);
out << data;
+
+ out.flags(flags);
}
template <typename T>
{
using namespace std;
+ ios::fmtflags flags(out.flags());
+
+ if (fmt.fill_zero)
+ out.fill('0');
+
switch (fmt.float_format) {
case Format::scientific:
if (fmt.precision != -1) {
}
out << data;
+
+ out.flags(flags);
}
template <typename T>
inline void
format_integer(std::ostream &out, signed char data, Format &fmt)
{ _format_integer(out, (int)data, fmt); }
-#if 0
inline void
-format_integer(std::ostream &out, short data, Format &fmt)
-{ _format_integer(out, data, fmt); }
+format_integer(std::ostream &out, const unsigned char *data, Format &fmt)
+{ _format_integer(out, (uintptr_t)data, fmt); }
inline void
-format_integer(std::ostream &out, unsigned short data, Format &fmt)
-{ _format_integer(out, data, fmt); }
-inline void
-format_integer(std::ostream &out, int data, Format &fmt)
-{ _format_integer(out, data, fmt); }
-inline void
-format_integer(std::ostream &out, unsigned int data, Format &fmt)
-{ _format_integer(out, data, fmt); }
-inline void
-format_integer(std::ostream &out, long data, Format &fmt)
-{ _format_integer(out, data, fmt); }
-inline void
-format_integer(std::ostream &out, unsigned long data, Format &fmt)
-{ _format_integer(out, data, fmt); }
-inline void
-format_integer(std::ostream &out, long long data, Format &fmt)
-{ _format_integer(out, data, fmt); }
-inline void
-format_integer(std::ostream &out, unsigned long long data, Format &fmt)
-{ _format_integer(out, data, fmt); }
-#endif
+format_integer(std::ostream &out, const signed char *data, Format &fmt)
+{ _format_integer(out, (uintptr_t)data, fmt); }
//
// floating point formats
format_string(std::ostream &out, const T &data, Format &fmt)
{ _format_string(out, data, fmt); }
-inline void
-format_string(std::ostream &out, const std::stringstream &data, Format &fmt)
-{ _format_string(out, data.str(), fmt); }
-
} // namespace cp
#endif // __CPRINTF_FORMATS_HH__