IDS peak genericC++ v1.17.0
Loading...
Searching...
No Matches
peak_init_once.hpp
Go to the documentation of this file.
1#pragma once
2
3
4#include <mutex>
5
6
7namespace peak
8{
9namespace core
10{
11
12class InitOnce
13{
14public:
15 InitOnce() = default;
16 virtual ~InitOnce() = default;
17 InitOnce(const InitOnce& other) = delete;
18 InitOnce& operator=(const InitOnce& other) = delete;
19 InitOnce(InitOnce&& other) = delete;
20 InitOnce& operator=(InitOnce&& other) = delete;
21
22protected:
23 // override the Initialize() method to lazy-load data in your derived class, then call InitializeIfNecessary() each
24 // time before accessing the lazy-load data.
25 //
26 // Note: If multiple classes in the inheritance-hierarchy use this lazy-loading mechanism, they should call
27 // the Initialize() Method of their parent class, to make sure all levels are initialized.
28 virtual void Initialize() const = 0;
29 void InitializeIfNecessary() const;
30
31private:
32 mutable std::once_flag m_initializedFlag;
33};
34
35} /* namespace core */
36} /* namespace peak */
37
38/* Implementation */
39namespace peak
40{
41namespace core
42{
43
44inline void InitOnce::InitializeIfNecessary() const
45{
46 std::call_once(m_initializedFlag, [this] { Initialize(); });
47}
48
49} /* namespace core */
50} /* namespace peak */
The "core" namespace contains the direct GenAPI and GenTL wrapper.
Definition peak_buffer.hpp:32
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition peak_buffer.hpp:29