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