nvidia-texture-tools/src/nvcore/TextWriter.h

63 lines
1.2 KiB
C
Raw Normal View History

2010-05-27 23:18:08 +00:00
// This code is in the public domain -- Ignacio Casta<74>o <castano@gmail.com>
2007-04-17 08:49:19 +00:00
2010-05-27 23:18:08 +00:00
#pragma once
#ifndef NVCORE_TEXTWRITER_H
#define NVCORE_TEXTWRITER_H
2007-04-17 08:49:19 +00:00
2010-05-27 23:18:08 +00:00
#include "nvcore.h"
2010-03-16 22:35:20 +00:00
#include "Stream.h"
2010-05-27 23:18:08 +00:00
#include "StrLib.h"
2007-04-17 08:49:19 +00:00
namespace nv
{
2010-05-27 23:18:08 +00:00
/// Text writer.
class NVCORE_CLASS TextWriter
{
public:
2007-11-06 10:14:57 +00:00
2010-05-27 23:18:08 +00:00
TextWriter(Stream * s);
void writeString(const char * str);
void writeString(const char * str, uint len);
2014-11-04 17:49:29 +00:00
void format(const char * format, ...) __attribute__((format (printf, 2, 3)));
void formatList(const char * format, va_list arg);
2010-05-27 23:18:08 +00:00
private:
Stream * s;
2007-04-17 08:49:19 +00:00
2010-05-27 23:18:08 +00:00
// Temporary string.
StringBuilder str;
2007-04-17 08:49:19 +00:00
2010-05-27 23:18:08 +00:00
};
2007-11-06 10:14:57 +00:00
2010-05-27 23:18:08 +00:00
inline TextWriter & operator<<( TextWriter & tw, int i)
{
2014-11-04 17:49:29 +00:00
tw.format("%d", i);
2010-05-27 23:18:08 +00:00
return tw;
}
inline TextWriter & operator<<( TextWriter & tw, uint i)
{
2014-11-04 17:49:29 +00:00
tw.format("%u", i);
2010-05-27 23:18:08 +00:00
return tw;
}
inline TextWriter & operator<<( TextWriter & tw, float f)
{
2014-11-04 17:49:29 +00:00
tw.format("%f", f);
2010-05-27 23:18:08 +00:00
return tw;
}
inline TextWriter & operator<<( TextWriter & tw, const char * str)
{
tw.writeString(str);
return tw;
}
} // nv namespace
2007-11-06 10:14:57 +00:00
2007-04-17 08:49:19 +00:00
#endif // NVCORE_TEXTWRITER_H