1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-07-08 19:00:33 +00:00
pdf2htmlEX/src/StringFormatter.h

44 lines
947 B
C
Raw Normal View History

2012-11-29 09:50:40 +00:00
/*
* Buffer reusing string formatter
*
* by WangLu
* 2012.11.29
*/
2012-11-29 12:39:30 +00:00
#ifndef STRINGFORMATTER_H__
#define STRINGFORMATTER_H__
2012-11-29 09:50:40 +00:00
2012-12-11 12:20:52 +00:00
#include <vector>
#include <cstdio>
2012-11-29 10:16:05 +00:00
namespace pdf2htmlEX {
2012-11-29 12:39:30 +00:00
class StringFormatter
2012-11-29 09:50:40 +00:00
{
public:
2013-06-13 10:00:25 +00:00
struct GuardedPointer
2012-11-29 09:50:40 +00:00
{
2012-11-29 12:39:30 +00:00
GuardedPointer(StringFormatter * sf) : sf(sf) { ++(sf->buf_cnt); }
GuardedPointer(const GuardedPointer & gp) : sf(gp.sf) { ++(sf->buf_cnt); }
~GuardedPointer(void) { --(sf->buf_cnt); }
2012-11-29 11:43:19 +00:00
operator char* () const { return &(sf->buf.front()); }
2012-11-29 09:50:40 +00:00
private:
2012-11-29 12:39:30 +00:00
StringFormatter * sf;
2012-11-29 09:50:40 +00:00
};
2012-11-29 12:39:30 +00:00
StringFormatter() : buf_cnt(0) { buf.reserve(L_tmpnam); }
2012-11-29 09:50:40 +00:00
/*
* Important:
* there is only one buffer, so new strings will replace old ones
*/
2012-12-11 12:17:36 +00:00
GuardedPointer operator () (const char * format, ...);
2012-11-29 09:50:40 +00:00
private:
2012-11-29 12:39:30 +00:00
friend class GuardedPointer;
2012-11-29 09:50:40 +00:00
std::vector<char> buf;
int buf_cnt;
};
2012-11-29 10:16:05 +00:00
} //namespace pdf2htmlEX
2012-11-29 12:39:30 +00:00
#endif //STRINGFORMATTER_H__