Main MRPT website
>
C++ reference for MRPT 1.5.9
utils
format.cpp
Go to the documentation of this file.
1
/* +---------------------------------------------------------------------------+
2
| Mobile Robot Programming Toolkit (MRPT) |
3
| http://www.mrpt.org/ |
4
| |
5
| Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6
| See: http://www.mrpt.org/Authors - All rights reserved. |
7
| Released under BSD License. See details in http://www.mrpt.org/License |
8
+---------------------------------------------------------------------------+ */
9
10
#include "
base-precomp.h
"
// Precompiled headers
11
12
13
#include <
mrpt/utils/utils_defs.h
>
14
#include <
mrpt/system/os.h
>
15
#include <
mrpt/system/memory.h
>
16
17
#include <cstdarg>
18
19
20
// A sprintf-like function for std::string
21
std::string
mrpt::format
(
const
char
*fmt, ...)
22
{
23
if
(!fmt)
return
std::string
();
24
25
int
result = -1,
length
= 2048;
26
std::string
buffer
;
27
while
(result == -1)
28
{
29
buffer
.resize(
length
);
30
31
va_list args;
// This must be done WITHIN the loop
32
va_start(args,fmt);
33
result =
mrpt::system::os::vsnprintf
(&
buffer
[0],
length
, fmt, args);
34
va_end(args);
35
36
// Truncated?
37
if
(result>=
length
) result=-1;
38
length
*=2;
39
40
// Ok?
41
if
(result >= 0) {
42
buffer
.resize(result);
43
}
44
}
45
46
return
buffer
;
47
}
48
memory.h
mrpt::system::os::vsnprintf
int BASE_IMPEXP vsnprintf(char *buf, size_t bufSize, const char *format, va_list args) MRPT_NO_THROWS
An OS-independent version of vsnprintf (Notice the bufSize param, which may be ignored in some compil...
Definition:
os.cpp:229
buffer
GLuint buffer
Definition:
glext.h:3775
utils_defs.h
mrpt::format
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition:
format.cpp:21
os.h
string
GLsizei const GLchar ** string
Definition:
glext.h:3919
length
GLuint GLsizei GLsizei * length
Definition:
glext.h:3900
base-precomp.h
Page generated by
Doxygen 1.8.14
for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020