ruby: message buffer: removes some unecessary functions.
[gem5.git] / src / base / cprintf.hh
index cff73a228c80afd9fee717619b8a89d9bbcb9fc8..e702fa3a6ef06cc65301e0f51917e3f1895922c6 100644 (file)
@@ -37,8 +37,8 @@
 #include <list>
 #include <string>
 
-#include "base/varargs.hh"
 #include "base/cprintf_formats.hh"
+#include "base/varargs.hh"
 
 namespace cp {
 
@@ -51,24 +51,54 @@ struct Print
     std::ostream &stream;
     const char *format;
     const char *ptr;
+    bool cont;
 
     std::ios::fmtflags saved_flags;
     char saved_fill;
     int saved_precision;
 
-    void process(Format &fmt);
+    Format fmt;
+    void process();
+    void process_flag();
 
   public:
     Print(std::ostream &stream, const std::string &format);
     Print(std::ostream &stream, const char *format);
     ~Print();
 
+    int
+    get_number(int data)
+    {
+        return data;
+    }
+    
+    template <typename T>
+    int
+    get_number(const T& data)
+    {
+        return 0;
+    }
+
     template <typename T>
     void
     add_arg(const T &data)
     {
-        Format fmt;
-        process(fmt);
+        if (!cont)
+            process();
+
+        if (fmt.get_width) {
+            fmt.get_width = false;
+            cont = true;
+            fmt.width = get_number(data);
+            return;
+        }
+            
+        if (fmt.get_precision) {
+            fmt.get_precision = false;
+            cont = true;
+            fmt.precision = get_number(data);
+            return;
+        }
 
         switch (fmt.format) {
           case Format::character:
@@ -96,7 +126,7 @@ struct Print
     void end_args();
 };
 
-/* end namespace cp */ }
+} // namespace cp
 
 typedef VarArgs::List<cp::Print> CPrintfArgsList;