BELFEM
0.9.0
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
#elif BELFEM_INTEL
27
#pragma warning push
28
#pragma warning disable 1595
29
#endif
30
31
namespace
belfem
32
{
33
//------------------------------------------------------------------------------
34
43
template
<
typename
... Args >
44
std::string
sprint
(
const
char
* aFormat,
const
Args ... aArgs )
45
{
46
// Determine size of string.
47
auto
tSize = std::snprintf(
nullptr
, 0, aFormat, aArgs ... );
48
49
// create unique pointer with length tSize. Add Extra space for '\0'.
50
std::unique_ptr< char[] > tBuffer(
new
char
[ tSize + 1 ] );
51
52
// write formatted string into buffer
53
std::snprintf( tBuffer.get(), tSize + 1, aFormat, aArgs ... );
54
55
// return formatted string
56
return
string
( tBuffer.get(), tBuffer.get() + tSize );
57
}
58
}
59
60
#ifdef BELFEM_CLANG
61
#pragma clang diagnostic pop
62
#elif BELFEM_GCC
63
#pragma GCC diagnostic pop
64
#elif BELFEM_INTEL
65
#pragma warning pop
66
#endif
67
68
#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:44
src
core
fn_sprint.hpp
Generated by
1.18.0