stub_analytics_plugin  1.6
Network Optix Video Analytics SDK
i_ref_countable.h
1 #pragma once
2 
3 #include <cstring>
4 
5 namespace nx {
6 namespace sdk {
7 
44 {
45 public:
55  struct InterfaceId
56  {
57  const char* const value;
60  template<int len>
61  explicit InterfaceId(const char (&charArray)[len]): value(charArray)
62  {
63  static_assert(len + /*terminating zero*/ 1 >= 16,
64  "Interface id should contain at least 15 chars");
65  }
66 
67  InterfaceId() = delete;
68 
69  bool operator==(const InterfaceId& other) const { return strcmp(value, other.value) == 0; }
70  bool operator!=(const InterfaceId& other) const { return !(*this == other); }
71  };
72 
74  static auto interfaceId() { return InterfaceId("nx::sdk::IRefCountable"); }
75 
77  virtual ~IRefCountable() = default;
78 
84  virtual IRefCountable* queryInterface(InterfaceId id)
85  {
86  if (id == interfaceId())
87  {
88  addRef();
89  return this;
90  }
91  return nullptr;
92  }
93 
94  const IRefCountable* queryInterface(InterfaceId id) const
95  {
96  return const_cast<IRefCountable*>(this)->queryInterface(id);
97  }
98 
99  template<class Interface>
100  Interface* queryInterface()
101  {
102  return static_cast<Interface*>(queryInterface(Interface::interfaceId()));
103  }
104 
105  template<class Interface>
106  const Interface* queryInterface() const
107  {
108  return static_cast<const Interface*>(queryInterface(Interface::interfaceId()));
109  }
110 
115  virtual int addRef() const = 0;
116 
121  virtual int releaseRef() const = 0;
122 };
123 
124 } // namespace sdk
125 } // namespace nx
Definition: i_ref_countable.h:55
const char *const value
Definition: i_ref_countable.h:57
virtual int releaseRef() const =0
virtual ~IRefCountable()=default
InterfaceId(const char(&charArray)[len])
Definition: i_ref_countable.h:61
Definition: debug.cpp:13
static auto interfaceId()
Definition: i_ref_countable.h:74
virtual int addRef() const =0
Definition: i_ref_countable.h:43