GCC Code Coverage Report


Directory: ./
File: src/dp/fallback.cc
Date: 2025-09-01 06:19:01
Exec Total Coverage
Lines: 0 28 0.0%
Functions: 0 4 0.0%
Branches: 0 8 0.0%

Line Branch Exec Source
1 #include "na64dp/fallback.hh"
2 #include "na64util/str-fmt.hh"
3
4 #include <cstdarg>
5
6 namespace na64dp {
7 namespace aux {
8
9 void FallbackableMixin::set_failflag_ptr(bool & ref) {
10 _failFlag = &ref;
11 }
12
13 bool FallbackableMixin::failflag() const {
14 if(!_failFlag) {
15 NA64DP_RUNTIME_ERROR("Fail flag destination is not set for object %p"
16 , this);
17 }
18 return *_failFlag;
19 }
20
21 void FallbackableMixin::failflag(bool v) {
22 if(!_failFlag) {
23 NA64DP_RUNTIME_ERROR("Fail flag destination is not set for object %p"
24 , this);
25 }
26 *_failFlag = v;
27 }
28
29 std::string
30 FallbackableMixin::set_failflag(const char *fmt, ...) {
31
32 if(_failFlag) *_failFlag = true;
33
34 va_list args;
35 va_start(args, fmt);
36 std::vector<char> v(NA64DP_STR_FMT_LENGTH);
37 while(true) {
38 va_list args2;
39 va_copy(args2, args);
40 int res = vsnprintf(v.data(), v.size(), fmt, args2);
41 if ((res >= 0) && (res < static_cast<int>(v.size()))) {
42 va_end(args);
43 va_end(args2);
44 if(!_failFlag)
45 throw na64dp::errors::GenericRuntimeError(v.data());
46 return std::string(v.data());
47 }
48 size_t size;
49 if (res < 0)
50 size = v.size() * 2;
51 else
52 size = static_cast<size_t>(res) + 1;
53 v.clear();
54 v.resize(size);
55 va_end(args2);
56 }
57 }
58
59 } // namespace ::na64dp::aux
60 } // namespace na64dp
61
62