camcom 1.0.3
 
Loading...
Searching...
No Matches
aravis_raii.hpp
Go to the documentation of this file.
1
8
9#ifndef CAMCOM_GENICAM_ARAVIS_RAII_HPP
10#define CAMCOM_GENICAM_ARAVIS_RAII_HPP
11
12#include <utility>
13#include <string>
14
15// Forward-declare Aravis/GLib types to avoid pulling arv.h into headers
16struct _ArvDevice;
17struct _ArvStream;
18struct _ArvBuffer;
19struct _GError;
20struct _GInetAddress;
21
22// GLib typedefs
23typedef struct _ArvDevice ArvDevice;
24typedef struct _ArvStream ArvStream;
25typedef struct _ArvBuffer ArvBuffer;
26typedef struct _GError GError;
27typedef struct _GInetAddress GInetAddress;
28
29namespace camcom::genicam {
30
33 GError* error{nullptr};
34
35 GErrorGuard() = default;
37
38 // Non-copyable
39 GErrorGuard(const GErrorGuard&) = delete;
41
43 GError** ptr() { return &error; }
44
46 explicit operator bool() const { return error != nullptr; }
47
49 std::string message() const;
50};
51
54template<typename T>
56public:
57 GObjectGuard() = default;
58 explicit GObjectGuard(T* p) : ptr_(p) {}
59
61
62 // Non-copyable
63 GObjectGuard(const GObjectGuard&) = delete;
65
66 // Movable
67 GObjectGuard(GObjectGuard&& o) noexcept : ptr_(std::exchange(o.ptr_, nullptr)) {}
69 if (this != &o) {
70 reset();
71 ptr_ = std::exchange(o.ptr_, nullptr);
72 }
73 return *this;
74 }
75
76 T* get() const { return ptr_; }
77 T* release() { return std::exchange(ptr_, nullptr); }
78 void reset(T* p = nullptr);
79
80 explicit operator bool() const { return ptr_ != nullptr; }
81
82private:
83 T* ptr_{nullptr};
84};
85
86// Convenience aliases
91
92} // namespace camcom::genicam
93
94#endif // CAMCOM_GENICAM_ARAVIS_RAII_HPP
struct _ArvBuffer ArvBuffer
Definition aravis_raii.hpp:25
struct _ArvStream ArvStream
Definition aravis_raii.hpp:24
struct _ArvDevice ArvDevice
Definition aravis_raii.hpp:23
struct _GError GError
Definition aravis_raii.hpp:26
struct _GInetAddress GInetAddress
Definition aravis_raii.hpp:27
Definition aravis_raii.hpp:55
~GObjectGuard()
Definition aravis_raii.cpp:37
GObjectGuard(const GObjectGuard &)=delete
GObjectGuard(T *p)
Definition aravis_raii.hpp:58
GObjectGuard & operator=(GObjectGuard &&o) noexcept
Definition aravis_raii.hpp:68
void reset(T *p=nullptr)
Definition aravis_raii.cpp:42
T * release()
Definition aravis_raii.hpp:77
GObjectGuard(GObjectGuard &&o) noexcept
Definition aravis_raii.hpp:67
T * get() const
Definition aravis_raii.hpp:76
GObjectGuard & operator=(const GObjectGuard &)=delete
Definition adapter.cpp:28
GObjectGuard< ArvBuffer > BufferGuard
Definition aravis_raii.hpp:89
GObjectGuard< ArvStream > StreamGuard
Definition aravis_raii.hpp:88
GObjectGuard< ArvDevice > DeviceGuard
Definition aravis_raii.hpp:87
GObjectGuard< GInetAddress > InetAddrGuard
Definition aravis_raii.hpp:90
std::string message() const
Extract error message (empty if no error)
Definition aravis_raii.cpp:25
GError * error
Definition aravis_raii.hpp:33
GErrorGuard & operator=(const GErrorGuard &)=delete
GError ** ptr()
Pass to Aravis functions expecting GError**.
Definition aravis_raii.hpp:43
~GErrorGuard()
Definition aravis_raii.cpp:19
GErrorGuard(const GErrorGuard &)=delete