summaryrefslogtreecommitdiff
path: root/src/base/cprintf.hh
diff options
context:
space:
mode:
authorAndreas Sandberg <Andreas.Sandberg@ARM.com>2014-08-26 10:13:45 -0400
committerAndreas Sandberg <Andreas.Sandberg@ARM.com>2014-08-26 10:13:45 -0400
commit70176fecd1ff04f7b8957f3110497d758310b569 (patch)
treeec2f32ee03a8a43a31bcfedd164b1ec3ee229532 /src/base/cprintf.hh
parentf3e5fee74373d16849a58a80827c54c773aa05e2 (diff)
downloadgem5-70176fecd1ff04f7b8957f3110497d758310b569.tar.xz
base: Replace the internal varargs stuff with C++11 constructs
We currently use our own home-baked support for type-safe variadic functions. This is confusing and somewhat limited (e.g., cprintf only supports a limited number of arguments). This changeset converts all uses of our internal varargs support to use C++11 variadic macros.
Diffstat (limited to 'src/base/cprintf.hh')
-rw-r--r--src/base/cprintf.hh70
1 files changed, 34 insertions, 36 deletions
diff --git a/src/base/cprintf.hh b/src/base/cprintf.hh
index e702fa3a6..94a74728d 100644
--- a/src/base/cprintf.hh
+++ b/src/base/cprintf.hh
@@ -1,4 +1,5 @@
/*
+ * Copyright (c) 2014 ARM Limited
* Copyright (c) 2002-2006 The Regents of The University of Michigan
* All rights reserved.
*
@@ -27,6 +28,7 @@
*
* Authors: Nathan Binkert
* Steve Reinhardt
+ * Andreas Sandberg
*/
#ifndef __BASE_CPRINTF_HH__
@@ -38,13 +40,9 @@
#include <string>
#include "base/cprintf_formats.hh"
-#include "base/varargs.hh"
namespace cp {
-#define CPRINTF_DECLARATION VARARGS_DECLARATION(cp::Print)
-#define CPRINTF_DEFINITION VARARGS_DEFINITION(cp::Print)
-
struct Print
{
protected:
@@ -128,33 +126,42 @@ struct Print
} // namespace cp
-typedef VarArgs::List<cp::Print> CPrintfArgsList;
-
inline void
-ccprintf(std::ostream &stream, const char *format, const CPrintfArgsList &args)
+ccprintf(cp::Print &print)
{
- cp::Print print(stream, format);
- args.add_args(print);
+ print.end_args();
}
-inline void
-ccprintf(std::ostream &stream, const char *format, CPRINTF_DECLARATION)
+
+template<typename T, typename ...Args> void
+ccprintf(cp::Print &print, const T &value, const Args &...args)
+{
+ print.add_arg(value);
+
+ ccprintf(print, args...);
+}
+
+
+template<typename ...Args> void
+ccprintf(std::ostream &stream, const char *format, const Args &...args)
{
cp::Print print(stream, format);
- VARARGS_ADDARGS(print);
+
+ ccprintf(print, args...);
}
-inline void
-cprintf(const char *format, CPRINTF_DECLARATION)
+
+template<typename ...Args> void
+cprintf(const char *format, const Args &...args)
{
- ccprintf(std::cout, format, VARARGS_ALLARGS);
+ ccprintf(std::cout, format, args...);
}
-inline std::string
-csprintf(const char *format, CPRINTF_DECLARATION)
+template<typename ...Args> std::string
+csprintf(const char *format, const Args &...args)
{
std::stringstream stream;
- ccprintf(stream, format, VARARGS_ALLARGS);
+ ccprintf(stream, format, args...);
return stream.str();
}
@@ -163,31 +170,22 @@ csprintf(const char *format, CPRINTF_DECLARATION)
* time converting const char * to std::string since we don't take
* advantage of it.
*/
-inline void
-ccprintf(std::ostream &stream, const std::string &format,
- const CPrintfArgsList &args)
-{
- ccprintf(stream, format.c_str(), args);
-}
-
-inline void
-ccprintf(std::ostream &stream, const std::string &format, CPRINTF_DECLARATION)
+template<typename ...Args> void
+ccprintf(std::ostream &stream, const std::string &format, const Args &...args)
{
- ccprintf(stream, format.c_str(), VARARGS_ALLARGS);
+ ccprintf(stream, format.c_str(), args...);
}
-inline void
-cprintf(const std::string &format, CPRINTF_DECLARATION)
+template<typename ...Args> void
+cprintf(const std::string &format, const Args &...args)
{
- ccprintf(std::cout, format.c_str(), VARARGS_ALLARGS);
+ ccprintf(std::cout, format.c_str(), args...);
}
-inline std::string
-csprintf(const std::string &format, CPRINTF_DECLARATION)
+template<typename ...Args> std::string
+csprintf(const std::string &format, const Args &...args)
{
- std::stringstream stream;
- ccprintf(stream, format.c_str(), VARARGS_ALLARGS);
- return stream.str();
+ return csprintf(format.c_str(), args...);
}
#endif // __CPRINTF_HH__