cprintf: properly deal with pointer types
This commit is contained in:
parent
1f57193439
commit
89f016aacb
2 changed files with 25 additions and 0 deletions
|
@ -147,6 +147,20 @@ struct Any : public Base<RECV>
|
|||
}
|
||||
};
|
||||
|
||||
template <typename T, class RECV>
|
||||
struct Any<T *, RECV> : public Base<RECV>
|
||||
{
|
||||
const T *argument;
|
||||
|
||||
Any(const T *arg) : argument(arg) {}
|
||||
|
||||
virtual void
|
||||
add_arg(RECV &receiver) const
|
||||
{
|
||||
receiver.add_arg(argument);
|
||||
}
|
||||
};
|
||||
|
||||
template <class RECV>
|
||||
struct Argument : public RefCountingPtr<Base<RECV> >
|
||||
{
|
||||
|
@ -156,6 +170,8 @@ struct Argument : public RefCountingPtr<Base<RECV> >
|
|||
Argument(const Null &null) { }
|
||||
template <typename T>
|
||||
Argument(const T& arg) : Base(new Any<T, RECV>(arg)) { }
|
||||
template <typename T>
|
||||
Argument(const T* arg) : Base(new Any<T *, RECV>(arg)) { }
|
||||
|
||||
void
|
||||
add_arg(RECV &receiver) const
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include <sstream>
|
||||
|
||||
#include "base/cprintf.hh"
|
||||
#include "base/misc.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -43,6 +44,14 @@ main()
|
|||
char foo[] = "foo";
|
||||
cprintf("%s\n", foo);
|
||||
|
||||
string _bar = "asdfkhasdlkfjhasdlkfhjalksdjfhalksdjhfalksdjfhalksdjhf";
|
||||
int length = 11;
|
||||
char bar[length + 1];
|
||||
bar[length] = 0;
|
||||
|
||||
memcpy(bar, _bar.c_str(), length);
|
||||
warn("%s\n", bar);
|
||||
|
||||
cprintf("%d\n", 'A');
|
||||
cprintf("%shits%%s + %smisses%%s\n", "test", "test");
|
||||
cprintf("%%s%-10s %c he went home \'\"%d %#o %#x %1.5f %1.2E\n",
|
||||
|
|
Loading…
Reference in a new issue