base,scons: Fixed `stats/hdf5.cc` CXXFlags to `-Wno-deprecated`
[gem5.git] / src / base / cprintf_formats.hh
index 0af493217d9787d84a0f78315e5a892cc9542d01..d111976cfc7aa8cca55006537a8f6efbd0f19e28 100644 (file)
  * 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 {
 
@@ -49,6 +48,8 @@ struct Format
     enum { best, fixed, scientific } float_format;
     int precision;
     int width;
+    bool get_precision;
+    bool get_width;
 
     Format() { clear(); }
 
@@ -62,8 +63,11 @@ struct Format
         uppercase = false;
         base = dec;
         format = none;
+        float_format = best;
         precision = -1;
         width = 0;
+        get_precision = false;
+        get_width = false;
     }
 };
 
@@ -82,6 +86,8 @@ _format_integer(std::ostream &out, const T &data, Format &fmt)
 {
     using namespace std;
 
+    ios::fmtflags flags(out.flags());
+
     switch (fmt.base) {
       case Format::hex:
         out.setf(std::ios::hex, std::ios::basefield);
@@ -131,6 +137,8 @@ _format_integer(std::ostream &out, const T &data, Format &fmt)
         out.setf(std::ios::uppercase);
 
     out << data;
+
+    out.flags(flags);
 }
 
 template <typename T>
@@ -139,6 +147,11 @@ _format_float(std::ostream &out, const T &data, Format &fmt)
 {
     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) {
@@ -183,6 +196,8 @@ _format_float(std::ostream &out, const T &data, Format &fmt)
     }
 
     out << data;
+
+    out.flags(flags);
 }
 
 template <typename T>
@@ -295,32 +310,12 @@ format_integer(std::ostream &out, unsigned char data, Format &fmt)
 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
@@ -346,10 +341,6 @@ inline void
 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__