BELFEM
0.9.3
Berkeley Lab Finite Element Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
fn_sprint.hpp
Go to the documentation of this file.
1
/*
2
* BELFEM -- The Berkeley Lab Finite Element Framework
3
* Copyright (c) 2026, The Regents of the University of California, through
4
* Lawrence Berkeley National Laboratory (subject to receipt of any required
5
* approvals from the U.S. Dept. of Energy). All rights reserved.
6
*
7
* Developers: Christian Messe, Gregory Giard
8
*
9
* See the top-level LICENSE file for the complete license and disclaimer.
10
*/
11
12
#ifndef BELFEM_FN_SPRINT_HPP
13
#define BELFEM_FN_SPRINT_HPP
14
15
16
#include <string>
17
#include <iostream>
18
#include <memory>
19
20
#ifdef BELFEM_CLANG
21
#pragma clang diagnostic push
22
#pragma clang diagnostic ignored "-Wformat-security"
23
#elif BELFEM_GCC
24
#pragma GCC diagnostic push
25
#pragma GCC diagnostic ignored "-Wformat"
26
#pragma GCC diagnostic ignored "-Wformat-security"
27
#elif BELFEM_INTEL
28
#pragma warning push
29
#pragma warning disable 1595
30
#endif
31
32
namespace
belfem
33
{
34
//------------------------------------------------------------------------------
35
44
template
<
typename
... Args >
45
std::string
sprint
(
const
char
* aFormat,
const
Args ... aArgs )
46
{
47
// Determine size of string.
48
auto
tSize = std::snprintf(
nullptr
, 0, aFormat, aArgs ... );
49
50
// create unique pointer with length tSize. Add Extra space for '\0'.
51
std::unique_ptr< char[] > tBuffer(
new
char
[ tSize + 1 ] );
52
53
// write formatted string into buffer
54
std::snprintf( tBuffer.get(), tSize + 1, aFormat, aArgs ... );
55
56
// return formatted string
57
return
string
( tBuffer.get(), tBuffer.get() + tSize );
58
}
59
}
60
61
#ifdef BELFEM_CLANG
62
#pragma clang diagnostic pop
63
#elif BELFEM_GCC
64
#pragma GCC diagnostic pop
65
#elif BELFEM_INTEL
66
#pragma warning pop
67
#endif
68
69
#endif
//BELFEM_FN_SPRINT_HPP
belfem
USER GUIDES:
Definition
cl_Capacitor.cpp:16
belfem::string
std::string string
Definition
typedefs.hpp:26
belfem::sprint
std::string sprint(const char *aFormat, const Args ... aArgs)
A format script similar to write( , ) in fortran.
Definition
fn_sprint.hpp:45
src
core
fn_sprint.hpp
Generated by
1.18.0