source: trunk/FACT++/src/tools.cc@ 10312

Last change on this file since 10312 was 10183, checked in by tbretz, 14 years ago
New import.
File size: 832 bytes
Line 
1// **************************************************************************
2/** @file tools.cc
3
4@todo
5 - Resolve the dependancies with dim
6 - Move code to a more appropriate place
7 - put stuff in namespaces
8*/
9// **************************************************************************
10#include "tools.h"
11
12#include <stdarg.h>
13
14using namespace std;
15
16string Format(const char *fmt, va_list &ap)
17{
18 int n=256;
19
20 char *ret=0;
21 while (1)
22 {
23 ret = new char[n+1];
24
25 const int sz = vsnprintf(ret, n, fmt, ap);
26 if (sz<=n)
27 break;
28
29 n *= 2;
30 delete [] ret;
31 };
32
33 string str(ret);
34
35 delete [] ret;
36
37 return str;
38}
39
40string Form(const char *fmt, ...)
41{
42 va_list ap;
43 va_start(ap, fmt);
44
45 string str = Format(fmt, ap);
46
47 va_end(ap);
48
49 return str;
50}
Note: See TracBrowser for help on using the repository browser.