scc 2025.09
SystemC components library
strprintf.h
1/*******************************************************************************
2 * Copyright 2020-2022 MINRES Technologies GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *******************************************************************************/
16
17#ifndef SCC_INCL_UTIL_STRPRINTF_H_
18#define SCC_INCL_UTIL_STRPRINTF_H_
19
20#include <cstdarg>
21#include <iostream>
22#include <string>
23#include <vector>
24#ifdef MSVC
25#define _CRT_NO_VA_START_VALIDATION
26#endif
27
33namespace util {
35inline std::string strprintf(const std::string format, ...) {
36 va_list args;
37 va_start(args, format);
38 size_t len = std::vsnprintf(NULL, 0, format.c_str(), args);
39 va_end(args);
40 std::vector<char> vec(len + 1);
41 va_start(args, format);
42 std::vsnprintf(&vec[0], len + 1, format.c_str(), args);
43 va_end(args);
44 return vec.data();
45}
46} // namespace util
48#endif /* SCC_INCL_UTIL_STRPRINTF_H_ */
SCC common utilities.
Definition bit_field.h:30
std::string strprintf(const std::string format,...)
allocate and print to a string buffer
Definition strprintf.h:35