GCC Code Coverage Report


Directory: ./
File: src/iguana/services/GlobalParam.h
Date: 2025-11-25 17:57:04
Coverage Exec Excl Total
Lines: 100.0% 10 0 10
Functions: 100.0% 3 0 3
Branches: 50.0% 2 0 4

Line Branch Exec Source
1 #pragma once
2
3 #include <mutex>
4 #include <string>
5
6 #include "Object.h"
7
8 namespace iguana {
9
10 /// @brief a globally accessible parameter
11 ///
12 /// A global parameter has the following properties
13 /// - a default value
14 /// - may be changed only _one time_
15 /// - may be read from _anywhere_
16 ///
17 /// @par Available global parameters
18 /// - `iguana::GlobalConcurrencyModel`
19 template <typename T>
20 class GlobalParam : public Object
21 {
22
23 public:
24
25 /// @param val the initial value of this parameter
26 82 GlobalParam(T val)
27 : Object("IGUANA")
28
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 82 times.
82 , m_val(val)
29 82 {}
30
31 /// @brief assign a new value to this parameter
32 /// @warning this may _only_ be used one time; a second attempt to set the parameter will fail
33 /// @param val the new value of this parameter
34 /// @returns `*this`
35 24 GlobalParam<T>& operator=(T const& val)
36 {
37 24 std::lock_guard<std::mutex> lock(m_mutex);
38
1/2
✓ Branch 3 → 4 taken 24 times.
✗ Branch 3 → 6 not taken.
24 std::call_once(m_once, [&]() { m_val = val; });
39 24 return *this;
40 }
41
42 /// @brief get the value of the parameter
43 /// @returns the value of the parameter
44 154 T const operator()()
45 {
46 154 std::lock_guard<std::mutex> lock(m_mutex);
47 154 return m_val;
48 }
49
50 private:
51
52 T m_val;
53 std::once_flag m_once;
54 std::mutex m_mutex;
55 };
56
57 // ==================================================================================
58 // IGUANA GLOBAL PARAMETERS (see source file 'GlobalParam.cc' for their default values)
59 // ==================================================================================
60
61 /// @brief The concurrency model, for running certain algorithms in a thread-safe way
62 /// @par Available Models
63 /// - "single": no thread safety, but optimal for single-threaded users
64 /// - "memoize": thread-safe lazy loading of configuration parameters
65 /// - "none": no concurrency model set by user; this is the *default option*, and if this
66 /// is the choice when `ConcurrentParamFactory::Create` is called, an appropriate
67 /// option will be _chosen_ by `ConcurrentParamFactory::Create` instead
68 extern GlobalParam<std::string> GlobalConcurrencyModel;
69
70 /// @brief Path to the RCDB
71 /// @see `iguana::RCDBReader` for details
72 extern GlobalParam<std::string> GlobalRcdbUrl;
73
74 }
75