forked from coolwanglu/pdf2htmlEX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStringFormatter.h
43 lines (36 loc) · 947 Bytes
/
StringFormatter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* Buffer reusing string formatter
*
* by WangLu
* 2012.11.29
*/
#ifndef STRINGFORMATTER_H__
#define STRINGFORMATTER_H__
#include <vector>
#include <cstdio>
namespace pdf2htmlEX {
class StringFormatter
{
public:
struct GuardedPointer
{
GuardedPointer(StringFormatter * sf) : sf(sf) { ++(sf->buf_cnt); }
GuardedPointer(const GuardedPointer & gp) : sf(gp.sf) { ++(sf->buf_cnt); }
~GuardedPointer(void) { --(sf->buf_cnt); }
operator char* () const { return &(sf->buf.front()); }
private:
StringFormatter * sf;
};
StringFormatter() : buf_cnt(0) { buf.reserve(L_tmpnam); }
/*
* Important:
* there is only one buffer, so new strings will replace old ones
*/
GuardedPointer operator () (const char * format, ...);
private:
friend class GuardedPointer;
std::vector<char> buf;
int buf_cnt;
};
} //namespace pdf2htmlEX
#endif //STRINGFORMATTER_H__